Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cornfeedhobo committed Dec 8, 2021
1 parent 2e6e250 commit 5c3ee84
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 95 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[**]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 160

[**.md]
indent_style = space

[**.yml]
indent_style = space
198 changes: 120 additions & 78 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Multistage docker build, requires docker 17.05

# builder stage
FROM alpine:3.13 as builder
# Builder stage
FROM alpine:3.15 as builder

RUN set -ex && apk add --update --no-cache \
ARG MONERO_VERSION
ARG MONERO_HASH
ARG MONERO_TARGET

# These steps are broken up so that the builder picks up the layer from the --update command
RUN set -ex && apk --update --no-cache upgrade
RUN set -ex && apk add --no-cache \
autoconf \
automake \
boost \
Expand Down Expand Up @@ -70,96 +76,118 @@ RUN set -ex && apk add --update --no-cache \
unbound-dev \
zeromq-dev

# zmq.hpp
ARG CPPZMQ_VERSION=v4.4.1
ARG CPPZMQ_HASH=f5b36e563598d48fcc0d82e589d3596afef945ae
RUN set -ex \
&& git clone --depth 1 -b ${CPPZMQ_VERSION} https://github.com/zeromq/cppzmq.git \
&& cd cppzmq \
&& test `git rev-parse HEAD` = ${CPPZMQ_HASH} || exit 1 \
&& mkdir /usr/local/include \
&& mv *.hpp /usr/local/include/
# Install fixuid tool
RUN set -ex && \
curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.5.1/fixuid-0.5.1-linux-amd64.tar.gz | tar -C /usr/local/bin -xzf - && \
chown root:root /usr/local/bin/fixuid && \
chmod 4755 /usr/local/bin/fixuid

WORKDIR /usr/local
WORKDIR /usr/src

ARG NPROC
ENV CFLAGS='-fPIC'
ENV CXXFLAGS='-fPIC -DELPP_FEATURE_CRASH_LOG'
ENV CFLAGS="-fPIC"
ENV CXXFLAGS="-fPIC -DELPP_FEATURE_CRASH_LOG"

# Monero
ENV MONERO_VERSION=0.17.2.3
ENV MONERO_HASH=2222bea92fdeef7e6449d2d784cdfc3012641ee1
# Build Monero
RUN set -ex \
&& git clone --recursive --depth 1 -b v${MONERO_VERSION} https://github.com/monero-project/monero.git \
&& git clone --recursive --depth 1 -b ${MONERO_VERSION} https://github.com/monero-project/monero.git \
&& cd monero \
&& git submodule init \
&& git submodule update \
&& test `git rev-parse HEAD` = ${MONERO_HASH} || exit 1 \
&& nice -n 19 ionice -c2 -n7 make -j${NPROC:-1} release
&& nice -n 19 ionice -c2 -n7 make -j${NPROC:-$(nproc)} ${MONERO_TARGET}


# runtime stage
FROM alpine:3.13
# Runtime stage
FROM alpine:3.15

RUN set -ex && apk add --update --no-cache \
boost \
boost-atomic \
boost-chrono \
boost-container \
boost-context \
boost-contract \
boost-coroutine \
boost-date_time \
boost-fiber \
boost-filesystem \
boost-graph \
boost-iostreams \
boost-libs \
boost-locale \
boost-log \
boost-log_setup \
boost-math \
boost-prg_exec_monitor \
boost-program_options \
boost-python3 \
boost-random \
boost-regex \
boost-serialization \
boost-stacktrace_basic \
boost-stacktrace_noop \
boost-static \
boost-system \
boost-thread \
boost-timer \
boost-type_erasure \
boost-unit_test_framework \
boost-wave \
boost-wserialization \
ca-certificates \
libexecinfo \
libsodium \
libusb \
miniupnpc \
ncurses-libs \
openssl \
pcsc-lite-libs \
protobuf \
rapidjson \
readline \
unbound-libs \
zeromq

