Skip to content

Commit

Permalink
chore(ci): image release to github container registry
Browse files Browse the repository at this point in the history
  • Loading branch information
heronimus committed Aug 15, 2023
1 parent 57d0ae1 commit 124abe5
Showing 1 changed file with 59 additions and 36 deletions.
95 changes: 59 additions & 36 deletions .github/workflows/backend-mage-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ on:
- 'v*.*.*'

env:
CARDINAL_REGISTRY_PATH: starter-game-template/cardinal
NAKAMA_REGISTRY_PATH: starter-game-templa/nakama
IMAGE_NAME_NAKAMA: starter-game-template-nakama
IMAGE_NAME_CARDINAL: starter-game-template-cardinal
IMAGE_NAME_TESTSUITE: starter-game-template-testsuite

jobs:
mage-build:
mage-build-test:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -39,51 +40,73 @@ jobs:
with:
version: latest
args: check
- name: Mage - build
- name: Mage - build & test
uses: magefile/mage-action@v2
with:
version: latest
args: build
mage-test:
args: test
- name: Docker show build images
run: |
docker image ls -a | grep starter-game-template
- name: Docker save local build images
run: |
docker save IMAGE_NAME_NAKAMA:latest > /tmp/IMAGE_NAME_NAKAMA-latest.tar
docker save IMAGE_NAME_CARDINAL:latest > /tmp/IMAGE_NAME_CARDINAL-latest.tar
docker save IMAGE_NAME_TESTSUITE:latest > /tmp/IMAGE_NAME_TESTSUITE-latest.tar
- name: Upload local build images to temporary artifact
uses: actions/upload-artifact@v3
with:
name: buildimage
path: /tmp/starter-game-template-*.tar
images-release:
runs-on: ubuntu-latest
needs: mage-build
needs: mage-build-test
# if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main'
defaults:
run:
shell: bash
strategy:
matrix:
go-version: [1.20.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Mage - check
uses: magefile/mage-action@v2
with:
version: latest
args: check
- name: Mage - test
uses: magefile/mage-action@v2
- name: Download local build images artifact
uses: actions/download-artifact@v3
with:
version: latest
args: test
images-release:
name: buildimage
path: /tmp/
- name: Load image and show build images
run: |
docker load --input /tmp/IMAGE_NAME_NAKAMA-latest.tar
docker load --input /tmp/IMAGE_NAME_CARDINAL-latest.tar
docker load --input /tmp/IMAGE_NAME_TESTSUITE-latest.tar
docker image ls -a | grep starter-game-template
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Push image
run: |
IMAGE_ID_NAKAMA=ghcr.io/${{ github.repository_owner }}/IMAGE_NAME_NAKAMA
IMAGE_ID_NAKAMA=$(echo $IMAGE_ID_NAKAMA | tr '[A-Z]' '[a-z]')
IMAGE_ID_CARDINAL=ghcr.io/${{ github.repository_owner }}/IMAGE_NAME_CARDINAL
IMAGE_ID_CARDINAL=$(echo $IMAGE_ID_CARDINAL | tr '[A-Z]' '[a-z]')
IMAGE_ID_TESTSUITE=ghcr.io/${{ github.repository_owner }}/IMAGE_NAME_TESTSUITE
IMAGE_ID_TESTSUITE=$(echo $IMAGE_ID_TESTSUITE | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=latest
docker tag $IMAGE_NAME_NAKAMA:latest $IMAGE_ID_NAKAMA:$VERSION
docker tag $IMAGE_NAME_CARDINAL:latest $IMAGE_ID_CARDINAL:$VERSION
docker tag $IMAGE_NAME_TESTSUITE:latest $IMAGE_ID_TESTSUITE:$VERSION
docker push $IMAGE_ID:$VERSION
artifact-cleanup:
runs-on: ubuntu-latest
needs: mage-build
defaults:
run:
shell: bash
strategy:
matrix:
go-version: [1.20.x]
needs: [
mage-build-test,
images-release
]
if: always()
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- run: docker images
- name: Remove local build image artifact
uses: geekyeggo/delete-artifact@v2
with:
name: buildimage

0 comments on commit 124abe5

Please sign in to comment.