go.mod replace #54
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a GitHub action that will have two jobs: build and publish | |
# The build job will create a Golang Docker image with a production target for multiple architectures | |
# The publish job will push the image to GitHub packages with the commit sha and build number as labels | |
# The image will also have some metadata labels about the build | |
# act --secret-file act.env --container-architecture linux/amd64 --workflows .github/workflows/build.yaml | |
name: build | |
on: | |
push: | |
jobs: | |
# This job will build the image using ubuntu | |
binary: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code from the repository | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
# Build a linux application | |
- name: Build Go application | |
# Build optimized - from Dockerfile | |
run: | | |
CGO_ENABLED=1 GOOS=linux go build \ | |
-v -a -installsuffix cgo \ | |
-o . \ | |
-ldflags="-s -w -X cmd/microservice/main.Version=${{ github.sha }}" \ | |
./... | |
- name: Upload Go binary | |
uses: actions/upload-artifact@v3 | |
with: | |
name: microservice-${{ github.sha }} | |
path: ./microservice | |
# This job will build the image using Docker Buildx | |
image: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code from the repository | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login to GitHub Container Registry | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Build and push the image to a SHA tag | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ghcr.io/${{ github.repository }}:${{ github.sha }} | |
target: production | |
platforms: linux/amd64,linux/arm64 | |
labels: | | |
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.version=$(cat VERSION) | |
org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
org.opencontainers.image.title=${{ github.event.repository.name }} | |
org.opencontainers.image.description="Service providers implemented in Go for a protected data lifecycle" | |
com.github.build.number=${{ github.run_number }} | |
# Use cache for faster builds, no scope for faster builds | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |