64 lines
2 KiB
YAML
64 lines
2 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: Update deployment manifest
|
|
run: |
|
|
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
|
|
TAG="${{ steps.tag.outputs.tag }}"
|
|
sed -i "s|image: ${IMAGE}:.*|image: ${IMAGE}:${TAG}|g" k8s/deployment.yaml
|
|
|
|
- name: Commit and push updated manifest
|
|
run: |
|
|
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
|
|
TAG="${{ steps.tag.outputs.tag }}"
|
|
git config user.name "FluxCD"
|
|
git config user.email "fluxcd@w5isp.com"
|
|
git remote set-url origin https://x-token:${{ github.token }}@git.mcintire.me/graham/aprs.me.git
|
|
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 ${IMAGE}:${TAG} [skip ci]"
|
|
git push origin main
|