84 lines
2.3 KiB
YAML
84 lines
2.3 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
# Cancel any in-progress run when a new one is triggered
|
|
concurrency:
|
|
group: deploy-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
REGISTRY: git.mcintire.me
|
|
IMAGE: git.mcintire.me/graham/aprs.me
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
outputs:
|
|
image_tag: ${{ steps.tag.outputs.image_tag }}
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- name: Compute image tag
|
|
id: tag
|
|
run: |
|
|
TIMESTAMP=$(date +%s)
|
|
SHA=${GITHUB_SHA:0:7}
|
|
echo "image_tag=main-${TIMESTAMP}-${SHA}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
${{ env.IMAGE }}:${{ steps.tag.outputs.image_tag }}
|
|
${{ env.IMAGE }}:main
|
|
cache-from: type=registry,ref=${{ env.IMAGE }}:main
|
|
cache-to: type=inline
|
|
|
|
deploy:
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Update image in deployment manifest
|
|
run: |
|
|
NEW_IMAGE="${{ env.IMAGE }}:${{ needs.build-and-push.outputs.image_tag }}"
|
|
sed -i "s|image: git.mcintire.me/graham/aprs.me:.*|image: ${NEW_IMAGE}|g" k8s/deployment.yaml
|
|
|
|
- name: Commit and push updated manifest
|
|
run: |
|
|
NEW_IMAGE="${{ env.IMAGE }}:${{ needs.build-and-push.outputs.image_tag }}"
|
|
git config user.name "github-actions"
|
|
git config user.email "github-actions@github.com"
|
|
git add k8s/deployment.yaml
|
|
git diff --cached --quiet && echo "No changes to commit" && exit 0
|
|
git commit -m "chore: update aprs.me image to ${NEW_IMAGE} [skip ci]"
|
|
git push
|