Files
cobblemon-ui/.gitea/workflows/deploy.yml
Alex Mickelson c3be192620
Some checks failed
Build and Deploy / Build & Push Image (push) Failing after 2s
name
2026-03-16 13:21:02 -06:00

58 lines
1.8 KiB
YAML

name: Build and Deploy
on:
push:
branches: [main]
workflow_dispatch:
env:
REGISTRY: git.alexmickelson.guru
jobs:
build:
name: Build & Push Image
runs-on: self-hosted
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to Gitea Container Registry
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
- name: Build and push image
id: build
run: |
IMAGE="${{ env.REGISTRY }}/alex/cobblemon:${{ github.run_number }}"
docker build --push -t "${IMAGE}" .
- name: Deploy
run: |
IMAGE="${{ env.REGISTRY }}/alex/cobblemon:${{ github.run_number }}"
kubectl get secret cobblemon-ui-secret --namespace=cobblemon 2>/dev/null || \
kubectl create secret generic cobblemon-ui-secret \
--namespace=cobblemon \
--from-literal=secret-key-base="${{ secrets.SECRET_KEY_BASE }}"
for file in k8s/*.yaml; do
envsubst < "$file" | kubectl apply -f -
done
kubectl rollout status deployment/cobblemon-ui \
--namespace=cobblemon \
--timeout=5m
- name: Cleanup old images
run: |
# Delete all container image versions except the most recent one
VERSIONS=$(curl -s -H "Authorization: token ${{ secrets.REGISTRY_TOKEN }}" \
"${{ env.REGISTRY }}/api/v1/packages/alexmickelson?type=container&q=cobblemon&limit=50" \
| jq -r 'sort_by(.created) | reverse | .[1:] | .[].id')
for id in $VERSIONS; do
curl -s -X DELETE -H "Authorization: token ${{ secrets.REGISTRY_TOKEN }}" \
"${{ env.REGISTRY }}/api/v1/packages/alexmickelson/container/cobblemon/${id}"
done