All checks were successful
Build and Deploy / Build & Push Image (push) Successful in 19s
66 lines
2.0 KiB
YAML
66 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
|
|
|
|
export IMAGE="${{ env.REGISTRY }}/alex/cobblemon:${{ github.run_number }}"
|
|
|
|
kubectl get secret cobblemon-ui-secret --namespace=minecraft 2>/dev/null || \
|
|
kubectl create secret generic cobblemon-ui-secret \
|
|
--namespace=minecraft \
|
|
--from-literal=secret-key-base="$(openssl rand -base64 64)"
|
|
|
|
for file in k8s/*.yaml; do
|
|
cat "$file" | envsubst | kubectl apply -f -
|
|
done
|
|
|
|
kubectl rollout status deployment/cobblemon-ui \
|
|
--namespace=minecraft \
|
|
--timeout=5m
|
|
|
|
- name: Cleanup old images
|
|
run: |
|
|
# Delete all container image versions except the most recent one
|
|
nix-shell -p jq --run '
|
|
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
|
|
'
|