Skip to content

Commit

Permalink
let dockerfile support multi platform builds, change publish action t…
Browse files Browse the repository at this point in the history
…o pulish muti-platform builds
  • Loading branch information
macyabbey authored and daveshanley committed Nov 1, 2024
1 parent 4f7bc5d commit 0a59369
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ jobs:
images: |
pb33f/wiretap
ghcr.io/${{ github.repository }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker images
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: pb33f/wiretap:latest, pb33f/wiretap:${{ github.event.client_payload.new-tag }}
32 changes: 26 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM node:20-bookworm-slim as builder
FROM node:20-bookworm-slim AS uibuilder

ARG TARGETOS
ARG TARGETARCH

RUN echo "I am building ui for OS:$TARGETOS, ARCH:$TARGETARCH" > /log

# set up ui build
RUN mkdir -p /wt_build
Expand All @@ -11,18 +16,33 @@ WORKDIR /wt_build/ui
RUN yarn install
RUN yarn build

FROM golang:1.23-bookworm
FROM golang:1.23-bookworm AS gobuilder

ARG TARGETOS
ARG TARGETARCH

WORKDIR /work

# copy ui build from previous stage
COPY --from=builder /wt_build/ui ./ui
COPY --from=uibuilder /wt_build/ui/dist ./ui/dist

COPY . ./

RUN go mod download && go mod verify
RUN go build -ldflags="-w -s" -v -o /wiretap wiretap.go
RUN echo "I am building go for GOOS:$TARGETOS, GOARCH:$TARGETARCH" > /log

RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go mod download && go mod verify
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -v -o /wiretap wiretap.go

FROM golang:1.23-alpine AS runner

ARG TARGETPLATFORM
ARG BUILDPLATFORM

RUN echo "I am running on $TARGETPLATFORM, was built on $BUILDPLATFORM" > /log

# copy only the built binary
COPY --from=gobuilder /wiretap /wiretap

ENV PATH=$PATH:/
ENV PATH=$PATH:/work/bin

ENTRYPOINT ["wiretap"]

0 comments on commit 0a59369

Please # to comment.