Skip to content

Commit

Permalink
Merge pull request #6 from tosuke/push-ecr-public
Browse files Browse the repository at this point in the history
Adds a workflow to build and push docker images
  • Loading branch information
Arthur1 committed Feb 29, 2024
2 parents f7c8f69 + 3a050b3 commit f021783
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
53 changes: 52 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- "v[0-9]+.[0-9]+.[0-9]+"
jobs:
goreleaser:
runs-on: ubuntu-latest
Expand All @@ -23,3 +23,54 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Buildx
uses: docker/setup-buildx-action@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
role-session-name: "mackerel-sql-metric-collector:${{ github.run_id }}-${{ github.run_number }}"
aws-region: ap-northeast-1
- name: Login to Public ECR
uses: docker/login-action@v3
with:
registry: public.ecr.aws
env:
AWS_REGION: us-east-1

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
public.ecr.aws/mackerel/mackerel-sql-metric-collector
tags: |
type=semver,pattern={{raw}}
- name: Get short sha
id: short-sha
run: echo "GIT_SHORT_SHA=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
provenance: false
file: Dockerfile
platforms: |
linux/amd64
linux/arm64
build-args: |
GIT_REVISION=${{ steps.short-sha.outputs.GIT_SHORT_SHA }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM golang:1.21 AS build
FROM --platform=$BUILDPLATFORM golang:1.21 AS build
ARG GIT_REVISION
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app
COPY . /app
RUN make NAME=mackerel-sql-metric-collector
# To avoid downloading Go modules in the build of each platform, we share the module cache and lock during builds.
RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod/ \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} make GIT_REVISION=${GIT_REVISION} NAME=mackerel-sql-metric-collector

FROM gcr.io/distroless/static-debian11:nonroot
COPY --from=build --chown=nonroot:nonroot /app/bin/mackerel-sql-metric-collector /
Expand Down

0 comments on commit f021783

Please sign in to comment.