Skip to content

Commit

Permalink
ci: add release_build
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Sep 10, 2023
1 parent a97ee16 commit a9dd12a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: release_build

on:
push:
tags:
- "v*.*.*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
julesmike/chatter
# generate Docker tags based on the following events/attributes
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

# Add git, curl and upx support
RUN apk add --no-cache git curl upx ca-certificates

WORKDIR /src

# Pull modules
COPY go.* ./
RUN go mod download

# Copy code into image
COPY . ./

# Build application for deployment
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags '-s -w' -o /tmp/chatter .

# Compress binary
RUN upx --best --lzma /tmp/chatter

# Create minimal image
FROM --platform=$TARGETPLATFORM gcr.io/distroless/base

# Add the binary
COPY --from=builder /tmp/chatter /chatter

EXPOSE 80/tcp

ENTRYPOINT ["/chatter"]

0 comments on commit a9dd12a

Please sign in to comment.