Skip to content

Commit

Permalink
chore: add continuous deployment workflow (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Lam Tran <[email protected]>
  • Loading branch information
tranngoclam authored Nov 14, 2023
1 parent b3fc778 commit 5a7a096
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Continuous Deployment

on:
push:
branches:
- main

jobs:
cd:
name: Build Container Image
runs-on: ubuntu-latest
strategy:
matrix:
service: [ bar, foo ]
steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

- name: Docker meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.5.0
id: meta
with:
images: |
ghcr.io/tranngoclam/monorepo-${{ matrix.service }}
tags: |
type=sha,enable=true,format=long,priority=200
type=raw,enable=true,value=latest,priority=100
- name: Build/Tag/Push Docker Image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: ${{ matrix.service }}/Dockerfile
platforms: linux/amd64,linux/arm64
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Go Workspace with Bazel
# Monorepo

[![Continuous Integration](https://github.com/tranngoclam/go-workspace-bazel/actions/workflows/ci.yaml/badge.svg)](https://github.com/tranngoclam/go-workspace-bazel/actions/workflows/ci.yaml)

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.21 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.21 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 5a7a096

Please sign in to comment.