|
| 1 | +name: CI — Test, Build, Push, Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + - name: Set up Python |
| 15 | + uses: actions/setup-python@v4 |
| 16 | + with: |
| 17 | + python-version: '3.10' |
| 18 | + - name: Install test deps |
| 19 | + run: python -m pip install --upgrade pip pytest |
| 20 | + - name: Run tests |
| 21 | + run: python -m pytest -q samples/book-app-project/tests |
| 22 | + |
| 23 | + build-and-push: |
| 24 | + needs: test |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + packages: write |
| 29 | + id-token: write |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + - name: Set up QEMU |
| 33 | + uses: docker/setup-qemu-action@v2 |
| 34 | + - name: Set up Docker Buildx |
| 35 | + uses: docker/setup-buildx-action@v2 |
| 36 | + - name: Log in to GHCR |
| 37 | + uses: docker/login-action@v2 |
| 38 | + with: |
| 39 | + registry: ghcr.io |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + - name: Build and push image |
| 43 | + uses: docker/build-push-action@v4 |
| 44 | + with: |
| 45 | + context: samples/book-app-project |
| 46 | + file: samples/book-app-project/Dockerfile |
| 47 | + push: true |
| 48 | + tags: ghcr.io/${{ github.repository_owner }}/bookkeeper-app:latest |
| 49 | + |
| 50 | + deploy: |
| 51 | + needs: build-and-push |
| 52 | + runs-on: ubuntu-latest |
| 53 | + if: ${{ secrets.KUBE_CONFIG != '' }} |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + - name: Install kubectl |
| 57 | + uses: azure/setup-kubectl@v3 |
| 58 | + with: |
| 59 | + version: 'latest' |
| 60 | + - name: Patch Job image to GHCR |
| 61 | + run: | |
| 62 | + sed -i "s|image: bookkeeper-app:latest|image: ghcr.io/${{ github.repository_owner }}/bookkeeper-app:latest|" samples/book-app-project/k8s/job-list.yaml |
| 63 | + - name: Configure kubeconfig |
| 64 | + run: echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig |
| 65 | + - name: Apply k8s manifests |
| 66 | + run: | |
| 67 | + kubectl --kubeconfig=kubeconfig apply -f samples/book-app-project/k8s/configmap-data.yaml |
| 68 | + kubectl --kubeconfig=kubeconfig apply -f samples/book-app-project/k8s/job-list.yaml |
| 69 | + - name: Wait for job completion |
| 70 | + run: kubectl --kubeconfig=kubeconfig wait --for=condition=complete job/bookkeeper-list-job --timeout=120s || true |
| 71 | + - name: Fetch job logs |
| 72 | + run: kubectl --kubeconfig=kubeconfig logs job/bookkeeper-list-job || true |
0 commit comments