fix(ci): detect container name dynamically for kubectl set image
This commit is contained in:
parent
411efc023a
commit
ccd3a5ac6a
1 changed files with 5 additions and 1 deletions
6
.github/workflows/build-and-deploy.yaml
vendored
6
.github/workflows/build-and-deploy.yaml
vendored
|
|
@ -46,11 +46,15 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
CONTAINER=$(kubectl -n $NAMESPACE get deployment homepage -o=jsonpath='{.spec.template.spec.containers[0].name}')
|
CONTAINER=$(kubectl -n $NAMESPACE get deployment homepage -o=jsonpath='{.spec.template.spec.containers[0].name}')
|
||||||
echo "container=$CONTAINER" >> $GITHUB_OUTPUT
|
echo "container=$CONTAINER" >> $GITHUB_OUTPUT
|
||||||
|
env:
|
||||||
|
NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }}
|
||||||
|
|
||||||
- name: Deploy to Kubernetes
|
- name: Deploy to Kubernetes
|
||||||
run: |
|
run: |
|
||||||
IMAGE="ghcr.io/${{ github.repository }}:$VERSION"
|
IMAGE="ghcr.io/${{ github.repository }}:$VERSION"
|
||||||
kubectl set image deployment/homepage ${{ steps.detect-container.outputs.container }}=$IMAGE -n $NAMESPACE
|
CONTAINER="${{ steps.detect-container.outputs.container }}"
|
||||||
|
echo "Setting image for container $CONTAINER"
|
||||||
|
kubectl set image deployment/homepage $CONTAINER=$IMAGE -n $NAMESPACE
|
||||||
env:
|
env:
|
||||||
VERSION: ${{ vars.VERSION || 'latest' }}
|
VERSION: ${{ vars.VERSION || 'latest' }}
|
||||||
NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }}
|
NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue