mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-22 16:36:30 +00:00
Add multiarch support agent (#622)
- Makefile - Delete _with-docker - Fix version creation - Add default values for TARGETOS & TARGETARCH - Add multiarch Dockerfile for agent - pipeline config - target more platforms for agent docker builds (windows & darwin) close #181, close #187
This commit is contained in:
parent
d0da1a104e
commit
9c7691094a
6 changed files with 77 additions and 51 deletions
|
@ -17,6 +17,8 @@ pipeline:
|
||||||
image: golang:1.16
|
image: golang:1.16
|
||||||
commands:
|
commands:
|
||||||
- make release-agent
|
- make release-agent
|
||||||
|
when:
|
||||||
|
event: tag
|
||||||
|
|
||||||
build-cli:
|
build-cli:
|
||||||
group: build
|
group: build
|
||||||
|
@ -59,13 +61,26 @@ pipeline:
|
||||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||||
event: push
|
event: push
|
||||||
|
|
||||||
|
publish-agent-dryrun:
|
||||||
|
group: bundle
|
||||||
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
|
settings:
|
||||||
|
dry_run: true
|
||||||
|
repo: woodpeckerci/woodpecker-agent
|
||||||
|
dockerfile: docker/Dockerfile.agent.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le,windows/amd64,darwin/amd64,darwin/arm64
|
||||||
|
tag: test
|
||||||
|
when:
|
||||||
|
event: pull_request
|
||||||
|
|
||||||
publish-agent:
|
publish-agent:
|
||||||
group: bundle
|
group: bundle
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [docker_username, docker_password]
|
secrets: [docker_username, docker_password]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-agent
|
repo: woodpeckerci/woodpecker-agent
|
||||||
dockerfile: docker/Dockerfile.agent
|
dockerfile: docker/Dockerfile.agent.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le,windows/amd64,darwin/amd64,darwin/arm64
|
||||||
# TODO: only release as next after 0.15.0 got released
|
# TODO: only release as next after 0.15.0 got released
|
||||||
tag: [next, latest]
|
tag: [next, latest]
|
||||||
when:
|
when:
|
||||||
|
@ -74,11 +89,12 @@ pipeline:
|
||||||
|
|
||||||
publish-agent-alpine:
|
publish-agent-alpine:
|
||||||
group: bundle
|
group: bundle
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [ docker_username, docker_password ]
|
secrets: [ docker_username, docker_password ]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-agent
|
repo: woodpeckerci/woodpecker-agent
|
||||||
dockerfile: docker/Dockerfile.agent.alpine
|
dockerfile: docker/Dockerfile.agent.alpine.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
# TODO: only release as next-alpine after 0.15.0 got released
|
# TODO: only release as next-alpine after 0.15.0 got released
|
||||||
tag: [next-alpine, latest-alpine]
|
tag: [next-alpine, latest-alpine]
|
||||||
when:
|
when:
|
||||||
|
@ -133,22 +149,24 @@ pipeline:
|
||||||
|
|
||||||
release-agent:
|
release-agent:
|
||||||
group: bundle
|
group: bundle
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [docker_username, docker_password]
|
secrets: [docker_username, docker_password]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-agent
|
repo: woodpeckerci/woodpecker-agent
|
||||||
dockerfile: docker/Dockerfile.agent
|
dockerfile: docker/Dockerfile.agent.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le,windows/amd64,darwin/amd64,darwin/arm64
|
||||||
tag: [latest, "${CI_COMMIT_TAG}"]
|
tag: [latest, "${CI_COMMIT_TAG}"]
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
|
||||||
release-agent-alpine:
|
release-agent-alpine:
|
||||||
group: bundle
|
group: bundle
|
||||||
image: plugins/docker
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
secrets: [ docker_username, docker_password ]
|
secrets: [ docker_username, docker_password ]
|
||||||
settings:
|
settings:
|
||||||
repo: woodpeckerci/woodpecker-agent
|
repo: woodpeckerci/woodpecker-agent
|
||||||
dockerfile: docker/Dockerfile.agent.alpine
|
dockerfile: docker/Dockerfile.agent.alpine.multiarch
|
||||||
|
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
|
||||||
tag: [latest-alpine, "${CI_COMMIT_TAG}-alpine"]
|
tag: [latest-alpine, "${CI_COMMIT_TAG}-alpine"]
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
|
27
Makefile
27
Makefile
|
@ -1,7 +1,9 @@
|
||||||
DOCKER_RUN_GO_VERSION=1.16
|
|
||||||
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
|
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
|
||||||
GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
GO_PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
||||||
|
|
||||||
|
TARGETOS ?= linux
|
||||||
|
TARGETARCH ?= amd64
|
||||||
|
|
||||||
VERSION ?= next
|
VERSION ?= next
|
||||||
ifneq ($(CI_COMMIT_TAG),)
|
ifneq ($(CI_COMMIT_TAG),)
|
||||||
VERSION := $(CI_COMMIT_TAG:v%=%)
|
VERSION := $(CI_COMMIT_TAG:v%=%)
|
||||||
|
@ -10,15 +12,12 @@ endif
|
||||||
# append commit-sha to next version
|
# append commit-sha to next version
|
||||||
BUILD_VERSION := $(VERSION)
|
BUILD_VERSION := $(VERSION)
|
||||||
ifeq ($(BUILD_VERSION),next)
|
ifeq ($(BUILD_VERSION),next)
|
||||||
|
CI_COMMIT_SHA ?= $(shell git rev-parse HEAD)
|
||||||
BUILD_VERSION := $(shell echo "next-$(shell echo ${CI_COMMIT_SHA} | head -c 8)")
|
BUILD_VERSION := $(shell echo "next-$(shell echo ${CI_COMMIT_SHA} | head -c 8)")
|
||||||
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}
|
||||||
|
|
||||||
DOCKER_RUN?=
|
|
||||||
_with-docker:
|
|
||||||
$(eval DOCKER_RUN=docker run --rm -v $(shell pwd):/go/src/ -v $(shell pwd)/build:/build -w /go/src golang:$(DOCKER_RUN_GO_VERSION))
|
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
vendor:
|
vendor:
|
||||||
|
@ -51,16 +50,16 @@ lint-frontend:
|
||||||
(cd web/; yarn lint --quiet)
|
(cd web/; yarn lint --quiet)
|
||||||
|
|
||||||
test-agent:
|
test-agent:
|
||||||
$(DOCKER_RUN) go test -race -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/agent github.com/woodpecker-ci/woodpecker/agent/...
|
go test -race -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/agent github.com/woodpecker-ci/woodpecker/agent/...
|
||||||
|
|
||||||
test-server:
|
test-server:
|
||||||
$(DOCKER_RUN) go test -race -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/server $(shell go list github.com/woodpecker-ci/woodpecker/server/... | grep -v '/store')
|
go test -race -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/server $(shell go list github.com/woodpecker-ci/woodpecker/server/... | grep -v '/store')
|
||||||
|
|
||||||
test-cli:
|
test-cli:
|
||||||
$(DOCKER_RUN) go test -race -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/cli github.com/woodpecker-ci/woodpecker/cli/...
|
go test -race -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/cmd/cli github.com/woodpecker-ci/woodpecker/cli/...
|
||||||
|
|
||||||
test-server-datastore:
|
test-server-datastore:
|
||||||
$(DOCKER_RUN) go test -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/server/store/...
|
go test -cover -coverprofile coverage.out -timeout 30s github.com/woodpecker-ci/woodpecker/server/store/...
|
||||||
|
|
||||||
test-frontend: frontend-dependencies
|
test-frontend: frontend-dependencies
|
||||||
(cd web/; yarn run lint)
|
(cd web/; yarn run lint)
|
||||||
|
@ -69,7 +68,7 @@ test-frontend: frontend-dependencies
|
||||||
(cd web/; yarn run test)
|
(cd web/; yarn run test)
|
||||||
|
|
||||||
test-lib:
|
test-lib:
|
||||||
$(DOCKER_RUN) go test -race -cover -coverprofile coverage.out -timeout 30s $(shell go list ./... | grep -v '/cmd\|/agent\|/cli\|/server')
|
go test -race -cover -coverprofile coverage.out -timeout 30s $(shell go list ./... | grep -v '/cmd\|/agent\|/cli\|/server')
|
||||||
|
|
||||||
test: test-agent test-server test-server-datastore test-cli test-lib test-frontend
|
test: test-agent test-server test-server-datastore test-cli test-lib test-frontend
|
||||||
|
|
||||||
|
@ -77,13 +76,13 @@ build-frontend:
|
||||||
(cd web/; yarn install --frozen-lockfile; yarn build)
|
(cd web/; yarn install --frozen-lockfile; yarn build)
|
||||||
|
|
||||||
build-server: build-frontend
|
build-server: build-frontend
|
||||||
$(DOCKER_RUN) go build -o dist/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
|
CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o dist/woodpecker-server github.com/woodpecker-ci/woodpecker/cmd/server
|
||||||
|
|
||||||
build-agent:
|
build-agent:
|
||||||
$(DOCKER_RUN) go build -o dist/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
|
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o dist/woodpecker-agent github.com/woodpecker-ci/woodpecker/cmd/agent
|
||||||
|
|
||||||
build-cli:
|
build-cli:
|
||||||
$(DOCKER_RUN) go build -o dist/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
|
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -o dist/woodpecker-cli github.com/woodpecker-ci/woodpecker/cmd/cli
|
||||||
|
|
||||||
build: build-agent build-server build-cli
|
build: build-agent build-server build-cli
|
||||||
|
|
||||||
|
@ -152,4 +151,4 @@ bundle: bundle-agent bundle-server bundle-cli
|
||||||
|
|
||||||
.PHONY: version
|
.PHONY: version
|
||||||
version:
|
version:
|
||||||
@echo ${VERSION}
|
@echo ${BUILD_VERSION}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
# docker build --rm -f docker/Dockerfile.agent -t woodpeckerci/woodpecker-agent .
|
|
||||||
|
|
||||||
# use golang image to copy ssl certs later
|
|
||||||
FROM golang:1.16
|
|
||||||
|
|
||||||
FROM scratch
|
|
||||||
|
|
||||||
# copy certs from golang:1.16 image
|
|
||||||
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
||||||
|
|
||||||
ENV GODEBUG=netdns=go
|
|
||||||
ADD dist/agent/linux_amd64/woodpecker-agent /bin/
|
|
||||||
|
|
||||||
EXPOSE 3000
|
|
||||||
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/woodpecker-agent"]
|
|
|
@ -1,12 +0,0 @@
|
||||||
# docker build --rm -f docker/Dockerfile.agent.alpine -t woodpeckerci/woodpecker-agent .
|
|
||||||
|
|
||||||
FROM alpine:3.14
|
|
||||||
RUN apk add -U --no-cache ca-certificates
|
|
||||||
|
|
||||||
ENV GODEBUG=netdns=go
|
|
||||||
ADD dist/agent/linux_amd64/woodpecker-agent /bin/
|
|
||||||
|
|
||||||
EXPOSE 3000
|
|
||||||
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/woodpecker-agent"]
|
|
18
docker/Dockerfile.agent.alpine.multiarch
Normal file
18
docker/Dockerfile.agent.alpine.multiarch
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
FROM --platform=$BUILDPLATFORM golang:1.16 AS build
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
COPY . .
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/go/pkg \
|
||||||
|
make build-agent
|
||||||
|
|
||||||
|
FROM alpine:3.14
|
||||||
|
RUN apk add -U --no-cache ca-certificates
|
||||||
|
ENV GODEBUG=netdns=go
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
COPY --from=build src/dist/woodpecker-agent /bin/
|
||||||
|
|
||||||
|
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
||||||
|
ENTRYPOINT ["/bin/woodpecker-agent"]
|
20
docker/Dockerfile.agent.multiarch
Normal file
20
docker/Dockerfile.agent.multiarch
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
FROM --platform=$BUILDPLATFORM golang:1.16 AS build
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
COPY . .
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/go/pkg \
|
||||||
|
make build-agent
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
ENV GODEBUG=netdns=go
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# copy certs from golang:1.16 image
|
||||||
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
# copy agent binary
|
||||||
|
COPY --from=build src/dist/woodpecker-agent /bin/
|
||||||
|
|
||||||
|
HEALTHCHECK CMD ["/bin/woodpecker-agent", "ping"]
|
||||||
|
ENTRYPOINT ["/bin/woodpecker-agent"]
|
Loading…
Reference in a new issue