-
Notifications
You must be signed in to change notification settings - Fork 91
ref(docker): create a standalone docker artifact to run lightwalletd
#476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gustavovalverde
wants to merge
5
commits into
zcash:master
Choose a base branch
from
gustavovalverde:ref-dockerfile
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a0ebb6c
ref(docker): create a standalone Dockerfile to run `lightwalletd`
gustavovalverde b168550
Merge branch 'master' into ref-dockerfile
gustavovalverde ebc2261
chore: reduce diff after conflict
gustavovalverde ad867cc
ref(docker): add a `docker-compose` to run lighwalletd with zebra
gustavovalverde f7fd125
Merge branch 'master' into ref-dockerfile
gustavovalverde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Before the docker CLI sends the context to the docker daemon, it looks for a file | ||
# named .dockerignore in the root directory of the context. If this file exists, the | ||
# CLI modifies the context to exclude files and directories that match patterns in it. | ||
# | ||
# You may want to specify which files to include in the context, rather than which | ||
# to exclude. To achieve this, specify * as the first pattern, followed by one or | ||
# more ! exception patterns. | ||
# | ||
# https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||
|
||
# Exclude everything: | ||
# | ||
* | ||
|
||
# Now un-exclude required files and folders: | ||
# | ||
!go.mod | ||
!go.sum | ||
!main.go | ||
!docker | ||
!cmd | ||
!common | ||
!frontend | ||
!parser | ||
!walletrpc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ZCASHD_RPCUSER=zcashrpc | ||
ZCASHD_RPCPASSWORD=${PASSWORD_ZCASHD} | ||
ZCASHD_RPCPORT=38232 | ||
ZCASHD_ALLOWIP=0.0.0.0/0 | ||
ZCASHD_DATADIR=/srv/zcashd/.zcash | ||
ZCASHD_PARMDIR=/srv/zcashd/.zcash-params | ||
ZCASHD_GEN=0 | ||
GF_SECURITY_ADMIN_USER=admin | ||
GF_SECURITY_ADMIN_PASSWORD=${PASSWORD_GRAFANA} | ||
LWD_GRPC_PORT=9067 | ||
LWD_HTTP_PORT=9068 | ||
ZCASHD_CONF_PATH=/srv/lightwalletd/zcash.conf | ||
ZEBRA_RPC_PORT=8232 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,74 @@ | ||
FROM golang:1.22 AS lightwalletd_base | ||
ARG APP_HOME=/srv/lightwalletd | ||
ARG ZCASHD_CONF_PATH=$APP_HOME/zcash.conf | ||
|
||
ADD . /go/src/github.com/zcash/lightwalletd | ||
WORKDIR /go/src/github.com/zcash/lightwalletd | ||
## | ||
## Builder | ||
## | ||
# Create layer in case you want to modify local lightwalletd code | ||
FROM golang:1.22 AS build | ||
|
||
RUN make \ | ||
&& /usr/bin/install -c ./lightwalletd /usr/local/bin/ \ | ||
&& mkdir -p /var/lib/lightwalletd/db \ | ||
&& chown 2002:2002 /var/lib/lightwalletd/db | ||
|
||
# Create and change to the app directory. | ||
WORKDIR /app | ||
|
||
# Retrieve application dependencies. | ||
# This allows the container build to reuse cached dependencies. | ||
# Expecting to copy go.mod and if present go.sum. | ||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
|
||
# Do not use `go get` as it updates the requirements listed in your go.mod file. | ||
# `go mod download` does not add new requirements or update existing requirements. | ||
RUN go mod download | ||
|
||
# Copy local code to the container image. | ||
COPY . ./ | ||
|
||
# Build and install the binary. | ||
RUN go build -v -o /usr/local/bin/lightwalletd | ||
|
||
## | ||
## Runtime | ||
## | ||
FROM debian:bookworm-slim as runtime | ||
|
||
# Get the needed ARGs values | ||
ARG APP_HOME | ||
ARG ZCASHD_CONF_PATH | ||
ARG LWD_GRPC_PORT=9067 | ||
ARG LWD_HTTP_PORT=9068 | ||
ARG LWD_USER=lightwalletd | ||
ARG LWD_UID=2002 | ||
|
||
RUN useradd --home-dir "/srv/$LWD_USER" \ | ||
--shell /bin/bash \ | ||
--create-home \ | ||
--uid "$LWD_UID" \ | ||
"$LWD_USER" | ||
# Always run a container with a non-root user. Running as root inside the container is running as root in the Docker host | ||
# If an attacker manages to break out of the container, they will have root access to the host | ||
RUN groupadd --gid ${LWD_UID} ${LWD_USER} && \ | ||
useradd --home-dir ${APP_HOME} --no-create-home --gid ${LWD_USER} --uid ${LWD_UID} --shell /bin/sh ${LWD_USER} | ||
|
||
# Create the directory for the database and certificates to keep backwards compatibility | ||
RUN mkdir -p /var/lib/lightwalletd/db && \ | ||
mkdir -p /secrets/lightwallted && \ | ||
chown ${LWD_USER}:${LWD_USER} /var/lib/lightwalletd/db && \ | ||
chown ${LWD_USER}:${LWD_USER} /secrets/lightwallted | ||
|
||
WORKDIR ${APP_HOME} | ||
|
||
COPY --from=build /usr/local/bin/lightwalletd /usr/local/bin | ||
COPY ./docker/cert.key ./ | ||
COPY ./docker/cert.pem ./ | ||
|
||
RUN set -ex; \ | ||
{ \ | ||
echo "rpcuser=zcashrpc"; \ | ||
echo "rpcpassword=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''`" \ | ||
echo "rpcbind=zcashd"; \ | ||
echo "rpcport=3434"; \ | ||
} > "${ZCASHD_CONF_PATH}" | ||
|
||
EXPOSE ${LWD_GRPC_PORT} | ||
EXPOSE ${LWD_HTTP_PORT} | ||
|
||
WORKDIR "/srv/$LWD_USER" | ||
USER ${LWD_USER} | ||
|
||
ENTRYPOINT ["lightwalletd"] | ||
CMD ["--help"] | ||
CMD ["--tls-cert=cert.pem", "--tls-key=cert.key", "--grpc-bind-addr=0.0.0.0:9067", "--http-bind-addr=0.0.0.0:9068", "--log-file=/dev/stdout", "--log-level=7"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: zebra-lwd | ||
|
||
services: | ||
lightwalletd: | ||
image: electriccoinco/lightwalletd | ||
platform: linux/amd64 | ||
build: | ||
context: . | ||
target: runtime | ||
depends_on: | ||
zebra: | ||
condition: service_started | ||
restart: unless-stopped | ||
deploy: | ||
resources: | ||
reservations: | ||
cpus: "2" | ||
memory: 4G | ||
configs: | ||
- source: lwd_config | ||
target: ${ZCASHD_CONF_PATH} | ||
uid: '2002' # Golang's container default user uid | ||
gid: '2002' # Golang's container default group gid | ||
volumes: | ||
- litewalletd-data:/var/lib/lightwalletd/db | ||
#! This setup with --no-tls-very-insecure is only for testing purposes | ||
#! For production environments follow the guidelines here: https://github.com/zcash/lightwalletd#production-usage | ||
command: > | ||
--no-tls-very-insecure | ||
--grpc-bind-addr=0.0.0.0:${LWD_GRPC_PORT} | ||
--http-bind-addr=0.0.0.0:${LWD_HTTP_PORT} | ||
--zcash-conf-path=${ZCASHD_CONF_PATH} | ||
--data-dir=/var/lib/lightwalletd/db | ||
--log-file=/dev/stdout | ||
--log-level=7 | ||
ports: | ||
- "127.0.0.1:${LWD_GRPC_PORT}:${LWD_GRPC_PORT}" # gRPC | ||
- "127.0.0.1:${LWD_HTTP_PORT}:${LWD_HTTP_PORT}" # HTTP | ||
|
||
zebra: | ||
image: zfnd/zebra | ||
platform: linux/amd64 | ||
restart: unless-stopped | ||
deploy: | ||
resources: | ||
reservations: | ||
cpus: "4" | ||
memory: 16G | ||
environment: | ||
- RPC_PORT=${ZEBRA_RPC_PORT} | ||
logging: | ||
options: | ||
max-size: "10m" | ||
max-file: "5" | ||
#! Uncomment the `configs` mapping below to use the `zebrad.toml` config file from the host machine | ||
#! NOTE: This will override the zebrad.toml in the image and make some variables irrelevant | ||
# configs: | ||
# - source: zebra_config | ||
# target: /etc/zebrad/zebrad.toml | ||
# uid: '2001' # Rust's container default user uid | ||
# gid: '2001' # Rust's container default group gid | ||
volumes: | ||
- zebrad-cache:/var/cache/zebrad-cache | ||
ports: | ||
# Zebra uses the following default inbound and outbound TCP ports | ||
- "127.0.0.1:8233:8233" # Mainnet Network (for peer connections) | ||
- "127.0.0.1:8232:8232" # Opens an RPC endpoint (for wallet storing and mining) | ||
# - "127.0.0.1:18233:18233" # Testnet Network | ||
# - "127.0.0.1:9999:9999" # Metrics | ||
# - "127.0.0.1:3000:3000" # Tracing | ||
healthcheck: | ||
start_period: 1m | ||
interval: 15s | ||
timeout: 10s | ||
retries: 3 | ||
test: ["CMD-SHELL", "curl --data-binary '{\"jsonrpc\":\"2.0\",\"id\":\"curltest\",\"method\":\"getinfo\",\"params\":[]}' -H 'Content-Type: application/json' http://127.0.0.1:8232 || exit 1"] | ||
|
||
configs: | ||
zebra_config: | ||
# Change the following line to point to a zebrad.toml on your host machine | ||
file: ./docker/zebrad.toml | ||
lwd_config: | ||
# Change the following line to point to a zcash.conf on your host machine | ||
file: ./docker/zebra.conf | ||
|
||
volumes: | ||
litewalletd-data: | ||
driver: local | ||
zebrad-cache: | ||
driver: local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rpcuser=zcashrpc | ||
rpcpassword=notsecure | ||
rpcbind=zebra | ||
rpcport=8232 | ||
testnet=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.