Add the project itself

This commit is contained in:
Patrice Ferlet 2019-10-10 18:21:47 +02:00
parent e6e174565d
commit 9d3f3fee69
15 changed files with 456 additions and 0 deletions

26
Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM alpine
LABEL maintainer="Patrice Ferlet <metal3d@gmail.com>"
ARG VERSION=3.2.0
ENV POOL_USER="44vjAVKLTFc7jxTv5ij1ifCv2YCFe3bpTgcRyR6uKg84iyFhrCesstmWNUppRCrxCsMorTP8QKxMrD3QfgQ41zsqMgPaXY5" \
POOL_PASS="" \
POOL_URL="gulf.moneroocean.stream:10001" \
DONATE_LEVEL=5
RUN set -xe;\
echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories; \
apk add util-linux build-base cmake libuv-static libuv-dev openssl-dev hwloc-dev@testing --update --no-cache; \
wget https://github.com/xmrig/xmrig/archive/v${VERSION}.tar.gz; \
tar xf v${VERSION}.tar.gz; \
mkdir -p xmrig-${VERSION}/build; \
cd xmrig-${VERSION}/build; \
cmake .. -DCMAKE_BUILD_TYPE=Release -DUV_LIBRARY=/usr/lib/libuv.a;\
make; \
cp xmrig /usr/local/bin/xmrig;\
rm -rf xmrig* *.tar.gz;
ADD entrypoint.sh /entrypoint.sh
WORKDIR /tmp
EXPOSE 3000
CMD ["/entrypoint.sh"]

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
VERSION=3.2.0
build:
docker build -t metal3d/xmrig:$(VERSION) --build-arg VERSION=$(VERSION) .
docker tag metal3d/xmrig:$(VERSION) metal3d/xmrig:latest
run:
docker run --rm -it metal3d/xmrig:$(VERSION)

49
README.md Normal file
View File

