Switch deployment to floating :main tag with imagePullPolicy: Always and have CI trigger a rollout restart directly via kubectl. Removes the [skip ci] image-bump commits from main's history. Requires a KUBECONFIG_DATA secret (base64-encoded kubeconfig with permission to restart deployment/aprs in the aprs namespace) in Forgejo Actions.
61 lines
1.8 KiB
YAML
61 lines
1.8 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
REGISTRY: git.mcintire.me
|
|
IMAGE_NAME: graham/aprs.me
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build-and-push:
|
|
name: Build and Push Docker Image
|
|
runs-on: ubuntu-22.04
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: https://github.com/actions/checkout@v4
|
|
|
|
- name: Install Docker CLI
|
|
run: |
|
|
apt-get update && apt-get install -y docker.io
|
|
|
|
- name: Generate image tag
|
|
id: tag
|
|
run: |
|
|
TIMESTAMP=$(date +%s)
|
|
SHORT_SHA=$(git rev-parse --short=7 HEAD | cut -c1-7)
|
|
TAG="main-${TIMESTAMP}-${SHORT_SHA}"
|
|
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Log in to container registry
|
|
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u ${{ secrets.REGISTRY_USER }} --password-stdin
|
|
|
|
- name: Build and push Docker image
|
|
run: |
|
|
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
|
|
TAG="${{ steps.tag.outputs.tag }}"
|
|
docker build -t "${IMAGE}:${TAG}" -t "${IMAGE}:main" .
|
|
docker push "${IMAGE}:${TAG}"
|
|
docker push "${IMAGE}:main"
|
|
|
|
- name: Install kubectl
|
|
run: |
|
|
curl -sLO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
|
install -m 0755 kubectl /usr/local/bin/kubectl
|
|
|
|
- name: Trigger rollout (no git commit)
|
|
env:
|
|
KUBECONFIG_DATA: ${{ secrets.KUBECONFIG_DATA }}
|
|
run: |
|
|
mkdir -p "$HOME/.kube"
|
|
printf '%s' "$KUBECONFIG_DATA" | base64 -d > "$HOME/.kube/config"
|
|
chmod 600 "$HOME/.kube/config"
|
|
kubectl -n aprs rollout restart deployment/aprs
|
|
kubectl -n aprs rollout status deployment/aprs --timeout=5m
|