Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add arm64 support #43

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,26 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker metadata-action
id: meta
uses: docker/metadata-action@v5
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
with:
images: robsonpeixoto/echo-server
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ steps.qemu.outputs.platforms }}
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker metadata-action
id: meta
uses: docker/metadata-action@v5
with:
images: robsonpeixoto/echo-server
- name: Build and push
uses: docker/build-push-action@v6
with:
Expand All @@ -59,3 +66,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ steps.qemu.outputs.platforms }}
26 changes: 17 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
FROM golang:1.22.5-alpine3.19 AS builder
WORKDIR /usr/src/app
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /usr/local/bin/app ./...
ARG GO_VERSION=1.22.5
ARG ALPINE_VERSION=3.20

FROM alpine:3.20
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /src
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
go mod download -x

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,target=. \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /usr/local/bin/app .

FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION}
COPY --from=builder /usr/local/bin/app /usr/local/bin/app
CMD ["app"]
CMD ["/usr/local/bin/app"]