diff --git a/.github/workflows/build-and-deploy.yaml b/.github/workflows/build-and-deploy.yaml index 0766bfd..5b904aa 100644 --- a/.github/workflows/build-and-deploy.yaml +++ b/.github/workflows/build-and-deploy.yaml @@ -41,8 +41,20 @@ jobs: echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > $HOME/.kube/config shell: bash + - name: Detect container name + id: detect-container + run: | + CONTAINER=$(kubectl -n $NAMESPACE get deployment homepage -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" - kubectl set image deployment/homepage home=$IMAGE -n $NAMESPACE - shell: bash + CONTAINER="${{ steps.detect-container.outputs.container }}" + echo "Deploying $CONTAINER with image $IMAGE to $NAMESPACE" + kubectl set image deployment/homepage $CONTAINER=$IMAGE -n $NAMESPACE + env: + VERSION: ${{ vars.VERSION || 'latest' }} + NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }}