-
Notifications
You must be signed in to change notification settings - Fork 156
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
Improve Dockerfile to reduce amount of config needed in docker-compose #723
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ WORKDIR /app | |
COPY ui/ ./ | ||
|
||
RUN rm -rf node_modules; \ | ||
yarn install --frozen-lockfile --non-interactive; \ | ||
yarn build | ||
yarn install --frozen-lockfile --non-interactive; \ | ||
yarn build | ||
|
||
# Stage 2: Go Builder | ||
FROM --platform=$TARGETPLATFORM golang:1.22-alpine as go-builder | ||
|
@@ -32,35 +32,28 @@ ARG USER="dagu" | |
ARG USER_UID=1000 | ||
ARG USER_GID=$USER_UID | ||
|
||
# Create user and set permissions | ||
RUN apk update; \ | ||
apk add --no-cache sudo tzdata; \ | ||
addgroup -g ${USER_GID} ${USER}; \ | ||
adduser ${USER} -h /home/${USER} -u ${USER_UID} -G ${USER} -D -s /bin/ash; \ | ||
echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER}; \ | ||
chmod 0440 /etc/sudoers.d/${USER}; \ | ||
mkdir -p .config/dagu/dags; \ | ||
chown -R ${USER}:${USER} /home/${USER}; | ||
|
||
COPY --from=go-builder /app/bin/dagu /usr/local/bin/ | ||
COPY ./entrypoint.sh /entrypoint.sh | ||
|
||
# Create user and set permissions | ||
RUN apk update && \ | ||
apk add --no-cache su-exec shadow tzdata && \ | ||
addgroup -g ${USER_GID} ${USER} && \ | ||
adduser ${USER} -h /config -u ${USER_UID} -G ${USER} -D -s /bin/ash && \ | ||
chown -R ${USER}:${USER} /config && \ | ||
chmod +x /entrypoint.sh; | ||
Comment on lines
-37
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of Ideally |
||
|
||
USER ${USER} | ||
WORKDIR /home/${USER} | ||
WORKDIR /config | ||
|
||
# Add the hello_world.yaml file | ||
COPY --chown=${USER}:${USER} <<EOF .config/dagu/dags/hello_world.yaml | ||
schedule: "* * * * *" | ||
steps: | ||
- name: hello world | ||
command: sh | ||
script: | | ||
echo "Hello, world!" | ||
EOF | ||
Comment on lines
-50
to
-58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could never work as when a user binds over If there is a desire to have an automatically populated hello-world dag, it would have to happen during runtime on the first boot. |
||
|
||
ENV DAGU_HOST=0.0.0.0 | ||
ENV DAGU_PORT=8080 | ||
ENV DAGU_TZ="Etc/UTC" | ||
ENV PUID=${USER_UID} | ||
ENV PGID=${USER_GID} | ||
ENV DOCKER_GID=-1 | ||
|
||
EXPOSE 8080 | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
CMD ["dagu", "start-all"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,28 @@ | ||
.. _Using Docker Compose: | ||
Using Docker Compose | ||
=================================== | ||
|
||
To automate DAG executions based on cron expressions, it is necessary to run both the ui server and scheduler process. Here is an example `docker-compose.yml` setup for running Dagu using Docker Compose. | ||
Here is an example `docker-compose.yml` setup for running Dagu using Docker Compose. | ||
|
||
.. code-block:: yaml | ||
version: "3.9" | ||
services: | ||
# init container updates permission | ||
init: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
user: root | ||
volumes: | ||
- dagu_config:/home/dagu/.config/dagu | ||
- dagu_data:/home/dagu/.local/share | ||
command: chown -R dagu /home/dagu/.config/dagu/ /home/dagu/.local/share | ||
# ui server process | ||
server: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
environment: | ||
- DAGU_PORT=8080 | ||
- DAGU_TZ=Asia/Tokyo | ||
restart: unless-stopped | ||
ports: | ||
- "8080:8080" | ||
volumes: | ||
- dagu_config:/home/dagu/.config/dagu | ||
- dagu_data:/home/dagu/.local/share | ||
command: dagu server | ||
depends_on: | ||
- init | ||
# scheduler process | ||
scheduler: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
environment: | ||
- DAGU_TZ=Asia/Tokyo | ||
restart: unless-stopped | ||
volumes: | ||
- dagu_config:/home/dagu/.config/dagu | ||
- dagu_data:/home/dagu/.local/share | ||
command: dagu scheduler | ||
depends_on: | ||
- init | ||
volumes: | ||
dagu_config: {} | ||
dagu_data: {} | ||
services: | ||
dagu: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
container_name: dagu | ||
hostname: dagu | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
- DAGU_PORT=8080 # optional. default is 8080 | ||
- DAGU_TZ=Asia/Tokyo | ||
- DAGU_BASE_PATH=/dagu # optional. default is / | ||
- PUID=1000 # optional. default is 1000 | ||
- PGID=1000 # optional. default is 1000 | ||
- DOCKER_GID=999 # optional. default is -1 and it will be ignored | ||
volumes: | ||
- dagu_config:/config | ||
- /var/run/docker.sock:/var/run/docker.sock # optional. required for docker in docker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if this was worth including here. It maybe the comment should mention the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the great suggestion! I believe this would be a valuable addition to include here. I think mentioning socat would be nice, but I also like the current focus on the docker-compose configuration. So, let's leave it as it is for now. |
||
volumes: | ||
dagu_config: {} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env /bin/sh | ||
|
||
echo "Starting entrypoint.sh" | ||
|
||
echo " | ||
PUID=${PUID} | ||
PGID=${PGID} | ||
DOCKER_GID=${DOCKER_GID} | ||
TZ=${DAGU_TZ} | ||
" | ||
|
||
# Check if both DOCKER_GID is not -1. This indicates the desire for a docker group | ||
if [ "$DOCKER_GID" != "-1" ]; then | ||
if ! getent group docker >/dev/null; then | ||
echo "Creating docker group with GID ${DOCKER_GID}" | ||
addgroup -g ${DOCKER_GID} docker | ||
usermod -a -G docker dagu | ||
fi | ||
|
||
echo "Changing docker group GID to ${DOCKER_GID}" | ||
groupmod -o -g "$DOCKER_GID" docker | ||
fi | ||
|
||
groupmod -o -g "$PGID" dagu | ||
usermod -o -u "$PUID" dagu | ||
|
||
mkdir -p /config | ||
|
||
chown $PUID:$PGID -R /config | ||
|
||
# If DAGU_HOME is not set, try to guess if the legacy /home directory is being | ||
# used. If so set the HOME to /home/dagu. Otherwise force the /config directory | ||
# as DAGU_HOME | ||
if [ -z "$DAGU_HOME" ]; then | ||
if [ -d /home/dagu/.config/dagu ]; then | ||
echo "WARNING: Using legacy /home/dagu directory. Please consider moving to /config" | ||
usermod -d /home/dagu dagu | ||
chown $PUID:$PGID -R /home/dagu | ||
else | ||
Comment on lines
+35
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check isn't the best, but it should cover most cases. We mirror what the "init" part of the original docker-compose stack did by chowning the directory. |
||
# For ease of use set DAGU_HOME to /config so all data is located in a | ||
# single directory | ||
export DAGU_HOME=/config | ||
fi | ||
fi | ||
|
||
# Run all scripts in /etc/custom-init.d. It assumes that all scripts are | ||
# executable | ||
if [ -d /etc/custom-init.d ]; then | ||
for f in /etc/custom-init.d/*; do | ||
if [ -x "$f" ]; then | ||
echo "Running $f" | ||
$f | ||
fi | ||
done | ||
fi | ||
|
||
# If DOCKER_GID is not -1 set RUN_GID to DOCKER_GID otherwise set to PGID | ||
if [ "$DOCKER_GID" != "-1" ]; then | ||
RUN_GID=$DOCKER_GID | ||
else | ||
RUN_GID=$PGID | ||
fi | ||
|
||
# Run the command as the dagu user and optionally the docker group | ||
su-exec $PUID:$RUN_GID "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,19 @@ | ||
version: "3.9" | ||
services: | ||
# init container updates permission | ||
init: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
user: root | ||
volumes: | ||
- dagu_config:/home/dagu/.config/dagu | ||
- dagu_data:/home/dagu/.local/share | ||
command: chown -R dagu /home/dagu/.config/dagu/ /home/dagu/.local/share | ||
# ui server process | ||
server: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
environment: | ||
- DAGU_PORT=8080 | ||
- DAGU_TZ=Asia/Tokyo | ||
restart: unless-stopped | ||
ports: | ||
- "8080:8080" | ||
volumes: | ||
- dagu_config:/home/dagu/.config/dagu | ||
- dagu_data:/home/dagu/.local/share | ||
depends_on: | ||
- init | ||
# scheduler process | ||
scheduler: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
environment: | ||
- DAGU_TZ=Asia/Tokyo | ||
restart: unless-stopped | ||
volumes: | ||
- dagu_config:/home/dagu/.config/dagu | ||
- dagu_data:/home/dagu/.local/share | ||
command: dagu scheduler | ||
depends_on: | ||
- init | ||
dagu: | ||
image: "ghcr.io/dagu-org/dagu:latest" | ||
container_name: dagu | ||
hostname: dagu | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
- DAGU_PORT=8080 # optional. default is 8080 | ||
- DAGU_TZ=Asia/Tokyo | ||
- DAGU_BASE_PATH=/dagu # optional. default is / | ||
- PUID=1000 # optional. default is 1000 | ||
- PGID=1000 # optional. default is 1000 | ||
- DOCKER_GID=999 # optional. default is -1 and it will be ignored | ||
volumes: | ||
- dagu_config:/config | ||
- /var/run/docker.sock:/var/run/docker.sock # optional. required for docker in docker | ||
volumes: | ||
dagu_config: {} | ||
dagu_data: {} | ||
dagu_config: {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My editor kept formatting this - happy to revert if it is undesired.