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 4bfbc2c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
24 changes: 15 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,25 @@ 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
FROM gcr.io/distroless/cc:debug as debug

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 @@ -117,21 +115,24 @@ COPY --from=test_debug /app/ /usr/
RUN printf "\n in debug mode \n \n run 'exec /usr/bin/torrust-tracker' (debug build) to start tracker \n \n" > /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}"
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
USER "torrust":"torrust"

RUN env

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

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

ENV USER_ID=${USER_ID}
ENV UDP_PORT=${UDP_PORT}
ENV HTTP_PORT=${HTTP_PORT}
ENV API_PORT=${API_PORT}
Expand All @@ -141,6 +142,11 @@ 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"]

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
USER "torrust":"torrust"

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

0 comments on commit 4bfbc2c

Please sign in to comment.