COPY --from=builder /usr/local/monero/build/Linux/_no_branch_/release/bin/* /usr/local/bin/

ENV MONERO_HOME "/root/.bitmonero"
ARG MONERO_VERSION
ARG MONERO_HASH
ARG MONERO_TARGET

# Contains the blockchain and wallet files
VOLUME $MONERO_HOME
WORKDIR $MONERO_HOME
RUN set -ex && apk --update --no-cache upgrade
RUN set -ex && \
case "${MONERO_TARGET}" in \
*static*) apk add --no-cache \
ca-certificates \
iputils \
libexecinfo \
libsodium \
ncurses-libs \
pcsc-lite-libs \
readline \
zeromq \
;; \
*) apk add --no-cache \
boost \
boost-atomic \
boost-chrono \
boost-container \
boost-context \
boost-contract \
boost-coroutine \
boost-date_time \
boost-fiber \
boost-filesystem \
boost-graph \
boost-iostreams \
boost-libs \
boost-locale \
boost-log \
boost-log_setup \
boost-math \
boost-prg_exec_monitor \
boost-program_options \
boost-python3 \
boost-random \
boost-regex \
boost-serialization \
boost-stacktrace_basic \
boost-stacktrace_noop \
boost-static \
boost-system \
boost-thread \
boost-timer \
boost-type_erasure \
boost-unit_test_framework \
boost-wave \
boost-wserialization \
ca-certificates \
iputils \
libexecinfo \
libsodium \
libusb \
miniupnpc \
ncurses-libs \
numactl-tools \
openssl \
pcsc-lite-libs \
protobuf \
rapidjson \
readline \
unbound-libs \
zeromq \
;; \
esac

COPY --from=builder /usr/local/bin/fixuid /usr/local/bin/fixuid
COPY --from=builder /usr/src/monero/build/Linux/_no_branch_/release/bin/* /usr/local/bin/

ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]

# Create a dedicated user and configure fixuid
ARG MONERO_USER="monero"
RUN set -ex && \
addgroup -g 1000 ${MONERO_USER} && \
adduser -u 1000 -G ${MONERO_USER} -h /home/${MONERO_USER} -s /bin/sh -D ${MONERO_USER} && \
mkdir -p /etc/fixuid && \
printf "user: ${MONERO_USER}\ngroup: ${MONERO_USER}\n" > /etc/fixuid/config.yml
USER "${MONERO_USER}:${MONERO_USER}"

# Contains the blockchain and wallet files
ARG MONERO_HOME="/home/${MONERO_USER}/.bitmonero"
VOLUME ${MONERO_HOME}
WORKDIR ${MONERO_HOME}

CMD [ "monerod", \
"--p2p-bind-ip=0.0.0.0", \
"--p2p-bind-port=18080", \
Expand All @@ -169,3 +197,17 @@ CMD [ "monerod", \
"--confirm-external-bind" ]

EXPOSE 18080 18081

# Labels, for details see http://label-schema.org/rc1/
ARG BUILD_DATE
LABEL maintainer="github.com/cornfeedhobo/docker-monero"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date="${BUILD_DATE}"
LABEL org.label-schema.name="cornfeedhobo/monero"
LABEL org.label-schema.description="Built from source monero Docker images based on Alpine Linux"
LABEL org.label-schema.url="https://getmonero.org/"
LABEL org.label-schema.vcs-url="https://github.com/monero-project/monero/"
LABEL org.label-schema.vcs-ref="${MONERO_HASH}"
LABEL org.label-schema.vendor="cornfeedhobo"
LABEL org.label-schema.version="${MONERO_VERSION}"
LABEL org.label-schema.docker.cmd="docker run -dit -p 18080:18080 -p 18081:18081 cornfeedhobo/monero"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 cornfeedhobo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
[![Docker Stars](https://img.shields.io/docker/stars/cornfeedhobo/monero.svg)](https://hub.docker.com/r/cornfeedhobo/monero/)
[![Docker Pulls](https://img.shields.io/docker/pulls/cornfeedhobo/monero.svg)](https://hub.docker.com/r/cornfeedhobo/monero/)

**Built from source [monero](http://monero.org) Docker images based on [Alpine Linux](https://alpinelinux.org)**
**Built from source [monero](http://getmonero.org) Docker images based on [Alpine Linux](https://alpinelinux.org)**

## Pulling
## TL;DR

```bash
docker pull cornfeedhobo/monero
UID="$(id -u)" GID="$(id -g)" docker-compose run wallet
```

```bash
docker-compose down
```

## Running the Daemon
Expand All @@ -17,7 +21,7 @@ docker pull cornfeedhobo/monero
docker run -dit --name monero \
-v $HOME/.bitmonero:/root/.bitmonero \
-p 18080:18080 -p 18081:18081 \
--memory=1g --memory-swap=1g \
--user="$(id -u):$(id -g)" \
cornfeedhobo/monero
```

Expand Down Expand Up @@ -47,19 +51,14 @@ docker exec -it monero monero-wallet-cli --wallet-file=wallet
```bash
docker run --rm -it --link monero \
-v $HOME/.bitmonero:/root/.bitmonero \
cornfeedhobo/monero monero-wallet-cli \
--wallet-file=wallet \
--daemon-address="$MONERO_PORT_18081_TCP_ADDR:$MONERO_PORT_18081_TCP_PORT"
--user="$(id -u):$(id -g)" \
cornfeedhobo/monero \
monero-wallet-cli \
--wallet-file=wallet \
--daemon-address="$MONERO_PORT_18081_TCP_ADDR:$MONERO_PORT_18081_TCP_PORT"
```

## Running Just the Wallet

```bash
docker run --rm -it \
-v $HOME/.bitmonero:/root/.bitmonero \
cornfeedhobo/monero monero-wallet-cli \
--wallet-file=wallet
```
_Note: these are special environment variables filled in by the docker daemon and are specific to these examples_.

## Is it any good?

Expand Down
49 changes: 49 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -eux

repo='monero-project/monero'
branch="$(git rev-parse --abbrev-ref HEAD)"

tag="${branch}"
if [ "${branch}" = 'master' ]; then
tag="$(curl -LSs "https://api.github.com/repos/${repo}/releases/latest" | jq -r '.tag_name')"
fi

read tag_type tag_sha < <(echo $(curl -LSs "https://api.github.com/repos/${repo}/git/ref/tags/${tag}" | jq -r '.object.type,.object.sha') )
if [ ! $tag_type = 'commit' ]; then
tag_sha="$(curl -LSs "https://api.github.com/repos/${repo}/git/tags/${tag_sha}" | jq -r '.object.sha')"
fi

build_date="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
build_flags="${1:-}"

docker build ${build_flags} \
--build-arg "BUILD_DATE=${build_date}" \
--build-arg "MONERO_VERSION=${tag}" \
--build-arg "MONERO_HASH=${tag_sha}" \
--build-arg "MONERO_TARGET=release" \
-t cornfeedhobo/monero:${tag} .

docker build ${build_flags} \
--build-arg "BUILD_DATE=${build_date}" \
--build-arg "MONERO_VERSION=${tag}" \
--build-arg "MONERO_HASH=${tag_sha}" \
--build-arg "MONERO_TARGET=release-static" \
-t cornfeedhobo/monero:${tag}-static .

if [ "${branch}" = 'master' ]; then
docker build ${build_flags} \
--build-arg "BUILD_DATE=${build_date}" \
--build-arg "MONERO_VERSION=${tag}" \
--build-arg "MONERO_HASH=${tag_sha}" \
--build-arg "MONERO_TARGET=release" \
-t cornfeedhobo/monero:latest .

docker build ${build_flags} \
--build-arg "BUILD_DATE=${build_date}" \
--build-arg "MONERO_VERSION=${tag}" \
--build-arg "MONERO_HASH=${tag_sha}" \
--build-arg "MONERO_TARGET=release-static" \
-t cornfeedhobo/monero:latest-static .
fi
Loading

0 comments on commit 5c3ee84

Please sign in to comment.