Deploy to k8s #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish and deploy | |
| on: | |
| push: | |
| branches: | |
| - trunk | |
| - new-pipeline | |
| jobs: | |
| build: | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Docker build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile.production | |
| load: true | |
| tags: vauhtijuoksu/cms:test | |
| - name: Extract Docker metadata | |
| if: github.event_name == 'push' | |
| id: meta | |
| uses: docker/metadata-action@v3 | |
| with: | |
| images: | | |
| name=ghcr.io/vauhtijuoksu/wwwauhtijuoksu-cms | |
| tags: | | |
| # sha for branch triggers | |
| type=ref,event=branch | |
| type=ref,event=branch,suffix=-{{sha}} | |
| type=ref,event=pr,suffix=-{{sha}} | |
| # semver only for version tags | |
| type=semver,pattern={{version}} | |
| - name: Log in to GHCR | |
| if: github.event_name == 'push' | |
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| # This should use cached image and not actually trigger a new build | |
| - name: Build and push images | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile.production | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| - name: Login to to Tailscale | |
| uses: tailscale/github-action@v4.1.0 | |
| with: | |
| oauth-client-id: ${{ vars.TS_OIDC_CLIENT_ID }} | |
| audience: ${{ vars.TS_OIDC_AUDIENCE }} | |
| tags: tag:gh-runner | |
| - name: Setup Kubectl | |
| uses: azure/setup-kubectl@v4 | |
| - name: Setup kubeconfig | |
| run: | | |
| mkdir ~/.kube | |
| echo "${{ vars.KUBECONFIG }}" > ~/.kube/config | |
| kubectl get all | |
| - name: Extract main sha tag | |
| id: main_sha | |
| run: | | |
| echo "tag=$(echo '${{ steps.meta.outputs.tags }}' | grep '^.*:main-')" >> $GITHUB_OUTPUT | |
| - uses: azure/setup-helm@v3.5 | |
| - run: | | |
| helm upgrade --install -n cms cms deployment/ -f deployment/prod-values.yaml --set image.tag=${{ steps.main_sha.outputs.tag }} |