75 lines
2.8 KiB
YAML
75 lines
2.8 KiB
YAML
on:
|
|
push:
|
|
branches: [ main ]
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- uses: benjlevesque/short-sha@v3.0
|
|
id: short-sha
|
|
with:
|
|
length: 10
|
|
- name: Set up 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: Set up kubectl
|
|
uses: azure/setup-kubectl@v4
|
|
- name: Configure (kubectl)
|
|
env:
|
|
KUBE_CA_DATA: ${{ secrets.KUBE_CA_DATA }}
|
|
KUBE_USER_TOKEN: ${{ secrets.KUBE_USER_TOKEN }}
|
|
run: |
|
|
KUBECONFIG=$(mktemp)
|
|
tee "${KUBECONFIG}" <<EOF
|
|
apiVersion: v1
|
|
kind: Config
|
|
clusters:
|
|
- cluster:
|
|
certificate-authority-data: ${KUBE_CA_DATA}
|
|
server: https://kubernetes.default.svc
|
|
name: local
|
|
contexts:
|
|
- context:
|
|
name: local
|
|
cluster: local
|
|
user: user
|
|
namespace: test-builder
|
|
current-context: local
|
|
users:
|
|
- name: local
|
|
user:
|
|
token: ${KUBE_USER_TOKEN}
|
|
EOF
|
|
echo "KUBECONFIG=${KUBECONFIG}" >> $GITHUB_ENV
|
|
- name: Check kubernetes connection
|
|
run: |
|
|
echo "Kubernetes connection config (KUBECONFIG): ${KUBECONFIG}"
|
|
cat ${KUBECONFIG}
|
|
kubectl get pod -A
|
|
- name: Update kpack image
|
|
env:
|
|
SHA: ${{ github.sha }}
|
|
SHORT_SHA: ${{ steps.short-sha.outputs.sha }}
|
|
run: |
|
|
kp image patch tutorial-image --replace-additional-tag "ghcr.io/hvg-dev/php-test:sha-${SHORT_SHA}" --git-revision "${SHA}" -n test-builder
|
|
- name: Wait for build to complete
|
|
run: |
|
|
BUILD=$(kubectl -n test-builder get image tutorial-image -o jsonpath='{.status.buildCounter}')
|
|
BUILD_REF=$(kubectl -n test-builder get image tutorial-image -o jsonpath='{.status.latestBuildRef}')
|
|
kp build logs tutorial-image -n test-builder --build ${BUILD}
|
|
kp build status tutorial-image -n test-builder -b $BUILD
|
|
if [ "$(kubectl -n test-builder 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 }}
|