Skip to content

Commit

Permalink
dev: more docker work
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Aug 25, 2023
1 parent a75a96a commit 971b26e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ config.toml
config.toml.local
cSpell.json
data.db
docker/
/docker/bin/
NOTICE
README.md
rustfmt.toml
Expand Down
45 changes: 15 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,23 @@ RUN cargo nextest run --workspace-remap /test/src/ --extract-to /test/src/ --no-
RUN cargo nextest run --workspace-remap /test/src/ --target-dir-remap /test/src/target/ --cargo-metadata /test/src/target/nextest/cargo-metadata.json --binaries-metadata /test/src/target/nextest/binaries-metadata.json

RUN mkdir -p /app/bin/; cp -l /test/src/target/release/torrust-tracker /app/bin/torrust-tracker
RUN mkdir /app/lib/; cp -l $(realpath $(ldd /app/bin/torrust-tracker | grep "libz\.so\.1" | awk '{print $3}')) /app/lib/libz.so.1
RUN mkdir -p /app/lib/; cp -l $(realpath $(ldd /app/bin/torrust-tracker | grep "libz\.so\.1" | awk '{print $3}')) /app/lib/libz.so.1

RUN chown -R root:root /app
RUN chmod -R u=rw,go=r,a+X /app
RUN chmod -R a+x /app/bin


## Torrust-Tracker (debug)
FROM gcr.io/distroless/cc:debug as tracker_debug

## Runtime
FROM gcr.io/distroless/cc:debug as Runtime
RUN ["/busybox/cp", "-sp", "/busybox/sh", "/bin/sh"]
ENV ENV=/etc/profile

ARG USER_ID=1000
ARG USER_NAME=appuser
ARG UDP_PORT=6969
ARG HTTP_PORT=7070
ARG API_PORT=1212

ENV USER_ID=${USER_ID}
ENV USER_NAME=${USER_NAME}
ENV UDP_PORT=${UDP_PORT}
ENV HTTP_PORT=${HTTP_PORT}
ENV API_PORT=${API_PORT}
Expand All @@ -112,35 +108,24 @@ EXPOSE ${UDP_PORT}/udp
EXPOSE ${HTTP_PORT}/tcp
EXPOSE ${API_PORT}/tcp

COPY --from=test_debug /app/ /usr/
WORKDIR /home/torrust
RUN adduser --disabled-password --uid "${USER_ID}" "torrust"
RUN mkdir -p /var/lib/torrust; chown -R "${USER_ID}":"${USER_ID}" /var/lib/torrust; chmod -R 2775 /var/lib/torrust

RUN printf "\n in debug mode \n \n run 'exec /usr/bin/torrust-tracker' (debug build) to start tracker \n \n" > /etc/motd
ENV ENV=/etc/profile
COPY ./docker/motd.debug /etc/motd
RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' >> /etc/profile

WORKDIR /home/${USER_NAME}
RUN adduser --disabled-password --uid "${USER_ID}" "${USER_NAME}"
USER "${USER_NAME}":"${USER_NAME}"
USER "torrust":"torrust"


## Torrust-Tracker (debug)
FROM runtime as debug
COPY --from=test_debug /app/ /usr/
RUN env

## Torrust-Tracker (release) (default)
FROM gcr.io/distroless/cc:nonroot as tracker
COPY --from=gcr.io/distroless/cc:debug /busybox/wget /usr/bin/wget
FROM runtime as release
COPY --from=test /app/ /usr/

ARG UDP_PORT=6969
ARG HTTP_PORT=7070
ARG API_PORT=1212

ENV UDP_PORT=${UDP_PORT}
ENV HTTP_PORT=${HTTP_PORT}
ENV API_PORT=${API_PORT}
ENV TZ=Etc/UTC

EXPOSE ${UDP_PORT}/udp
EXPOSE ${HTTP_PORT}/tcp
EXPOSE ${API_PORT}/tcp

