Skip to content

Commit

Permalink
Action for docker build on release (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornandre authored Nov 15, 2023
1 parent bd8c46c commit c1351f6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Build

on:
release:
types: [ published ]
push:
branches:
- master
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Release docker image

on:
release:
types: [ published ]

env:
REGISTRY: europe-north1-docker.pkg.dev/artifact-registry-5n/dapla-pseudo-docker/ssb/dapla
IMAGE: dapla-dlp-pseudo-service

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v3

- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/[email protected]
with:
workload_identity_provider: "projects/848539402404/locations/global/workloadIdentityPools/gh-actions/providers/gh-actions"
service_account: "gh-actions-dapla-pseudo@artifact-registry-5n.iam.gserviceaccount.com"
token_format: access_token

- name: Login to Artifact Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: "oauth2accesstoken"
password: "${{ steps.auth.outputs.access_token }}"

- name: Docker meta
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE }}
# Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr,suffix=-${{ github.event.pull_request.head.sha }}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value={{branch}}-{{sha}},enable={{is_default_branch}}
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
- name: Download Java asset
run: |
mkdir -p target
# Download just the jar file (no javadoc or sources)
gh release download -p "*{{ github.event.release.tag_name }}.jar" -D target
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
file: Dockerfile
push: true
context: .
tags: |
${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

0 comments on commit c1351f6

Please sign in to comment.