Skip to content

Commit

Permalink
ci: separate build/push image to fix permission issue
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Oct 10, 2023
1 parent 860d928 commit 0ccecde
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 60 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Build App
on:
workflow_call

permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- run: mvn --batch-mode --update-snapshots verify
56 changes: 0 additions & 56 deletions .github/workflows/build-image.yml

This file was deleted.

14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@ on:
permissions:
contents: read
jobs:
build-app:
uses: ./.github/workflows/build-app.yaml
build-image:
uses: ./.github/workflows/build-image.yml
runs-on: ubuntu-latest
needs:
- build-app
steps:
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
42 changes: 39 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,48 @@ on:

permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-app:
uses: ./.github/workflows/build-app.yaml
build-push-image:
if: ${{ github.repository == 'statnett/k3a-lag-exporter' }}
needs:
- build-app
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
uses: ./.github/workflows/build-image.yml
with:
push: true
steps:
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# output 0.1.2
type=semver,pattern={{version}}
# output 0.1
type=semver,pattern={{major}}.{{minor}}
# disabled if major zero
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

0 comments on commit 0ccecde

Please sign in to comment.