Skip to content

Commit

Permalink
Create "publish" GitHub workflow to publish to GHCR on new releases
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyuanliang committed Jun 18, 2023
1 parent 9040dbc commit 3767ea8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Create and publish image

on:
release:
types: [published]

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
run: make manifest-list
env:
REGISTRY: ghcr.io/${{ github.repository }}
REGISTRY_USERNAME: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ BASE_IMAGE ?= gcr.io/distroless/static
# Where to push the docker images.
REGISTRY ?= example.com

# Credentials to access the registry.
REGISTRY_USERNAME ?= oauth2accesstoken
REGISTRY_PASSWORD ?= $$(gcloud auth print-access-token)

# This version-strategy uses git tags to set the version string
VERSION ?= $(shell git describe --tags --always --dirty)
#
Expand Down Expand Up @@ -332,8 +336,8 @@ manifest-list: all-push
for bin in $(BINS); do \
platforms=$$(echo $(ALL_PLATFORMS) | sed 's/ /,/g'); \
bin/tools/manifest-tool \
--username=oauth2accesstoken \
--password=$$(gcloud auth print-access-token) \
--username="$(REGISTRY_USERNAME)" \
--password="$(REGISTRY_PASSWORD)" \
push from-args \
--platforms "$$platforms" \
--template $(REGISTRY)/$$bin:$(VERSION)__OS_ARCH \
Expand Down

0 comments on commit 3767ea8

Please sign in to comment.