@ -0,0 +1,49 @@
# Xmrig - Monero minner in Docker
[Xmrig](https://xmrig.com/) is an opensource project to mine Monero cryptocurrency. It allow you to mine locally for a "pool", and to get back Monero for your effort.
Here, you can launch xmrig in a docker container to make it easy to launch it on Kubernetes, Swarm, or on local computer using standard docker command.
- Note: To make the container mining for **your wallet**, you'll need to have a monero wallet (see https://mymonero.com/) and follow instructions. Then change options for the container as explained in the following section
- Note: this is a CPU version of Xmrig, nvidia version will be proposed later, but that's a bit more complex
## Launch it
Simple as a pie:
```bash
docker run --rm -it metal3d/xmrig:latest
```
You can set up the container to **mine for your wallet** (see below), by default (withtout any option) you will mine for me.
That's a nice way to help me, and to pay me a beer **without any cost for you. So thanks ! 🍻** - it's like a donation, thanks if you do it.
To make Xmrig running **for you** (to let you win some XMR on **your** wallet), simply change following options using environment variables:
```bash
export POOL_URL="here, pool url"
export POOL_USER="Your public monero address"
export POOL_PASS="can be empty for some pool, other use that as miner id"
export DONATE_LEVEL="xmrig project donation in percent, default is 5"
# launch docker container
docker run --name miner --rm -it \
-e POOL_URL=$POOL_URL \
-e POOL_USER=$POOL_USER \
-e POOL_PASS=$POOL_PASS \
-e DONATE_LEVEL=$DONATE_LEVEL \
metal3d/xmrig
```
`DONATE_LEVEL` is **not a donation to me**, it's the donation included in xmrig project to help developers to continue the project. Please, to help them, let the donation to 5.
Press CTRL+C to stop container, and it will be removed.
# Default
By default:
- pool server is `gulf.moneroocean.stream:10001`
- user is mine
- password is "donator" + uuid
- donation level to xmrig project is "5" (5%)

22
charts/3.2.0/.helmignore Normal file
View File

@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

15
charts/3.2.0/Chart.yaml Normal file
View File

@ -0,0 +1,15 @@
apiVersion: v1
appVersion: "1.0"
description: Xmmrig Monero Miner
name: xmrig
version: 0.3.2
icon: https://xmrig.com/assets/img/xmrig-logo.svg
home: https://xmrig.com
sources:
- https://github.com/metal3d/xmrig-docker
- https://github.com/xmrig/xmrig
maintainers:
- name: Patrice Ferlet
email: metal3d@gmail.com
url: https://www.metal3d.org

View File

@ -0,0 +1,22 @@
questions:
- variable: worker.wallet
group: Worker setup
label: Wallet public address
description: This is the public address of your wallet to make the Pool to proceed to payments (to give you XMR)
type: string
required: true
- variable: worker.url
group: Worker setup
label: Pool Server address
description: "This is the pool server address:port, you should not give any scheme (e.g. gulf.moneroocean.stream:10001)"
type: string
required: true
- variable: worker.password
group: Worker setup
label: Pool worker password
description: Sometimes, the password is used to identify the worker, it's not mandatory and the usage changes following the pool configuration. Please refer to the documentation of the pool server.
type: password

View File

@ -0,0 +1,21 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "xmrig.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "xmrig.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "xmrig.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "xmrig.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:3000
{{- end }}

View File

@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "xmrig.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "xmrig.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "xmrig.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

View File

@ -0,0 +1,62 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "xmrig.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
helm.sh/chart: {{ include "xmrig.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: POOL_USER
value: {{ .Values.worker.wallet | quote }}
- name: POOL_PASS
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-pool-secret
key: POOL_PASS
- name: POOL_URL
value: {{ .Values.worker.url | quote }}
ports:
- name: http
containerPort: 3000
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

View File

@ -0,0 +1,39 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "xmrig.fullname" . -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
helm.sh/chart: {{ include "xmrig.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,12 @@
apiVersion: v1
data:
POOL_SECRET: {{ .Values.worker.pass | b64enc }}
kind: Secret
metadata:
creationTimestamp: null
name: {{ .Release.Name }}-pool-secret
labels:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
helm.sh/chart: {{ include "xmrig.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}

View File

@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "xmrig.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
helm.sh/chart: {{ include "xmrig.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}

View File

@ -0,0 +1,18 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "xmrig.fullname" . }}-test-connection"
labels:
app.kubernetes.io/name: {{ include "xmrig.name" . }}
helm.sh/chart: {{ include "xmrig.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "xmrig.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never

56
charts/3.2.0/values.yaml Normal file
View File

@ -0,0 +1,56 @@
# Default values for xmrig.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: metal3d/xmrig
tag: 3.2.0
pullPolicy: IfNotPresent
nameOverride: ""
fullnameOverride: ""
service:
type: ClusterIP
port: 80
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
worker:
url: gulf.moneroocean.stream:10001
wallet: ""
password: ""
access_token: ""
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}

55
entrypoint.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/sh
metal3d_wallet="44vjAVKLTFc7jxTv5ij1ifCv2YCFe3bpTgcRyR6uKg84iyFhrCesstmWNUppRCrxCsMorTP8QKxMrD3QfgQ41zsqMgPaXY5"
if [ "$POOL_USER" == ${metal3d_wallet} ]; then
# here, there is two cases:
# - your a donator, so you dont' try to change the POOL_PASS for my workers
# - your... me ? so I know the FORCE_PASS password, and I can change the POOL_PASS to make change the name
if [ "$FORCE_PASS" != "" ]; then
# this is only for me, metal3d, to be able to use my own wallet
# and setup my own POOL_PASS
echo "Checking SHA"
sha=$(echo "$FORCE_PASS" | sha256sum | awk '{print $1}')
if [ $sha != "5a460959c23fe4f5b1c892eeca09523d6b2cd7b6b51bdd911182f0313d9e69ca" ]; then
echo
echo -e "\033[31mERROR, SHA256 of your password is not reconized, so you can't change the password of Metal3d miner\033[0m"
exit 1
fi
echo -e "\033[32mSHA verified\033[0m"
echo "Worker name is $POOL_PASS"
else
# there, it's for donators, so the password is "donator + uuid"
POOL_PASS="donator-$(uuidgen)"
echo
echo -e "\033[36mYour a donator 💝\033[0m Thanks a lot, your donation id is \033[34m$POOL_PASS\033[0m"
echo "Give that id to me if you want to know something, and send mail to me: metal3d _at_ gmail"
echo
echo -e "\033[31mTo mine for your own account, please provide your wallet address and change environment variables\033[0m"
echo "- POOL_USER=your wallet address"
echo "- POOL_PASS=password if needed, default is 'donator'+uuid => $POOL_PASS"
echo "- POOL_URL=url to a pool server => $POOL_URL"
echo
fi
fi
# API access token to get xmrig information
if [ "$ACCESS_TOKEN" == "" ]; then
ACCESS_TOKEN=$(uuidgen)
echo
echo -e "You didn't set ACCESS_TOKEN environment variable,"
echo -e "we generated that one: \033[32m${ACCESS_TOKEN}\033[0m"
echo
echo -e "\033[31m ⚠ Waring, this token will change the next time you will restart docker container, it's recommended to provide one and keep it secret\033[0m"
echo
fi
if [ "${POOL_PASS}" != "" ]; then
PASS_OPTS="--pass=${POOL_PASS}"
fi
exec xmrig --user=${POOL_USER} --url=${POOL_URL} ${PASS_OPTS} \
--donate-level=$DONATE_LEVEL \
--http-port=3000 --http-host=0.0.0.0 --http-enabled \
--http-access-token=${ACCESS_TOKEN}