Skip to content

Commit

Permalink
chore(ci): publish the staging Docker image with goreleaser (#179)
Browse files Browse the repository at this point in the history
Publish the staging Docker image (ghcr.io/italia/developers-italia-api:main)
when pushing to main.
  • Loading branch information
bfabio authored Nov 11, 2022
1 parent a2b29cd commit bc1a195
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/workflows/publish-staging-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Push the staging Docker image (ghcr.italia/developers-italia-api:main)
# on updates to main.

on:
push:
branches: [ main ]

permissions:
# To push Docker images to GitHub
packages: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
uses: actions/setup-go@v3
with:
go-version: 1.18.x
-
uses: actions/checkout@v2
with:
# All history, required for goreleaser
fetch-depth: 0
-
# FIXME: goreleaser should already take care of the login
# (see https://github.com/goreleaser/goreleaser/blame/02a3486d4ba59505113a57b438ae567351ed3dab/scripts/entrypoint.sh#L17)
# but it doesn't work for some reason.
run: echo "$GITHUB_TOKEN" | docker login ghcr.io -u docker --password-stdin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

-
# Tag with a temporary valid semantic version. This is required by goreleaser.
run: git tag $(git describe --tags --abbrev=0)-main-$(git rev-parse --short HEAD)

-
uses: goreleaser/goreleaser-action@v2
with:
version: v1.9.2
args: release --config .goreleaser.staging.yaml
21 changes: 21 additions & 0 deletions .goreleaser.staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Goreleases configuration for staging builds, just builds and pushes
# the Docker image for the main branch.
#
# Make sure to check the documentation at https://goreleaser.com

# Don't create a GitHub release
release:
disable: true

builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w
goos:
- linux
dockers:
-
dockerfile: Dockerfile.goreleaser
image_templates:
- "ghcr.io/italia/developers-italia-api:main"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This is for local development only.
# See Dockerfile.goreleaser for the image published on release.
# See Dockerfile.goreleaser for the image published on release or staging.
#

FROM golang:1.18 as base
Expand Down

0 comments on commit bc1a195

Please sign in to comment.