Repository navigation
Expand file tree
/
Copy pathDockerfile.dev
More file actions
138 lines (127 loc) · 4.51 KB
/
Copy pathDockerfile.dev
File metadata and controls
138 lines (127 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# syntax=docker/dockerfile:1.4
# Stage 1: UI Builder
FROM --platform=$BUILDPLATFORM node:26-alpine AS ui-builder
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg && \
npm install -g corepack@latest && corepack enable
WORKDIR /app
COPY ui/package.json ui/pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY ui/ ./
RUN pnpm build
# Stage 2: Go Builder
FROM --platform=$TARGETPLATFORM golang:1.27.4 AS go-builder
ARG LDFLAGS
ARG TARGETOS
ARG TARGETARCH
RUN if ! command -v g++ >/dev/null; then \
apt-get update && \
apt-get install -y --no-install-recommends g++ && \
rm -rf /var/lib/apt/lists/*; \
fi
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
COPY --from=ui-builder /app/dist/ ./internal/service/frontend/assets/
COPY schemas/dag.schema.json ./internal/service/frontend/assets/
RUN CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -tags netgo,osusergo -ldflags="${LDFLAGS} -linkmode=external -extldflags=-static" -o ./bin/dagu ./cmd
# Stage 3: Final Image
FROM --platform=$TARGETPLATFORM ubuntu:24.04
ARG USER="dagu"
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG DAGU_HOME="/var/lib/dagu"
# Install common tools
ENV DEBIAN_FRONTEND=noninteractive
# Install common tools without cache mounts to avoid multi-platform conflicts
RUN set -ex && \
for attempt in 1 2 3 4 5; do \
rm -rf /var/lib/apt/lists/*; \
apt-get update -o Acquire::Retries=5 \
-o APT::Update::Error-Mode=any && \
apt-get -o Acquire::Retries=5 install -y --no-install-recommends \
sudo \
tini \
git \
curl \
wget \
zip \
unzip \
tzdata \
build-essential \
jq \
python3 \
python3-pip \
openjdk-17-jdk \
nodejs \
npm \
ca-certificates \
&& break; \
if [ "$attempt" = 5 ]; then exit 1; fi; \
apt-get clean; \
sleep $((attempt * 10)); \
done && \
apt-get clean && rm -rf /var/lib/apt/lists/*; \
ln -sf /usr/bin/tini /usr/local/bin/tini
# Chromium for browser steps. Ubuntu ships Chromium only as a snap, so the
# build comes from Playwright, which provides amd64 and arm64. Playwright
# 1.61 is the last release that runs on Ubuntu's Node.js 18.
ARG TARGETARCH
ARG PLAYWRIGHT_VERSION=1.61.1
RUN set -ex; \
if [ "$TARGETARCH" = "amd64" ] || [ "$TARGETARCH" = "arm64" ]; then \
PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright \
npx --yes "playwright@${PLAYWRIGHT_VERSION}" install --with-deps --no-shell chromium && \
ln -s "$(find /opt/ms-playwright -type f -name chrome -path '*/chromium-*' | head -n 1)" /usr/local/bin/chromium && \
/usr/local/bin/chromium --version && \
apt-get clean && rm -rf /var/lib/apt/lists/* /root/.npm; \
fi
# Chromium keeps its sandbox. The seccomp profile it needs to start is
# bundled so that it can be copied out of the image; deploy/docker/browser has
# a Compose file that applies it.
ENV CHROME_PATH=/usr/local/bin/chromium
COPY deploy/docker/browser/seccomp-chromium.json /usr/share/dagu/seccomp-chromium.json
COPY --from=go-builder /app/bin/dagu /usr/local/bin/
COPY ./entrypoint.sh /entrypoint.sh
RUN set -eux; \
# Try to create group with specified GID, fallback if GID in use
(groupadd -g "${USER_GID}" "${USER}" || groupadd "${USER}") && \
# Try to create user with specified UID, fallback if UID in use
(useradd -m -d /home/${USER} \
-u "${USER_UID}" \
-g "$(getent group "${USER}" | cut -d: -f3)" \
-s /bin/bash \
"${USER}" \
|| useradd -m -d /home/${USER} \
-g "$(getent group "${USER}" | cut -d: -f3)" \
-s /bin/bash \
"${USER}") && \
chmod +x /entrypoint.sh
# Create user and set permissions
RUN set -eux; \
{ \
echo 'dagu ALL=(ALL) NOPASSWD:ALL'; \
echo 'Defaults:dagu !requiretty'; \
} > /etc/sudoers.d/99-dagu && \
chmod 0440 /etc/sudoers.d/99-dagu && \
visudo -cf /etc/sudoers.d/99-dagu
# Delete the default ubuntu user if it exists
RUN userdel -f ubuntu || true
# Create the DAGU_HOME directory and set permissions
RUN mkdir -p "${DAGU_HOME}" && \
chown -R "${USER_UID}:${USER_GID}" "${DAGU_HOME}" && \
chmod 755 "${DAGU_HOME}"
WORKDIR /home/${USER}
ENV DAGU_HOST=0.0.0.0
ENV DAGU_PORT=8080
ENV DAGU_HOME=${DAGU_HOME}
ENV DAGU_TZ="Etc/UTC"
ENV PUID=${USER_UID}
ENV PGID=${USER_GID}
ENV DOCKER_GID=-1
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/tini", "-g", "--", "/entrypoint.sh"]
CMD ["dagu", "start-all"]