1
0
Files
test-php/.gitea/workflows/cd.yaml
felegy 056c391fe7
All checks were successful
/ build-and-deploy (push) Successful in 1m31s
~ FIX IMAGE_NAME in cd.yaml
2025-08-21 12:34:04 +00:00

56 lines
2.4 KiB
YAML

on:
push:
branches: [ main ]
env:
NAMESPACE: ${{ github.repository_owner }}
DOCKER_REGISTRY: ghcr.io
DOCKER_REPOSITORY: ${{ github.repository }}
jobs:
build-and-deploy:
env:
IMAGE: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REPOSITORY }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: benjlevesque/short-sha@v3.0
id: short-sha
with:
length: 10
- name: Install kpack-cli
env:
KPACK_CLI_VERSION: "0.13.0"
working-directory: /tmp
run: |
mkdir kp-binaries
curl -L "https://github.com/buildpacks-community/kpack-cli/releases/download/v${KPACK_CLI_VERSION}/kp-linux-amd64-${KPACK_CLI_VERSION}" -o kp-binaries/kp-linux-amd64-${KPACK_CLI_VERSION}
curl -LO "https://github.com/buildpacks-community/kpack-cli/releases/download/v${KPACK_CLI_VERSION}/kp-linux-amd64-${KPACK_CLI_VERSION}.sha256"
sha256sum -c kp-linux-amd64-${KPACK_CLI_VERSION}.sha256 || exit 1
sudo mv kp-binaries/kp-linux-amd64-${KPACK_CLI_VERSION} /usr/local/bin/kp
sudo chmod +x /usr/local/bin/kp
kp version
- name: Install kubectl
uses: azure/setup-kubectl@v4
- name: Configure kubectl
uses: azure/k8s-set-context@v1
with:
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Update kpack image
env:
SHA: ${{ github.sha }}
SHORT_SHA: ${{ steps.short-sha.outputs.sha }}
run: |
IMAGE_NAME="${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}-${GITHUB_REF##*/}"
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
kp image patch $IMAGE_NAME --replace-additional-tag "${IMAGE}:sha-${SHORT_SHA}" --git-revision "${SHA}" -n $NAMESPACE
kp image status $IMAGE_NAME -n $NAMESPACE
- name: Wait for build to complete
run: |
BUILD=$(kubectl -n $NAMESPACE get image $IMAGE_NAME -o jsonpath='{.status.buildCounter}')
BUILD_REF=$(kubectl -n $NAMESPACE get image $IMAGE_NAME -o jsonpath='{.status.latestBuildRef}')
kp build logs $IMAGE_NAME -n $NAMESPACE --build ${BUILD}
kp build status $IMAGE_NAME -n $NAMESPACE -b $BUILD
if [ "$(kubectl -n $NAMESPACE get build $BUILD_REF -o jsonpath='{.status.conditions[0].status}')" != "True" ]; then exit 1; fi
# - name: Update Kubernetes deployment
# run: |
# kubectl set image deployment/my-app my-app=<registry>/<repository>:${{ github.sha }}