1
0
Files
test-php/.gitea/workflows/cd.yaml
2025-08-21 14:36:40 +00:00

55 lines
2.4 KiB
YAML

on:
push:
branches:
- main
- dev
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
- name: Install kpack-cli
env:
KPACK_CLI_VERSION: "0.13.0"
working-directory: /tmp
run: |
mkdir kp-binaries
curl -sL "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 -sLO "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 }}
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV
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 }}