Skip to content

Build and push image #35

Build and push image

Build and push image #35

Workflow file for this run

name: Build and push image
on:
push:
tags:
- 'v*'
env:
IMAGE: ghcr.io/${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: node_modules
key: node-${{ hashFiles('yarn.lock') }}
- uses: actions/cache@v4
with:
path: ~/.m2
key: maven-${{ hashFiles('shadow-cljs.edn') }}
- run: yarn
- run: yarn build
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
update_image:
runs-on: ubuntu-latest
needs:
- build
environment:
name: production
url: https://advent.dekiru.tech
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
if [ "${{ github.sha }}" == $(git rev-parse origin/main) ]; then
git checkout --track origin/main
else
echo "Tag is out of date"
exit 1
fi
- run: |
version=$(echo ${{ github.ref_name }} | sed 's/v//')
path='manifests/deployment.yaml'
sed -i -e "s%image: ${{ env.IMAGE }}:.*$%image: ${{ env.IMAGE }}:$version%" $path
git diff "$path"
- run: |
git config user.email "[email protected]"
git config user.name "Github Action"
git add "manifests/deployment.yaml"
git commit -m "Update target image tag"
git push