k8sdeploy/entrypoint.sh

33 lines
926 B
Bash
Raw Permalink Normal View History

2024-04-30 21:08:27 +00:00
#!/bin/bash -e
# shellcheck disable=SC1091
2024-11-29 05:39:38 +00:00
cd "$INPUT_WORKDIR"
2024-04-30 21:08:27 +00:00
set -a
. ./.env
set +a
2024-11-29 05:05:59 +00:00
export K8S_NS;
K8S_NS="$(printf '%s' "${GITHUB_REPOSITORY#*/}-$GITHUB_REF_NAME" \
| tr '[:upper:]' '[:lower:]' | tr -c '[:lower:][:digit:]-' - \
| sed 's/-\+/-/g; s/^-\+//; s/-$//')"
2024-04-30 21:08:27 +00:00
mkdir -p "$HOME/.kube/"
2024-05-10 09:59:11 +00:00
echo "$INPUT_KUBECONFIG" > "$HOME/.kube/config"
2024-05-15 17:41:54 +00:00
kubectl get namespace "$K8S_NS" || kubectl create namespace "$K8S_NS"
kubectl config set-context --current --namespace="$K8S_NS"
2024-04-30 21:08:27 +00:00
2024-05-10 09:59:11 +00:00
if [ -n "$INPUT_REGISTRY_PASSWORD" ]; then
2024-04-30 21:34:03 +00:00
kubectl get secret regcred \
|| kubectl create secret docker-registry regcred \
2024-11-29 05:05:59 +00:00
--docker-server="${IMAGEAPP%%/*}" \
2024-05-10 09:59:11 +00:00
--docker-username="$INPUT_REGISTRY_USERNAME" \
--docker-password="$INPUT_REGISTRY_PASSWORD"
2024-04-30 21:08:27 +00:00
fi
2024-05-10 09:59:11 +00:00
if [ "$GITHUB_REF_NAME" = prod ] || [ "$GITHUB_REF_NAME" = staging ]; then
2024-05-01 10:36:00 +00:00
./manifests/bin/prod.sh
else
./manifests/bin/devel.sh
fi