Initial commit
This commit is contained in:
commit
1b0358c8c0
20 files changed
+835
No files matched your search
@@ -0,0 +1,94 @@
|
||||
name: Build & Publish to GHCR
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
GHCR_ORG: gansejunge
|
||||
IMAGE_NAME: app-notifications-GENERIC
|
||||
IMAGE_PATH: ghcr.io/gansejunge/app-notifications-GENERIC
|
||||
OPS_ORG: notifier
|
||||
OPS_REPO: ops-deployment
|
||||
OPS_BRANCH_BASE: main
|
||||
OPS_PATH: GENERIC/deployment.yaml
|
||||
|
||||
jobs:
|
||||
select-runner:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
runner: ${{ steps.pick.outputs.runner }}
|
||||
steps:
|
||||
- name: Check if local runner is online
|
||||
id: pick
|
||||
env:
|
||||
API_TOKEN: ${{ secrets.GET_AVAILABLE_RUNNERS_API_TOKEN }}
|
||||
API_URL: ${{ github.server_url }}/api/v1/admin/actions/runners
|
||||
run: |
|
||||
RUNNER="ubuntu-latest"
|
||||
|
||||
RESPONSE=$(curl -fsS --max-time 15 \
|
||||
-H "Authorization: token ${API_TOKEN}" \
|
||||
"${API_URL}" || echo "")
|
||||
|
||||
if [ -n "$RESPONSE" ]; then
|
||||
ONLINE=$(echo "$RESPONSE" | jq '[.runners[]?
|
||||
| select(.status != "offline")
|
||||
| select(any(.labels[]?; .name == "local"))] | length')
|
||||
if [ "${ONLINE:-0}" -gt 0 ]; then
|
||||
RUNNER="local"
|
||||
fi
|
||||
else
|
||||
echo "Runner API not reachable, falling back to ubuntu-latest"
|
||||
fi
|
||||
|
||||
echo "Selected runner: $RUNNER"
|
||||
echo "runner=$RUNNER" >> "$GITHUB_OUTPUT"
|
||||
build:
|
||||
needs: select-runner
|
||||
runs-on: ${{ needs.select-runner.outputs.runner }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to GHCR
|
||||
run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
|
||||
|
||||
- name: Get Latest Tag
|
||||
id: get_tag
|
||||
run: |
|
||||
BASE64_TOKEN=$(echo "${{ secrets.GHCR_TOKEN }}" | base64)
|
||||
LATEST_TAG=$(curl -s -H "Authorization: Bearer $BASE64_TOKEN" \
|
||||
https://ghcr.io/v2/${{ env.GHCR_ORG }}/${{ env.IMAGE_NAME }}/tags/list \
|
||||
| jq -r '.tags | map(select(test("^[0-9]+$"))) | map(tonumber) | max // 0')
|
||||
NEXT_TAG=$((LATEST_TAG + 1))
|
||||
echo "latest=$LATEST_TAG" >> $GITHUB_OUTPUT
|
||||
echo "next=$NEXT_TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
run: |
|
||||
docker build \
|
||||
--build-arg COMMIT_ID=$(echo "${{ github.sha }}" | cut -c1-7) \
|
||||
-t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} .
|
||||
docker push ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }}
|
||||
|
||||
- name: Clone ops-deployment repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: notifier/ops-deployment
|
||||
path: ./ops-deployment
|
||||
token: ${{ secrets.BOT_TOKEN }}
|
||||
|
||||
- name: Update ${{ github.repository }} deployment
|
||||
working-directory: ./ops-deployment
|
||||
run: |
|
||||
NEW_TAG=${{ steps.get_tag.outputs.next }}
|
||||
NEW_IMAGE="${{ env.IMAGE_PATH }}:$NEW_TAG"
|
||||
git config user.name "automation-bot"
|
||||
git config user.email "dev@gansejunge.com"
|
||||
|
||||
sed -i "s|ghcr.io/$GHCR_ORG/$IMAGE_NAME:[0-9]\+|$NEW_IMAGE|g" "$OPS_PATH"
|
||||
|
||||
COMMIT_URL="https://git.gansejunge.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
|
||||
git add $OPS_PATH
|
||||
git commit -m "Update ${GITHUB_REPOSITORY} image to version $NEW_TAG" -m "Linked build commit: $COMMIT_URL"
|
||||
git push origin $OPS_BRANCH_BASE
|
||||
Reference in new issue
Block a user