Skip to content

Commit

Permalink
Upgrade GHA for publishing a new image
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jan 19, 2023
1 parent 92f411d commit 5c178d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 51 deletions.
41 changes: 8 additions & 33 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Set Username/Repo and ImagePrefix as ENV vars
run: |
echo "IMAGE_PREFIX=ghcr.io/${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Build x86_64 container into library
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
outputs: "type=docker,push=false"
build-args: |
VERSION=latest-dev
GIT_COMMIT=${{ github.sha }}
platforms: linux/amd64
tags: |
${{ env.IMAGE_PREFIX }}:${{ github.sha }}
build-multi-arch:
# run in parallel to build because multi-arch is slow
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Set Username/Repo and ImagePrefix as ENV vars
run: |
echo "IMAGE_PREFIX=ghcr.io/${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Get Repo Owner
id: get_repo_owner
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" > $GITHUB_ENV

- name: Build multi-arch containers for validation only
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
Expand All @@ -58,4 +32,5 @@ jobs:
GIT_COMMIT=${{ github.sha }}
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: |
${{ env.IMAGE_PREFIX }}:${{ github.sha }}
ghcr.io/${{ env.REPO_OWNER }}/ingress-operator:${{ github.sha }}
48 changes: 30 additions & 18 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,46 @@ jobs:
statuses: read
steps:
- uses: actions/checkout@master
- name: Install Go
uses: actions/setup-go@v3.1.0
with:
go-version: 1.19.x
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Get TAG
id: get_tag
run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
- name: Set Username/Repo and ImagePrefix as ENV vars
run: |
echo "IMAGE_PREFIX=ghcr.io/${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
uses: docker/setup-buildx-action@v2
- name: Login to Docker Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io

- name: Get TAG
id: get_tag
run: echo TAG=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV

- name: Get git commit
id: get_git_commit
run: echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Get version
id: get_version
run: echo "VERSION=$(git describe --tags --dirty)" >> $GITHUB_ENV
- name: Get Repo Owner
id: get_repo_owner
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" > $GITHUB_ENV

- name: Push containers
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
outputs: "type=registry,push=true"
build-args: |
VERSION=${{ steps.get_tag.outputs.TAG }}
GIT_COMMIT=${{ github.sha }}
platforms: linux/amd64,linux/arm/v7,linux/arm64
build-args: |
GIT_COMMIT=${{env.GIT_COMMIT}}
VERSION=${{env.VERSION}}
tags: |
${{ env.IMAGE_PREFIX }}:${{ github.sha }}
${{ env.IMAGE_PREFIX }}:${{ steps.get_tag.outputs.TAG }}
${{ env.IMAGE_PREFIX }}:latest
ghcr.io/${{ env.REPO_OWNER }}/ingress-operator:${{ github.sha }}
ghcr.io/${{ env.REPO_OWNER }}/ingress-operator:${{ env.TAG }}
ghcr.io/${{ env.REPO_OWNER }}/ingress-operator:latest

0 comments on commit 5c178d1

Please sign in to comment.