104 lines
3.9 KiB
YAML
104 lines
3.9 KiB
YAML
name: Validate and deploy coturn
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
|
|
env:
|
|
KUBECONFORM_VERSION: v0.7.0
|
|
KUBECTL_VERSION: v1.36.3
|
|
KUBERNETES_API: https://host.containers.internal:6443
|
|
KUBERNETES_TLS_SERVER_NAME: 192.168.0.2
|
|
NAMESPACE: coturn
|
|
|
|
jobs:
|
|
validate:
|
|
name: Validate manifests
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Validate scripts and Kubernetes resources
|
|
run: |
|
|
sh -n install.sh bootstrap-turn-secret.sh
|
|
bash -n create-ci-kubeconfig.sh
|
|
docker run --rm --interactive \
|
|
"ghcr.io/yannh/kubeconform:${KUBECONFORM_VERSION}" \
|
|
-strict -summary -ignore-missing-schemas < coturn.yaml
|
|
docker run --rm --interactive \
|
|
"ghcr.io/yannh/kubeconform:${KUBECONFORM_VERSION}" \
|
|
-strict -summary < coturn-relay-service.yaml
|
|
docker run --rm --interactive \
|
|
"ghcr.io/yannh/kubeconform:${KUBECONFORM_VERSION}" \
|
|
-strict -summary < ci-deployer.yaml
|
|
|
|
deploy:
|
|
name: Deploy to Kubernetes
|
|
if: gitea.ref == 'refs/heads/main'
|
|
needs: validate
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out source
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install kubectl
|
|
run: |
|
|
curl --fail --silent --show-error --location \
|
|
--output "${RUNNER_TEMP}/kubectl" \
|
|
"https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"
|
|
chmod 0700 "${RUNNER_TEMP}/kubectl"
|
|
|
|
- name: Configure Kubernetes access
|
|
env:
|
|
KUBE_CONFIG_BASE64: ${{ secrets.KUBE_CONFIG_BASE64 }}
|
|
run: |
|
|
test -n "${KUBE_CONFIG_BASE64}"
|
|
printf '%s' "${KUBE_CONFIG_BASE64}" | base64 --decode > "${RUNNER_TEMP}/kubeconfig"
|
|
chmod 0600 "${RUNNER_TEMP}/kubeconfig"
|
|
export KUBECONFIG="${RUNNER_TEMP}/kubeconfig"
|
|
"${RUNNER_TEMP}/kubectl" config set-cluster cluster \
|
|
--server="${KUBERNETES_API}" \
|
|
--tls-server-name="${KUBERNETES_TLS_SERVER_NAME}"
|
|
|
|
- name: Apply and verify
|
|
run: |
|
|
export KUBECONFIG="${RUNNER_TEMP}/kubeconfig"
|
|
"${RUNNER_TEMP}/kubectl" apply \
|
|
--dry-run=server \
|
|
--validate=false \
|
|
--filename coturn.yaml \
|
|
--filename coturn-relay-service.yaml
|
|
"${RUNNER_TEMP}/kubectl" apply \
|
|
--validate=false \
|
|
--filename coturn.yaml \
|
|
--filename coturn-relay-service.yaml
|
|
|
|
for attempt in {1..60}; do
|
|
IFS='|' read -r generation observed desired updated available unavailable <<< "$(
|
|
"${RUNNER_TEMP}/kubectl" --namespace "${NAMESPACE}" \
|
|
get deployment/coturn \
|
|
--output=jsonpath='{.metadata.generation}|{.status.observedGeneration}|{.spec.replicas}|{.status.updatedReplicas}|{.status.availableReplicas}|{.status.unavailableReplicas}'
|
|
)"
|
|
certificate_ready=$(
|
|
"${RUNNER_TEMP}/kubectl" --namespace "${NAMESPACE}" \
|
|
get certificate/coturn \
|
|
--output=jsonpath='{.status.conditions[?(@.type=="Ready")].status}'
|
|
)
|
|
|
|
echo "Check ${attempt}/60: deployment generation ${observed}/${generation}, replicas ${updated}/${desired} updated, ${available}/${desired} available; certificate Ready=${certificate_ready:-False}"
|
|
if [[ "${observed}" == "${generation}" \
|
|
&& "${updated}" == "${desired}" \
|
|
&& "${available}" == "${desired}" \
|
|
&& ( -z "${unavailable}" || "${unavailable}" == "0" ) \
|
|
&& "${certificate_ready}" == "True" ]]; then
|
|
echo "coturn deployment and certificate are ready"
|
|
exit 0
|
|
fi
|
|
|
|
sleep 5
|
|
done
|
|
|
|
echo "coturn did not become ready within five minutes" >&2
|
|
exit 1
|