Multiarch build cli docker images (#634)

This commit is contained in:
6543 2021-12-21 16:51:23 +01:00 committed by GitHub
parent bed69f9f72
commit c2b0c1d73e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 35 deletions

View file

@ -25,6 +25,8 @@ pipeline:
image: golang:1.16
commands:
- make release-cli
when:
event: tag
build-deb-rpm:
group: bundle
@ -100,13 +102,26 @@ pipeline:
branch: ${CI_REPO_DEFAULT_BRANCH}
event: push
publish-cli-dryrun:
group: docker
image: woodpeckerci/plugin-docker-buildx
settings:
dry_run: true
repo: woodpeckerci/woodpecker-cli
dockerfile: docker/Dockerfile.cli.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-cli:
group: docker
image: plugins/docker
image: woodpeckerci/plugin-docker-buildx
secrets: [docker_username, docker_password]
settings:
repo: woodpeckerci/woodpecker-cli
dockerfile: docker/Dockerfile.cli
dockerfile: docker/Dockerfile.cli.multiarch
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le,windows/amd64,darwin/amd64,darwin/arm64
tag: next
when:
branch: ${CI_REPO_DEFAULT_BRANCH}
@ -114,11 +129,12 @@ pipeline:
publish-cli-alpine:
group: docker
image: plugins/docker
image: woodpeckerci/plugin-docker-buildx
secrets: [ docker_username, docker_password ]
settings:
repo: woodpeckerci/woodpecker-cli
dockerfile: docker/Dockerfile.cli.alpine
dockerfile: docker/Dockerfile.cli.alpine.multiarch
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
tag: next-alpine
when:
branch: ${CI_REPO_DEFAULT_BRANCH}
@ -172,22 +188,24 @@ pipeline:
release-cli:
group: docker
image: plugins/docker
image: woodpeckerci/plugin-docker-buildx
secrets: [docker_username, docker_password]
settings:
repo: woodpeckerci/woodpecker-cli
dockerfile: docker/Dockerfile.cli
dockerfile: docker/Dockerfile.cli.multiarch
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le,windows/amd64,darwin/amd64,darwin/arm64
tag: [latest, "${CI_COMMIT_TAG}"]
when:
event: tag
release-cli-alpine:
group: docker
image: plugins/docker
image: woodpeckerci/plugin-docker-buildx
secrets: [ docker_username, docker_password ]
settings:
repo: woodpeckerci/woodpecker-cli
dockerfile: docker/Dockerfile.cli.alpine
dockerfile: docker/Dockerfile.cli.alpine.multiarch
platforms: linux/arm/v7,linux/arm64/v8,linux/amd64,linux/ppc64le
tag: [latest-alpine, "${CI_COMMIT_TAG}-alpine"]
when:
event: tag

View file

@ -1,16 +0,0 @@
# docker build --rm -f docker/Dockerfile.cli -t woodpeckerci/woodpecker-cli .
# 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/cli/linux_amd64/woodpecker-cli /bin/
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
ENTRYPOINT ["/bin/woodpecker-cli"]

View file

@ -1,11 +0,0 @@
# docker build --rm -f docker/Dockerfile.cli.alpine -t woodpeckerci/woodpecker-cli .
FROM alpine:3.14
RUN apk add -U --no-cache ca-certificates
ENV GODEBUG=netdns=go
ADD dist/cli/linux_amd64/woodpecker-cli /bin/
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
ENTRYPOINT ["/bin/woodpecker-cli"]

View file

@ -0,0 +1,17 @@
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-cli
FROM alpine:3.14
RUN apk add -U --no-cache ca-certificates
ENV GODEBUG=netdns=go
COPY --from=build src/dist/woodpecker-cli /bin/
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
ENTRYPOINT ["/bin/woodpecker-cli"]

View file

@ -0,0 +1,19 @@
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-cli
FROM scratch
ENV GODEBUG=netdns=go
# copy certs from golang:1.16 image
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# copy cli binary
COPY --from=build src/dist/woodpecker-cli /bin/
HEALTHCHECK CMD ["/bin/woodpecker-cli", "ping"]
ENTRYPOINT ["/bin/woodpecker-cli"]