k8sdeploy/entrypoint.sh
2024-11-29 05:39:38 +00:00

33 lines
926 B
Bash
Executable File

#!/bin/bash -e
# shellcheck disable=SC1091
cd "$INPUT_WORKDIR"
set -a
. ./.env
set +a
export K8S_NS;
K8S_NS="$(printf '%s' "${GITHUB_REPOSITORY#*/}-$GITHUB_REF_NAME" \
| tr '[:upper:]' '[:lower:]' | tr -c '[:lower:][:digit:]-' - \
| sed 's/-\+/-/g; s/^-\+//; s/-$//')"
mkdir -p "$HOME/.kube/"
echo "$INPUT_KUBECONFIG" > "$HOME/.kube/config"
kubectl get namespace "$K8S_NS" || kubectl create namespace "$K8S_NS"
kubectl config set-context --current --namespace="$K8S_NS"
if [ -n "$INPUT_REGISTRY_PASSWORD" ]; then
kubectl get secret regcred \
|| kubectl create secret docker-registry regcred \
--docker-server="${IMAGEAPP%%/*}" \
--docker-username="$INPUT_REGISTRY_USERNAME" \
--docker-password="$INPUT_REGISTRY_PASSWORD"
fi
if [ "$GITHUB_REF_NAME" = prod ] || [ "$GITHUB_REF_NAME" = staging ]; then
./manifests/bin/prod.sh
else
./manifests/bin/devel.sh
fi