Files
cobblemon-ui/.gitea/workflows/deploy.yml
Alex Mickelson 0b4692cdf0
Some checks failed
Build and Deploy / Build & Push Image (push) Failing after 6s
kubeconfig
2026-03-16 16:43:51 -06:00

64 lines
2.0 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
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push image
id: build
run: |
IMAGE="${{ env.REGISTRY }}/alex/cobblemon:${{ github.run_number }}"
docker build --push -t "${IMAGE}" .
- name: Deploy
run: |
export KUBECONFIG=/home/gitea-runner/.kube/config
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