Skip to content

Commit d321f37

Browse files
refactor(docker): streamline Zebra configuration handling in entrypoint script
1 parent 0852e0f commit d321f37

File tree

4 files changed

+140
-119
lines changed

4 files changed

+140
-119
lines changed

docker/Dockerfile

+2-12
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ COPY --from=electriccoinco/lightwalletd:latest /usr/local/bin/lightwalletd /usr/
120120
# and allow to change permissions for mounted cache directories
121121
COPY --from=tianon/gosu:bookworm /gosu /usr/local/bin/
122122

123-
# Use the same default config as in the production environment.
124-
ENV ZEBRA_CONF_PATH="${HOME}/.config/zebrad.toml"
125-
COPY --chown=${UID}:${GID} ./docker/default-zebra-config.toml ${ZEBRA_CONF_PATH}
126-
127123
# As the build has already run with the root user,
128124
# we need to set the correct permissions for the home and cargo home dirs owned by it.
129125
RUN chown -R ${UID}:${GID} "${HOME}" && \
@@ -140,7 +136,9 @@ ENTRYPOINT [ "entrypoint.sh", "test" ]
140136
# `test` stage. The resulting zebrad binary is used in the `runtime` stage.
141137
FROM deps AS release
142138

139+
# Set the working directory for the build.
143140
ARG HOME
141+
WORKDIR ${HOME}
144142

145143
RUN --mount=type=bind,source=tower-batch-control,target=tower-batch-control \
146144
--mount=type=bind,source=tower-fallback,target=tower-fallback \
@@ -198,15 +196,8 @@ RUN addgroup --quiet --gid ${GID} ${USER} && \
198196
adduser --quiet --gid ${GID} --uid ${UID} --home ${HOME} ${USER} --disabled-password --gecos ""
199197

200198
WORKDIR ${HOME}
201-
202-
# We set the default locations of the conf and cache dirs according to the XDG
203-
# spec: https://specifications.freedesktop.org/basedir-spec/latest/
204-
205199
RUN chown -R ${UID}:${GID} ${HOME}
206200

207-
ARG ZEBRA_CONF_PATH="${HOME}/.config/zebrad.toml"
208-
ENV ZEBRA_CONF_PATH=${ZEBRA_CONF_PATH}
209-
210201
# We're explicitly NOT using the USER directive here.
211202
# Instead, we run as root initially and use gosu in the entrypoint.sh
212203
# to step down to the non-privileged user. This allows us to change permissions
@@ -216,7 +207,6 @@ ENV ZEBRA_CONF_PATH=${ZEBRA_CONF_PATH}
216207
# Copy the gosu binary to be able to run the entrypoint as non-root user
217208
COPY --from=tianon/gosu:bookworm /gosu /usr/local/bin/
218209
COPY --from=release /usr/local/bin/zebrad /usr/local/bin/
219-
COPY --chown=${UID}:${GID} ./docker/default-zebra-config.toml ${ZEBRA_CONF_PATH}
220210
COPY --chown=${UID}:${GID} ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
221211

222212
ENTRYPOINT [ "entrypoint.sh" ]

docker/default-zebra-config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cache_dir = "/home/zebra/.cache/zebra"
2323
# listen_addr = "0.0.0.0:8232" # Mainnet
2424
# listen_addr = "0.0.0.0:18232" # Testnet
2525

26-
cookie_dir = "/home/zebra/.cache/zebra"
26+
cookie_dir = "/home/zebra/.config/cookie"
2727

2828
# To disable cookie authentication, uncomment the line below and set the value
2929
# to false.

docker/docker-compose.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
services:
22
zebra:
33
container_name: zebra
4+
build:
5+
context: ../
6+
dockerfile: docker/Dockerfile
7+
target: runtime
8+
# user: 10001:10001
49
image: zfnd/zebra
510
platform: linux/amd64
611
restart: unless-stopped
@@ -12,15 +17,12 @@ services:
1217
env_file:
1318
- .env
1419
volumes:
15-
- zebrad-cache:/home/zebra/.cache/zebra
20+
- zebrad-cache:/home/zebra/.cache/
1621
# Having `tty` set to true makes Zebra use colored logs.
1722
tty: true
18-
#! Uncomment the `configs` mapping below to make your custom configuration
19-
#! take effect.
20-
#
21-
# configs:
22-
# - source: zebra-config
23-
# target: /home/zebra/.config/zebrad.toml
23+
configs:
24+
- source: zebra-config
25+
target: /home/zebra/.config/zebrad.toml
2426
#
2527
# Uncomment the `ports` mapping below to map ports between the container and
2628
# host.
@@ -35,10 +37,9 @@ services:
3537

3638
configs:
3739
zebra-config:
38-
#! To customize the default configuration, edit this file before starting
40+
#! To use a different configuration file, edit this file before starting
3941
#! the container.
4042
file: ./default-zebra-config.toml
4143

4244
volumes:
4345
zebrad-cache:
44-
driver: local

0 commit comments

Comments
 (0)