Skip to content

Build & Deploy

Build & Deploy #18

Workflow file for this run

name: Build & Deploy
on:
workflow_dispatch:
push:
tags:
- "v*.*.*"
env:
REGISTRY: ghcr.io
jobs:
build-and-update:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Set image name
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY_OWNER,,}/wynnsource-server" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update image tag in deploy/
run: |
cd deploy
kustomize edit set image \
ghcr.io/${{ env.IMAGE_NAME }}=ghcr.io/${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Commit updated kustomization
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add deploy/kustomization.yaml
git diff --cached --quiet || git commit -m "chore: update image to ${{ github.sha }}" && git push
- name: Delete old images
uses: actions/delete-package-versions@v5
with:
package-type: container
package-name: wynnsource-server
min-versions-to-keep: 3
delete-only-untagged-versions: true