# HEALTHCHECK ["/usr/bin/wget", "--no-verbose", "--tries=1", "--spider", "localhost:${API_PORT}/version"]

# HEALTHCHECK CMD ["/usr/bin/wget", "--no-verbose", "--tries=1", "--spider", "localhost:${API_PORT}/version"]
CMD ["/usr/bin/torrust-tracker"]
15 changes: 5 additions & 10 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ name: torrust
services:

tracker:
pull_policy: missing
image: torrust-tracker:local
# build:
# context: .
# tags:
# - torrust-tracker:local

user: ${USER_UID:-1000}:${USER_UID:-1000}
image: torrust-tracker:debug
tty: true
environment:
- TORRUST_TRACKER_CONFIG=${TORRUST_TRACKER_CONFIG}
- TORRUST_TRACKER_API_TOKEN=${TORRUST_TRACKER_API_TOKEN:-MyAccessToken}
networks:
- server_side
ports:
- 6969:6969/udp
- 7070:7070
- 1212:1212
volumes:
- ./:/app/src
- ./storage:/app/storage
- ./storage:/var/lib/torrust/tracker
depends_on:
- mysql

Expand Down
17 changes: 9 additions & 8 deletions docker/bin/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash

TORRUST_TRACKER_USER_UID=${TORRUST_TRACKER_USER_UID:-1000}
TORRUST_TRACKER_RUN_AS_USER=${TORRUST_TRACKER_RUN_AS_USER:-appuser}
CURRENT_USER_NAME=$(whoami)
CURRENT_USER_ID=$(id -u)
echo "User name: $CURRENT_USER_NAME"
echo "User id: $CURRENT_USER_ID"

USER_ID=$CURRENT_USER_ID
export USER_ID


echo "Building docker image ..."
echo "TORRUST_TRACKER_USER_UID: $TORRUST_TRACKER_USER_UID"
echo "TORRUST_TRACKER_RUN_AS_USER: $TORRUST_TRACKER_RUN_AS_USER"

docker build \
--build-arg UID="$TORRUST_TRACKER_USER_UID" \
--build-arg RUN_AS_USER="$TORRUST_TRACKER_RUN_AS_USER" \
-t torrust-tracker .
docker build --target debug --tag torrust-tracker:debug .
6 changes: 3 additions & 3 deletions docker/bin/run-local-image.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

TORRUST_TRACKER_USER_UID=${TORRUST_TRACKER_USER_UID:-1000}
TORRUST_TRACKER_CONFIG=$(cat config.toml)

docker run -it \
--user="$TORRUST_TRACKER_USER_UID" \
--user="$(whoami)" \
--publish 6969:6969/udp \
--publish 7070:7070/tcp \
--publish 1212:1212/tcp \
--env TORRUST_TRACKER_CONFIG="$TORRUST_TRACKER_CONFIG" \
--volume "$(pwd)/storage":"/app/storage" \
torrust-tracker
--entrypoint torrust-tracker \
torrust-tracker:debug
4 changes: 2 additions & 2 deletions docker/bin/run-public-image.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

TORRUST_TRACKER_USER_UID=${TORRUST_TRACKER_USER_UID:-1000}
TORRUST_TRACKER_CONFIG=$(cat config.toml)

docker run -it \
--user="$TORRUST_TRACKER_USER_UID" \
--user="$(whoami)" \
--publish 6969:6969/udp \
--publish 7070:7070/tcp \
--publish 1212:1212/tcp \
--env TORRUST_TRACKER_CONFIG="$TORRUST_TRACKER_CONFIG" \
--volume "$(pwd)/storage":"/app/storage" \
--entrypoint torrust-tracker \
torrust/tracker
3 changes: 3 additions & 0 deletions docker/motd.debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
in debug mode

run 'torrust-tracker' to start tracker

0 comments on commit 971b26e

Please sign in to comment.