From 190238cc4c5d9ef7f7328317b5e4f264973bab47 Mon Sep 17 00:00:00 2001 From: Keyvan Ebrahimpour Date: Fri, 11 Apr 2025 19:16:53 +0000 Subject: [PATCH] use gh token --- .github/workflows/build-and-deploy.yaml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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' }}