-
Notifications
You must be signed in to change notification settings - Fork 102
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 2 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 |
|---|---|---|
| @@ -1,22 +1,110 @@ | ||
| FROM golang:1.22 AS lightwalletd_base | ||
| # /************************************************************************ | ||
| # File: Dockerfile | ||
| # Author: gustavovalverde | ||
| # Date: 26/02/2023 | ||
| # Description: Used for devs that have not built zcashd or lightwalletd on | ||
| # on existing system | ||
| # USAGE: | ||
| # | ||
| # To build image: docker build --target runner --tag zcash_lwd_base . | ||
| # To run container: docker run --detach -it -p 9067:9067 -p 9068:9068 zcash_lwd_base | ||
| # | ||
| # Once the block height is at least 280,000 you can go ahead and start lightwalletd | ||
| # make docker_img_run_lightwalletd_insecure_server | ||
| # | ||
| # If you need a random bash session in the container, use: | ||
| # docker exec -it zcashdlwd bash | ||
| # | ||
| # If you get kicked out of docker or it locks up... | ||
| # To restart, check to see what container you want to restart via docker ps -a | ||
| # Then, docker restart <container id> | ||
| # The reattach to it, docker attach <container id> | ||
| # | ||
| # Known bugs/missing features/todos: | ||
| # | ||
| # *** DO NOT USE IN PRODUCTION *** | ||
| # | ||
| # - Create docker-compose with according .env scaffolding | ||
| # - Determine librustzcash bug that breaks zcashd alpine builds at runtime | ||
| # - Once versioning is stable add config flags for images | ||
| # - Add mainnet config once lightwalletd stack supports it | ||
| # | ||
| # ************************************************************************/ | ||
| ARG APP_HOME=/srv/lightwalletd | ||
| ARG ZCASHD_CONF_PATH=$APP_HOME/zcash.conf | ||
| ARG LWD_GRPC_PORT=9067 | ||
| ARG LWD_HTTP_PORT=9068 | ||
|
|
||
| ADD . /go/src/github.com/zcash/lightwalletd | ||
| WORKDIR /go/src/github.com/zcash/lightwalletd | ||
| RUN make \ | ||
| && /usr/bin/install -c ./lightwalletd /usr/local/bin/ \ | ||
| && mkdir -p /var/lib/lightwalletd/db \ | ||
| && chown 2002:2002 /var/lib/lightwalletd/db | ||
| ## | ||
| ## Builder | ||
| ## | ||
| # Create layer in case you want to modify local lightwalletd code | ||
| FROM golang:1.22 AS build | ||
|
|
||
| # 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 | ||
|
|
||
| ARG ZCASHD_CONF_PATH | ||
|
|
||
| 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"; \ | ||
| } > "/etc/zcash.conf" | ||
|
|
||
| ## | ||
| ## Runner | ||
| ## | ||
| FROM debian:bookworm-slim as runner | ||
|
|
||
| # Get the needed ARGs values | ||
| ARG APP_HOME | ||
| ARG ZCASHD_CONF_PATH | ||
| ARG LWD_GRPC_PORT | ||
| ARG LWD_HTTP_PORT | ||
| 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 | ||
| USER $LWD_USER | ||
| WORKDIR /srv/$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 --from=build --chown=${LWD_USER}:${LWD_USER} /etc/zcash.conf ./ | ||
| COPY ./docker/cert.key ./ | ||
| COPY ./docker/cert.pem ./ | ||
|
|
||
| EXPOSE $LWD_GRPC_PORT | ||
| EXPOSE $LWD_HTTP_PORT | ||
|
|
||
| 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
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.