Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Improve docker #92

Merged
merged 4 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mono:5.12.0.226 AS webminerpool-build
FROM mono:5.16 AS webminerpool-build

ARG DONATION_LEVEL=0.03

Expand All @@ -8,16 +8,30 @@ COPY hash_cn /hash_cn
RUN sed -ri "s/^(.*DonationLevel = )[0-9]\.[0-9]{2}/\1${DONATION_LEVEL}/" /server/Server/DevDonation.cs && \
apt-get -qq update && \
apt-get -qq install build-essential && \
rm -rf /var/lib/apt/lists/* && \
cd /hash_cn/libhash && \
make && \
cd /server && \
msbuild Server.sln /p:Configuration=Release_Server /p:Platform="any CPU"

FROM mono:5.12.0.226

VOLUME ["/root"]
FROM mono:5.16

RUN mkdir /webminerpool

# Install acme.sh
RUN apt-get -qq update && \
apt-get install -qq \
coreutils \
cron \
curl \
git \
openssl \
socat && \
rm -rf /var/lib/apt/lists/* && \
git clone https://github.com/Neilpang/acme.sh.git /root/acme.sh && \
cd /root/acme.sh && \
git checkout 2.7.9 && \
Copy link

@ghost ghost Feb 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please externalize version to ENV on next update and, ideally, pull from release tarball as opposed to using Git. Here's how you can pull release tarball:

A nice to have also is a multi-stage build where binary is compiled in mono then dropped into a busybox container or similar for a microcontainer end-result. Ideally the final binary would be moved into a scratch container but cron is necessary to keep the cert up-to-date (though I doubt this will always be the case).

This should make the whole thing take up very small amounts of resources and more suitable for deployment on ARMv7 and other ARM-based architectures following a compile using mono.

/root/acme.sh/acme.sh --install --home /root/.acme.sh
COPY entrypoint.sh /entrypoint.sh
COPY --from=webminerpool-build /server/Server/bin/Release_Server/server.exe /webminerpool
COPY --from=webminerpool-build /server/Server/bin/Release_Server/pools.json /webminerpool
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ The cryptonight hashing functions in C-code. With simple Makefiles (use the "mak
Find the original pull request with instructions by nierdz [here](https://github.com/notgiven688/webminerpool/pull/62).

Added Dockerfile and entrypoint.sh.
Inside entrypoint.sh, a certificate is installed so you need to provide a domain name during docker run. The certificate is automatically renewed using a cronjob.
Inside entrypoint.sh, if `$DOMAIN` is provided, a certificate is registered and packed in pkcs12 format to be used with server.exe.

```bash
cd webminerpool
Expand All @@ -162,7 +162,7 @@ To run it:
```bash
docker run -d -p 80:80 -p 8181:8181 -e DOMAIN=mydomain.com webminerpool
```
You absolutely need to set a domain name.

The 80:80 bind is used to obtain a certificate.
The 8181:8181 bind is used for server itself.

Expand All @@ -172,6 +172,28 @@ If you want to bind these ports to a specific IP, you can do this:
docker run -d -p xx.xx.xx.xx:80:80 -p xx.xx.xx.xx:8181:8181 -e DOMAIN=mydomain.com webminerpool
```

You can even use docker-compose, here is a sample snippet:

```
webminer:
container_name: webminer
image: webminer:1.0
build:
context: ./webminerpool
args:
- DONATION_LEVEL=${WEBMINER_DONATION_LEVEL}
restart: always
ports:
- ${WEBMINER_IP}:80:80
- ${WEBMINER_IP}:8181:8181
environment:
DOMAIN: ${WEBMINER_DOMAIN}
networks:
- my-network
```

To use this snippet, you need to define `$WEBMINER_DONATION_LEVEL`, `$WEBMINER_DOMAIN` and `$WEBMINER_IP` in a `.env` file.

# Developer Donations

By default a server-side 3% dev-donation is configured. Leaving this fee at the current level is highly appreciated. If you want
Expand Down
46 changes: 18 additions & 28 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

# Check if $DOMAIN is set
if [ -z $DOMAIN ]; then
echo -e "You need to set \$DOMAIN variable at run time\n"
echo -e "For example: docker run -d -p 80:80 -p 443:443 -e DOMAIN=example.com\n"
exit 1
if [ -z "$DOMAIN" ]; then
echo -e "You did not set \$DOMAIN variable at run time. No certificate will be registered.\n"
echo -e "If you want to define it on command line here is an example:\n"
echo -e "docker run -d -p 80:80 -p 443:443 -e DOMAIN=example.com\n"
else
# Install acme.sh
apt-get -qq update
apt-get install -qq \
cron \
openssl \
curl \
coreutils \
socat \
git
git clone https://github.com/Neilpang/acme.sh.git /root/acme.sh && \
cd /root/acme.sh && \
git checkout 2.7.8 && \
/root/acme.sh/acme.sh --install

# Generate SSL cert
/root/.acme.sh/acme.sh --issue --standalone -d ${DOMAIN} -d www.${DOMAIN}

# Generate pfx
openssl pkcs12 -export -out /webminerpool/certificate.pfx -inkey /root/.acme.sh/${DOMAIN}/${DOMAIN}.key -in /root/.acme.sh/${DOMAIN}/${DOMAIN}.cer -certfile /root/.acme.sh/${DOMAIN}/fullchain.cer -passin pass:miner -passout pass:miner

# Start server
pushd /webminerpool
exec /usr/bin/mono server.exe

if [[ ! -f "/root/.acme.sh/${DOMAIN}/${DOMAIN}.cer" ]] || ! openssl x509 -checkend 0 -in "/root/.acme.sh/${DOMAIN}/${DOMAIN}.cer"; then
# Generate SSL cert
/root/.acme.sh/acme.sh --issue --standalone -d "${DOMAIN}" -d "www.${DOMAIN}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would anyone want a cert on www for a proxy server? I think the second -d flag should be removed.

# Generate pfx
openssl pkcs12 -export -out /webminerpool/certificate.pfx -inkey "/root/.acme.sh/${DOMAIN}/${DOMAIN}.key" -in "/root/.acme.sh/${DOMAIN}/${DOMAIN}.cer" -certfile "/root/.acme.sh/${DOMAIN}/fullchain.cer" -passin pass:miner -passout pass:miner
fi
fi

# Start server
pushd /webminerpool
exec /usr/bin/mono server.exe