mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-05 07:08:41 +00:00
Build multiarch images for server (#821)
Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
09e6460f95
commit
da99f47553
8 changed files with 76 additions and 44 deletions
|
@ -3,6 +3,9 @@ depends_on:
|
||||||
- web
|
- web
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
|
###############
|
||||||
|
# S e r v e r #
|
||||||
|
###############
|
||||||
build-web:
|
build-web:
|
||||||
image: node:16-alpine
|
image: node:16-alpine
|
||||||
commands:
|
commands:
|
||||||
|
@ -10,59 +13,61 @@ pipeline:
|
||||||
- yarn install --frozen-lockfile
|
- yarn install --frozen-lockfile
|
||||||
- yarn build
|
- yarn build
|
||||||
|
|
||||||
###############
|
cross-compile-server:
|
||||||
# S e r v e r #
|
image: techknowlogick/xgo:go-1.17.x
|
||||||
###############
|
|
||||||
|
|
||||||
# TODO: needed until https://github.com/woodpecker-ci/woodpecker/pull/635
|
|
||||||
build-server:
|
|
||||||
image: golang:1.17
|
|
||||||
commands:
|
commands:
|
||||||
- make release-server
|
- apt update
|
||||||
|
- apt install -y tree
|
||||||
|
- make cross-compile-server
|
||||||
|
environment:
|
||||||
|
PLATFORMS: linux|arm/v7;linux|arm64/v8;linux|amd64;linux|ppc64le
|
||||||
|
TAGS: bindata sqlite sqlite_unlock_notify
|
||||||
|
|
||||||
publish-server-dryrun:
|
publish-server-dryrun:
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
group: docker
|
group: docker
|
||||||
secrets: [docker_username, docker_password]
|
|
||||||
settings:
|
settings:
|
||||||
dry_run: true
|
dry_run: true
|
||||||
repo: woodpeckerci/woodpecker-server
|
repo: woodpeckerci/woodpecker-server
|
||||||
dockerfile: docker/Dockerfile.server
|
dockerfile: docker/Dockerfile.server.multiarch
|
||||||
tag: next
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
|
tag: test
|
||||||
when:
|
when:
|
||||||
event: pull_request
|
event: pull_request
|
||||||
|
|
||||||
publish-server-alpine-dryrun:
|
publish-server-alpine-dryrun:
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
group: docker
|
group: docker
|
||||||
secrets: [ docker_username, docker_password ]
|
|
||||||
settings:
|
settings:
|
||||||
dry_run: true
|
dry_run: true
|
||||||
repo: woodpeckerci/woodpecker-server
|
repo: woodpeckerci/woodpecker-server
|
||||||
dockerfile: docker/Dockerfile.server.alpine
|
dockerfile: docker/Dockerfile.server.alpine.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
tag: next-alpine
|
tag: next-alpine
|
||||||
when:
|
when:
|
||||||
event: pull_request
|
event: pull_request
|
||||||
|
|
||||||
publish-next-server:
|
publish-next-server:
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
group: docker
|
group: docker
|
||||||
secrets: [docker_username, docker_password]
|
secrets: [docker_username, docker_password]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-server
|
repo: woodpeckerci/woodpecker-server
|
||||||
dockerfile: docker/Dockerfile.server
|
dockerfile: docker/Dockerfile.server.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
tag: next
|
tag: next
|
||||||
when:
|
when:
|
||||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||||
event: push
|
event: push
|
||||||
|
|
||||||
publish-next-server-alpine:
|
publish-next-server-alpine:
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
group: docker
|
group: docker
|
||||||
secrets: [ docker_username, docker_password ]
|
secrets: [ docker_username, docker_password ]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-server
|
repo: woodpeckerci/woodpecker-server
|
||||||
dockerfile: docker/Dockerfile.server.alpine
|
dockerfile: docker/Dockerfile.server.alpine.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
tag: next-alpine
|
tag: next-alpine
|
||||||
when:
|
when:
|
||||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
@ -94,11 +99,12 @@ pipeline:
|
||||||
|
|
||||||
release-server:
|
release-server:
|
||||||
group: docker
|
group: docker
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [docker_username, docker_password]
|
secrets: [docker_username, docker_password]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-server
|
repo: woodpeckerci/woodpecker-server
|
||||||
dockerfile: docker/Dockerfile.server
|
dockerfile: docker/Dockerfile.server.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
# remove 'latest' on older version branches to avoid accidental downgrade
|
# remove 'latest' on older version branches to avoid accidental downgrade
|
||||||
tag: [latest, "${CI_COMMIT_TAG}"]
|
tag: [latest, "${CI_COMMIT_TAG}"]
|
||||||
when:
|
when:
|
||||||
|
@ -106,11 +112,12 @@ pipeline:
|
||||||
|
|
||||||
release-server-alpine:
|
release-server-alpine:
|
||||||
group: docker
|
group: docker
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [ docker_username, docker_password ]
|
secrets: [ docker_username, docker_password ]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-server
|
repo: woodpeckerci/woodpecker-server
|
||||||
dockerfile: docker/Dockerfile.server.alpine
|
dockerfile: docker/Dockerfile.server.alpine.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
# remove 'latest-alpine' on older version branches to avoid accidental downgrade
|
# remove 'latest-alpine' on older version branches to avoid accidental downgrade
|
||||||
tag: [latest-alpine, "${CI_COMMIT_TAG}-alpine"]
|
tag: [latest-alpine, "${CI_COMMIT_TAG}-alpine"]
|
||||||
when:
|
when:
|
||||||
|
|
32
Makefile
32
Makefile
|
@ -19,6 +19,13 @@ ifeq ($(BUILD_VERSION),next)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LDFLAGS := -s -w -extldflags "-static" -X github.com/woodpecker-ci/woodpecker/version.Version=${BUILD_VERSION}
|
LDFLAGS := -s -w -extldflags "-static" -X github.com/woodpecker-ci/woodpecker/version.Version=${BUILD_VERSION}
|
||||||
|
CGO_CFLAGS ?=
|
||||||
|
|
||||||
|
HAS_GO = $(shell hash go > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
||||||
|
ifeq ($(HAS_GO), GO)
|
||||||
|
XGO_VERSION ?= go-1.17.x
|
||||||
|
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
# If the first argument is "in_docker"...
|
# If the first argument is "in_docker"...
|
||||||
ifeq (in_docker,$(firstword $(MAKECMDGOALS)))
|
ifeq (in_docker,$(firstword $(MAKECMDGOALS)))
|
||||||
|
@ -117,6 +124,31 @@ build: build-agent build-server build-cli
|
||||||
|
|
||||||
release-frontend: build-frontend
|
release-frontend: build-frontend
|
||||||
|
|
||||||
|
check-xgo:
|
||||||
|
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
$(GO) install src.techknowlogick.com/xgo@latest; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
cross-compile-server:
|
||||||
|
$(foreach platform,$(subst ;, ,$(PLATFORMS)),\
|
||||||
|
TARGETOS=$(firstword $(subst |, ,$(platform))) \
|
||||||
|
TARGETARCH_XGO=$(subst arm64/v8,arm64,$(subst arm/v7,arm-7,$(word 2,$(subst |, ,$(platform))))) \
|
||||||
|
TARGETARCH_BUILDX=$(subst arm64/v8,arm64,$(subst arm/v7,arm,$(word 2,$(subst |, ,$(platform))))) \
|
||||||
|
make release-server-xgo || exit 1; \
|
||||||
|
)
|
||||||
|
tree dist
|
||||||
|
|
||||||
|
release-server-xgo: check-xgo
|
||||||
|
@echo "Building for:"
|
||||||
|
@echo "os:$(TARGETOS)"
|
||||||
|
@echo "arch orgi:$(TARGETARCH)"
|
||||||
|
@echo "arch (xgo):$(TARGETARCH_XGO)"
|
||||||
|
@echo "arch (buildx):$(TARGETARCH_BUILDX)"
|
||||||
|
|
||||||
|
CGO_CFLAGS="$(CGO_CFLAGS)" xgo -go $(XGO_VERSION) -dest ./dist/server/$(TARGETOS)-$(TARGETARCH_XGO) -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external $(LDFLAGS)' -targets '$(TARGETOS)/$(TARGETARCH_XGO)' -out woodpecker-server -pkg cmd/server .
|
||||||
|
mkdir -p ./dist/server/$(TARGETOS)/$(TARGETARCH_BUILDX)
|
||||||
|
mv /build/woodpecker-server-$(TARGETOS)-$(TARGETARCH_XGO) ./dist/server/$(TARGETOS)/$(TARGETARCH_BUILDX)/woodpecker-server
|
||||||
|
|
||||||
release-server:
|
release-server:
|
||||||
# compile
|
# compile
|
||||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '${LDFLAGS}' -o dist/server/linux_amd64/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '${LDFLAGS}' -o dist/server/linux_amd64/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
|
||||||
|
|
|
@ -12,7 +12,7 @@ RUN apk add -U --no-cache ca-certificates
|
||||||
ENV GODEBUG=netdns=go
|
ENV GODEBUG=netdns=go
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
COPY --from=build src/dist/woodpecker-agent /bin/
|
COPY --from=build /src/dist/woodpecker-agent /bin/
|
||||||
|
|
||||||
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
||||||
ENTRYPOINT ["/bin/woodpecker-agent"]
|
ENTRYPOINT ["/bin/woodpecker-agent"]
|
||||||
|
|
|
@ -14,7 +14,7 @@ EXPOSE 3000
|
||||||
# copy certs from golang:1.16 image
|
# copy certs from golang:1.16 image
|
||||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
# copy agent binary
|
# copy agent binary
|
||||||
COPY --from=build src/dist/woodpecker-agent /bin/
|
COPY --from=build /src/dist/woodpecker-agent /bin/
|
||||||
|
|
||||||
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
||||||
ENTRYPOINT ["/bin/woodpecker-agent"]
|
ENTRYPOINT ["/bin/woodpecker-agent"]
|
||||||
|
|
|
@ -11,7 +11,7 @@ FROM alpine:3.14
|
||||||
RUN apk add -U --no-cache ca-certificates
|
RUN apk add -U --no-cache ca-certificates
|
||||||
ENV GODEBUG=netdns=go
|
ENV GODEBUG=netdns=go
|
||||||
|
|
||||||
COPY --from=build src/dist/woodpecker-cli /bin/
|
COPY --from=build /src/dist/woodpecker-cli /bin/
|
||||||
|
|
||||||
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
|
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
|
||||||
ENTRYPOINT ["/bin/woodpecker-cli"]
|
ENTRYPOINT ["/bin/woodpecker-cli"]
|
||||||
|
|
|
@ -13,7 +13,7 @@ ENV GODEBUG=netdns=go
|
||||||
# copy certs from golang:1.16 image
|
# copy certs from golang:1.16 image
|
||||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
# copy cli binary
|
# copy cli binary
|
||||||
COPY --from=build src/dist/woodpecker-cli /bin/
|
COPY --from=build /src/dist/woodpecker-cli /bin/
|
||||||
|
|
||||||
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
|
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
|
||||||
ENTRYPOINT ["/bin/woodpecker-cli"]
|
ENTRYPOINT ["/bin/woodpecker-cli"]
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
# docker build --rm -f docker/Dockerfile.server.alpine -t woodpeckerci/woodpecker-server .
|
|
||||||
|
|
||||||
FROM alpine:3.14
|
FROM alpine:3.14
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
RUN apk add -U --no-cache ca-certificates
|
RUN apk add -U --no-cache ca-certificates
|
||||||
|
|
||||||
EXPOSE 8000 9000 80 443
|
|
||||||
|
|
||||||
ENV GODEBUG=netdns=go
|
ENV GODEBUG=netdns=go
|
||||||
ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite
|
ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite
|
||||||
ENV WOODPECKER_DATABASE_DRIVER=sqlite3
|
ENV WOODPECKER_DATABASE_DRIVER=sqlite3
|
||||||
ENV XDG_CACHE_HOME=/var/lib/woodpecker
|
ENV XDG_CACHE_HOME=/var/lib/woodpecker
|
||||||
|
EXPOSE 8000 9000 80 443
|
||||||
|
|
||||||
ADD dist/server/linux_amd64/woodpecker-server /bin/
|
COPY dist/server/${TARGETOS}/${TARGETARCH}/woodpecker-server /bin/
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/woodpecker-server"]
|
ENTRYPOINT ["/bin/woodpecker-server"]
|
|
@ -1,20 +1,16 @@
|
||||||
# docker build --rm -f docker/Dockerfile.server -t woodpeckerci/woodpecker-server .
|
FROM golang:1.16 AS certs
|
||||||
|
|
||||||
# use golang image to copy ssl certs later
|
|
||||||
FROM golang:1.16
|
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
# copy certs from golang:1.16 image
|
|
||||||
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
||||||
|
|
||||||
EXPOSE 8000 9000 80 443
|
|
||||||
|
|
||||||
ENV GODEBUG=netdns=go
|
ENV GODEBUG=netdns=go
|
||||||
ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite
|
ENV WOODPECKER_DATABASE_DATASOURCE=/var/lib/woodpecker/woodpecker.sqlite
|
||||||
ENV WOODPECKER_DATABASE_DRIVER=sqlite3
|
ENV WOODPECKER_DATABASE_DRIVER=sqlite3
|
||||||
ENV XDG_CACHE_HOME=/var/lib/woodpecker
|
ENV XDG_CACHE_HOME=/var/lib/woodpecker
|
||||||
|
EXPOSE 8000 9000 80 443
|
||||||
|
|
||||||
ADD dist/server/linux_amd64/woodpecker-server /bin/
|
# copy certs from golang:1.16 image
|
||||||
|
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
# copy server binary
|
||||||
|
COPY dist/server/${TARGETOS}/${TARGETARCH}/woodpecker-server /bin/
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/woodpecker-server"]
|
ENTRYPOINT ["/bin/woodpecker-server"]
|
Loading…
Reference in a new issue