Skip to content

Commit

Permalink
feat: add matrix
Browse files Browse the repository at this point in the history
Signed-off-by: Lam Tran <[email protected]>
  • Loading branch information
tranngoclam authored and Lam Tran committed Nov 14, 2023
1 parent e015ea9 commit 6a4a6e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
cd:
name: Build Container Image
runs-on: ubuntu-latest
strategy:
matrix:
service: [ bar, foo ]
steps:
- uses: actions/checkout@v4

Expand All @@ -20,7 +23,7 @@ jobs:
id: meta
with:
images: |
ghcr.io/tranngoclam/monorepo-foo
ghcr.io/tranngoclam/monorepo-${{ matrix.service }}
tags: |
type=sha,enable=true,format=long
type=raw,enable=true,value=latest
Expand All @@ -29,7 +32,7 @@ jobs:
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: foo/Dockerfile
file: ${{ matrix.service }}/Dockerfile
platforms: linux/amd64,linux/arm64
push: false
tags: ${{ steps.meta.outputs.tags }}
Expand Down
6 changes: 3 additions & 3 deletions bar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 AS build
FROM --platform=$BUILDPLATFORM golang:1.21 AS build

WORKDIR /src

Expand All @@ -9,14 +9,14 @@ RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,source=./lib/go.sum,target=./lib/go.sum \
--mount=type=bind,source=./api/go.mod,target=./api/go.mod \
--mount=type=bind,source=./api/go.sum,target=./api/go.sum \
go work init ./bar ./lib ./api && go work sync
go work init ./bar ./lib ./api && go mod download

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=./bar,target=./bar \
--mount=type=bind,source=./lib,target=./lib \
--mount=type=bind,source=./api,target=./api \
CGO_ENABLED=0 go build -x -o /bin/bar bar
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /bin/bar bar

FROM gcr.io/distroless/static-debian11

Expand Down
6 changes: 3 additions & 3 deletions foo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 AS build
FROM --platform=$BUILDPLATFORM golang:1.21 AS build

WORKDIR /src

Expand All @@ -7,13 +7,13 @@ RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,source=./foo/go.sum,target=./foo/go.sum \
--mount=type=bind,source=./lib/go.mod,target=./lib/go.mod \
--mount=type=bind,source=./lib/go.sum,target=./lib/go.sum \
go work init ./foo ./lib && go work sync
go work init ./foo ./lib && go mod download

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=./foo,target=./foo \
--mount=type=bind,source=./lib,target=./lib \
CGO_ENABLED=0 go build -x -o /bin/foo foo
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /bin/foo foo

FROM gcr.io/distroless/static-debian11

Expand Down

0 comments on commit 6a4a6e2

Please sign in to comment.