Skip to content

Commit dc8742f

Browse files
committed
feat(docker): add multi-stage Dockerfile for server using xgo, and enabled to targets (scratch and alpine) from the containerfile
1 parent 700e0a0 commit dc8742f

File tree

2 files changed

+90
-24
lines changed

2 files changed

+90
-24
lines changed

docker/Dockerfile.server

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# -------------- Build frontend --------------
2+
FROM --platform=$BUILDPLATFORM docker.io/node:24-alpine AS web-build
3+
4+
RUN corepack enable && corepack prepare pnpm@latest --activate
5+
6+
WORKDIR /src
7+
8+
COPY web/package.json web/pnpm-lock.yaml ./
9+
RUN pnpm install --frozen-lockfile
10+
11+
COPY web/ ./
12+
RUN pnpm build
13+
14+
# -------------- Prepare user --------------
15+
16+
FROM --platform=$BUILDPLATFORM docker.io/golang:1.25 AS prepare
17+
18+
RUN groupadd -g 1000 woodpecker && \
19+
useradd -u 1000 -g 1000 woodpecker && \
20+
mkdir -p /var/lib/woodpecker && \
21+
chown -R woodpecker:woodpecker /var/lib/woodpecker
22+
23+
# -------------- Build backend --------------
24+
25+
FROM --platform=$BUILDPLATFORM docker.io/techknowlogick/xgo:go-1.25.x AS build
26+
27+
ARG TARGETOS TARGETARCH CI_COMMIT_SHA CI_COMMIT_TAG CI_COMMIT_BRANCH
28+
ARG TAGS="sqlite sqlite_unlock_notify"
29+
ARG VERSION="next"
30+
31+
WORKDIR /src
32+
COPY . .
33+
COPY --from=web-build /src/dist ./web/dist
34+
35+
RUN xgo -go go-1.25.x \
36+
-dest /build \
37+
-tags "netgo osusergo grpcnotrace ${TAGS}" \
38+
-ldflags '-linkmode external -X go.woodpecker-ci.org/woodpecker/v3/version.Version=${VERSION} -s -w -extldflags "-static"' \
39+
-targets "${TARGETOS}/${TARGETARCH}" \
40+
-out woodpecker-server \
41+
-pkg cmd/server . && \
42+
ls -la /build/
43+
44+
# -------------- Alpine final image --------------
45+
FROM docker.io/alpine:3.22 AS alpine-final
46+
ARG TARGETOS TARGETARCH
47+
48+
RUN apk add -U --no-cache ca-certificates && \
49+
adduser -u 1000 -g 1000 woodpecker -D && \
50+
mkdir -p /var/lib/woodpecker && \
51+
chown -R woodpecker:woodpecker /var/lib/woodpecker
52+
53+
# from here both final images are identical
54+
ENV GODEBUG=netdns=go \
55+
WOODPECKER_IN_CONTAINER=true \
56+
XDG_CACHE_HOME=/var/lib/woodpecker \
57+
XDG_DATA_HOME=/var/lib/woodpecker
58+
59+
EXPOSE 8000 9000 80 443
60+
COPY --from=build /build/woodpecker-server-* /bin/woodpecker-server
61+
USER woodpecker
62+
HEALTHCHECK CMD ["/bin/woodpecker-server", "ping"]
63+
ENTRYPOINT ["/bin/woodpecker-server"]
64+
65+
# -------------- Scratch final image --------------
66+
FROM scratch AS final
67+
ARG TARGETOS TARGETARCH
68+
69+
COPY --from=prepare /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
70+
COPY --from=prepare /etc/passwd /etc/passwd
71+
COPY --from=prepare /etc/group /etc/group
72+
COPY --from=prepare --chown=woodpecker:woodpecker /var/lib/woodpecker /var/lib/woodpecker
73+
74+
# from here both final images are identical
75+
ENV GODEBUG=netdns=go \
76+
WOODPECKER_IN_CONTAINER=true \
77+
XDG_CACHE_HOME=/var/lib/woodpecker \
78+
XDG_DATA_HOME=/var/lib/woodpecker
79+
80+
EXPOSE 8000 9000 80 443
81+
COPY --from=build /build/woodpecker-server-* /bin/woodpecker-server
82+
USER woodpecker
83+
HEALTHCHECK CMD ["/bin/woodpecker-server", "ping"]
84+
ENTRYPOINT ["/bin/woodpecker-server"]

docs/docs/92-development/07-guides.md

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,17 @@ All official default images, are saved in [shared/constant/constant.go](https://
2727
### Server
2828

2929
```sh
30-
### build web component
31-
make vendor
32-
cd web/
33-
pnpm install --frozen-lockfile
34-
pnpm build
35-
cd ..
36-
37-
### define the platforms to build for (e.g. linux/amd64)
38-
# (the | is not a typo here)
39-
export PLATFORMS='linux|amd64'
40-
make cross-compile-server
41-
42-
### build the image
43-
docker buildx build --platform linux/amd64 -t username/repo:tag -f docker/Dockerfile.server.multiarch.rootless --push .
30+
export PLATFORMS='linux/amd64' # supported 'linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/riscv64'
31+
export TAG='username/repo:tag' # Your image name
32+
docker buildx build . --platform $PLATFORMS -t $TAG -f docker/Dockerfile.server --push # This will push the image to the registry, use --load to load it only locally (only single arch allowed)
4433
```
4534

46-
:::info
47-
The `cross-compile-server` rule makes use of `xgo`, a go cross-compiler. You need to be on a `amd64` host to do this, as `xgo` is only available for `amd64` (see [xgo#213](https://github.com/techknowlogick/xgo/issues/213)).
48-
You can try to use the `build-server` rule instead, however this one fails for some OS (e.g. macOS).
49-
:::
50-
5135
### Agent
5236

5337
```sh
54-
### build the agent
55-
make build-agent
56-
57-
### build the image
58-
docker buildx build --platform linux/amd64 -t username/repo:tag -f docker/Dockerfile.agent.multiarch --push .
38+
export PLATFORMS='linux/amd64' # supported 'linux/386,linux/amd64,freebsd/amd64,openbsd/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,openbsd/arm64,freebsd/arm64,linux/ppc64le,linux/riscv64,linux/s390x'
39+
export TAG='username/repo:tag' # Your image name
40+
docker buildx build . --platform $PLATFORMS -t $TAG -f docker/Dockerfile.agent.multiarch --load # This will push the image to the registry, use --load to load it only locally (only single arch allowed)
5941
```
6042

6143
### CLI

0 commit comments

Comments
 (0)