Skip to content

feat: add deployment for bookkeeper app #3

feat: add deployment for bookkeeper app

feat: add deployment for bookkeeper app #3

Workflow file for this run

name: CI — Test, Build, Push, Deploy

Check failure on line 1 in .github/workflows/ci-build-deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci-build-deploy.yml

Invalid workflow file

(Line: 64, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.KUBE_CONFIG != '', (Line: 69, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.KUBE_CONFIG != '', (Line: 73, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.KUBE_CONFIG != '', (Line: 76, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.KUBE_CONFIG != '', (Line: 81, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.KUBE_CONFIG != '', (Line: 84, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.KUBE_CONFIG != ''
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install test deps
run: python -m pip install --upgrade pip pytest
- name: Run tests
run: python -m pytest -q samples/book-app-project/tests
build-and-push:
if: github.event_name == 'push'
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v4
with:
context: samples/book-app-project
file: samples/book-app-project/Dockerfile
push: true
tags: ghcr.io/${{ github.repository_owner }}/bookkeeper-app:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main') }}
steps:
- uses: actions/checkout@v4
- name: Check KUBE_CONFIG secret
run: |
if [ -z "${{ secrets.KUBE_CONFIG }}" ]; then
echo "KUBE_CONFIG secret is not configured; skipping deploy."
exit 0
fi
- name: Install kubectl
if: ${{ secrets.KUBE_CONFIG != '' }}
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Patch Job image to GHCR
if: ${{ secrets.KUBE_CONFIG != '' }}
run: |
sed -i "s|image: bookkeeper-app:latest|image: ghcr.io/${{ github.repository_owner }}/bookkeeper-app:latest|" samples/book-app-project/k8s/job-list.yaml
- name: Configure kubeconfig
if: ${{ secrets.KUBE_CONFIG != '' }}
run: echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig
- name: Apply k8s manifests
if: ${{ secrets.KUBE_CONFIG != '' }}
run: |
kubectl --kubeconfig=kubeconfig apply -f samples/book-app-project/k8s/configmap-data.yaml
kubectl --kubeconfig=kubeconfig apply -f samples/book-app-project/k8s/job-list.yaml
- name: Wait for job completion
if: ${{ secrets.KUBE_CONFIG != '' }}
run: kubectl --kubeconfig=kubeconfig wait --for=condition=complete job/bookkeeper-list-job --timeout=120s || true
- name: Fetch job logs
if: ${{ secrets.KUBE_CONFIG != '' }}
run: kubectl --kubeconfig=kubeconfig logs job/bookkeeper-list-job || true