Skip to content
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

chore: update the Dockerfile & docs #699

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ RUN apk update; \
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};

USER ${USER}
WORKDIR /home/${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/

RUN mkdir -p .config/dagu/dags
USER ${USER}
WORKDIR /home/${USER}

# Add the hello_world.yaml file
COPY <<EOF .config/dagu/dags/hello_world.yaml
COPY --chown=${USER}:${USER} <<EOF .config/dagu/dags/hello_world.yaml
schedule: "* * * * *"
steps:
- name: hello world
Expand All @@ -59,6 +59,7 @@ EOF

ENV DAGU_HOST=0.0.0.0
ENV DAGU_PORT=8080
ENV DAGU_TZ="Etc/UTC"

EXPOSE 8080

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ docker run \
-p 8080:8080 \
-v $HOME/.config/dagu/dags:/home/dagu/.config/dagu/dags \
-v $HOME/.local/share/dagu:/home/dagu/.local/share/dagu \
-e DAGU_TZ=Asia/Tokyo \
ghcr.io/dagu-org/dagu:latest dagu start-all
```

Note: The environment variable `DAGU_TZ` is the timezone for the scheduler and server. You can set it to your local timezone.

See [Environment variables](https://dagu.readthedocs.io/en/latest/config.html#environment-variables) to configure those default directories.

## **Quick Start Guide**
Expand Down
3 changes: 3 additions & 0 deletions docs/source/docker-compose.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ To automate DAG executions based on cron expressions, it is necessary to run bot
image: "ghcr.io/dagu-org/dagu:latest"
environment:
- DAGU_PORT=8080
- DAGU_TZ=Asia/Tokyo
restart: unless-stopped
ports:
- "8080:8080"
Expand All @@ -32,6 +33,8 @@ To automate DAG executions based on cron expressions, it is necessary to run bot
# 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
Expand Down
85 changes: 51 additions & 34 deletions docs/source/docker.rst
Original file line number Diff line number Diff line change
@@ -1,57 +1,74 @@
Building Docker Image
=====================

Create the ``Dockerfile`` and you can build an image.
Example Dockerfile for building a multi-platform image:

.. code-block:: dockerfile

# syntax=docker/dockerfile:1.4
FROM --platform=$BUILDPLATFORM alpine:latest

# Stage 1: UI Builder
FROM --platform=$BUILDPLATFORM node:18-alpine as ui-builder

WORKDIR /app
COPY ui/ ./

RUN rm -rf node_modules; \
yarn install --frozen-lockfile --non-interactive; \
yarn build

# Stage 2: Go Builder
FROM --platform=$TARGETPLATFORM golang:1.22-alpine as go-builder

ARG LDFLAGS
ARG TARGETOS
ARG TARGETARCH
ARG VERSION=
ARG RELEASES_URL="https://github.com/dagu-org/dagu/releases"

WORKDIR /app
COPY . .

RUN go mod download && rm -rf frontend/assets
COPY --from=ui-builder /app/dist/ ./internal/frontend/assets/

RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="${LDFLAGS}" -o ./bin/dagu .

# Stage 3: Final Image
FROM --platform=$TARGETPLATFORM alpine:latest

ARG USER="dagu"
ARG USER_UID=1000
ARG USER_GID=$USER_UID

EXPOSE 8080
# 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};

RUN <<EOF
#User and permissions setup
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}
EOF
COPY --from=go-builder /app/bin/dagu /usr/local/bin/

USER ${USER}
WORKDIR /home/${USER}

USER dagu
WORKDIR /home/dagu
RUN <<EOF
#dagu binary setup
if [ "${TARGETARCH}" == "amd64" ]; then
arch="x86_64";
else
arch="${TARGETARCH}"
fi
export TARGET_FILE="dagu_${VERSION}_Linux_${arch}.tar.gz"
wget ${RELEASES_URL}/download/v${VERSION}/${TARGET_FILE}
tar -xf ${TARGET_FILE} && rm *.tar.gz
sudo mv dagu /usr/local/bin/
mkdir .dagu
# 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

ENV DAGU_HOST=0.0.0.0
ENV DAGU_PORT=8080
ENV DAGU_TZ="Etc/UTC"

CMD dagu server
EXPOSE 8080

For example::
CMD ["dagu", "start-all"]

DAGU_VERSION=<X.X.X>
docker build -t dagu:${DAGU_VERSION} \
--build-arg VERSION=${DAGU_VERSION} \
--no-cache .
3 changes: 3 additions & 0 deletions examples/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
image: "ghcr.io/dagu-org/dagu:latest"
environment:
- DAGU_PORT=8080
- DAGU_TZ=Asia/Tokyo
restart: unless-stopped
ports:
- "8080:8080"
Expand All @@ -24,6 +25,8 @@ services:
# 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
Expand Down
Loading