Skip to content

Commit

Permalink
Merge pull request #79 from cybozu-go/multi-platform
Browse files Browse the repository at this point in the history
Support multi-platform
  • Loading branch information
masa213f authored Mar 7, 2023
2 parents 759960b + 2f22010 commit 0da8cad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- run: docker build -t moco-agent:dev .
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- run: docker buildx build --load -t moco-agent:dev .
test:
name: Small Tests
strategy:
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,24 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Login to ghcr.io
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- run: docker build -t ghcr.io/cybozu-go/moco-agent:${GITHUB_REF#refs/tags/v} .
- run: docker push ghcr.io/cybozu-go/moco-agent:${GITHUB_REF#refs/tags/v}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/amd64,linux/arm64/v8
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Tag
id: set-tag
run: echo "RELEASE_TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT # Remove "v" prefix.
- name: Build and push
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64/v8
push: true
tags: ghcr.io/cybozu-go/moco-agent:${{ steps.set-tag.outputs.RELEASE_TAG }}
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# stage1: build the binary
FROM quay.io/cybozu/golang:1.19-jammy as builder
FROM --platform=$BUILDPLATFORM quay.io/cybozu/golang:1.19-jammy as builder

ARG TARGETARCH

COPY ./ .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -a -o moco-agent ./cmd/moco-agent
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -a -o moco-init ./cmd/moco-init
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -a -o cp ./cmd/cp
RUN GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -ldflags="-w -s" -a -o moco-agent ./cmd/moco-agent
RUN GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -ldflags="-w -s" -a -o moco-init ./cmd/moco-init
RUN GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -ldflags="-w -s" -a -o cp ./cmd/cp

# stage2: build the final image
FROM scratch
FROM --platform=$TARGETPLATFORM scratch
LABEL org.opencontainers.image.source https://github.com/cybozu-go/moco-agent

COPY --from=builder /work/moco-agent /
Expand Down

0 comments on commit 0da8cad

Please sign in to comment.