name: Build and Deploy on: push: branches: - main - dev - 'feat/**' - 'test/**' - 'fix/**' - 'hotfix/**' env: VERSION: ${{ vars.VERSION || 'latest' }} NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }} jobs: build-and-deploy: runs-on: ubuntu-24.04 permissions: contents: read packages: write steps: - name: Checkout code uses: actions/checkout@v3 - name: Log in to GitHub Container Registry uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GHCR_PAT }} - name: Build and Push Docker Image run: | docker build -t ghcr.io/${{ github.repository }}:$VERSION . docker push ghcr.io/${{ github.repository }}:$VERSION - name: Set up kubeconfig from secret run: | mkdir -p $HOME/.kube echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > $HOME/.kube/config chmod 600 ~/.kube/config shell: bash - name: Detect container name id: detect-container run: | CONTAINER=$(kubectl -n $NAMESPACE get deployment landing-page -o=jsonpath='{.spec.template.spec.containers[0].name}') echo "container=$CONTAINER" >> $GITHUB_OUTPUT env: NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }} - name: Deploy to Kubernetes run: | IMAGE="ghcr.io/${{ github.repository }}:$VERSION" CONTAINER="${{ steps.detect-container.outputs.container }}" echo "Setting image for container $CONTAINER" kubectl set image deployment/landing-page $CONTAINER=$IMAGE -n $NAMESPACE env: VERSION: ${{ vars.VERSION || 'latest' }} NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }}