From 2b6c1a109ef17f22ee6546e3d785cb4e9555abd0 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Fri, 3 May 2024 18:02:29 -0500 Subject: [PATCH 1/2] feat: make running gitops secrets gen from another box easier Make it possible to re-run the secrets generating script when you don't have the configs for setting up the repo access locally. This should make it easier to share things between folks. --- scripts/gitops-secrets-gen.sh | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/scripts/gitops-secrets-gen.sh b/scripts/gitops-secrets-gen.sh index eec9bc2fe..81fcc3c50 100755 --- a/scripts/gitops-secrets-gen.sh +++ b/scripts/gitops-secrets-gen.sh @@ -30,19 +30,21 @@ if [ "x${DEPLOY_NAME}" = "x" ]; then usage fi -if [ "x${UC_DEPLOY_GIT_URL}" = "x" ]; then - echo "UC_DEPLOY_GIT_URL is not set." >&2 - usage -fi - -if [ "x${UC_DEPLOY_SSH_FILE}" = "x" ]; then - echo "UC_DEPLOY_SSH_FILE is not set." >&2 - usage -fi - -if [ ! -f "${UC_DEPLOY_SSH_FILE}" ]; then - echo "UC_DEPLOY_SSH_FILE is not a file." >&2 - usage +if [ -f "${UC_DEPLOY}/secrets/${DEPLOY_NAME}/argocd/secret-deploy-repo.yaml" ]; then + NO_SECRET_DEPLOY=1 +else + if [ "x${UC_DEPLOY_GIT_URL}" = "x" ]; then + echo "UC_DEPLOY_GIT_URL is not set." >&2 + usage + fi + if [ "x${UC_DEPLOY_SSH_FILE}" = "x" ]; then + echo "UC_DEPLOY_SSH_FILE is not set." >&2 + usage + fi + if [ ! -f "${UC_DEPLOY_SSH_FILE}" ]; then + echo "UC_DEPLOY_SSH_FILE at ${UC_DEPLOY_SSH_FILE} does not exist." >&2 + usage + fi fi if [ "x${DNS_ZONE}" = "x" ]; then @@ -62,9 +64,10 @@ export DO_TMPL_VALUES=y mkdir -p "${UC_DEPLOY}/secrets/${DEPLOY_NAME}" "${SCRIPTS_DIR}/easy-secrets-gen.sh" "${UC_DEPLOY}/secrets/${DEPLOY_NAME}" -echo "Creating ArgoCD config" -mkdir -p "${UC_DEPLOY}/secrets/${DEPLOY_NAME}/argocd" -cat << EOF > "${UC_DEPLOY}/secrets/${DEPLOY_NAME}/argocd/secret-deploy-repo.yaml" +if [ "x${NO_SECRET_DEPLOY}" = "x" ]; then + echo "Creating ArgoCD config" + mkdir -p "${UC_DEPLOY}/secrets/${DEPLOY_NAME}/argocd" + cat << EOF > "${UC_DEPLOY}/secrets/${DEPLOY_NAME}/argocd/secret-deploy-repo.yaml" apiVersion: v1 kind: Secret metadata: @@ -76,6 +79,7 @@ data: type: $(printf "git" | base64) url: $(printf "${UC_DEPLOY_GIT_URL}" | base64) EOF +fi echo "Creating Cert Manager Cluster Issuer" cat << EOF > "${UC_DEPLOY}/secrets/${DEPLOY_NAME}/cluster-issuer.yaml" From 1515519107997d164e034f733f60b96b4cdd8b5d Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 6 May 2024 10:11:07 -0500 Subject: [PATCH 2/2] feat: make it easier for others to re-run gitops scripts This should make it much easier for others to re-run the scripts by making the paths relative. --- docs/gitops-install.md | 3 +-- scripts/gitops-deploy.sh | 2 ++ scripts/gitops-secrets-gen.sh | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/gitops-install.md b/docs/gitops-install.md index c0968f9f4..ce4b0fd4d 100644 --- a/docs/gitops-install.md +++ b/docs/gitops-install.md @@ -48,8 +48,7 @@ To avoid defining many environment variables we'll simplify by creating an place it where we've cloned understack. A complete file would like like ```bash title="/path/to/uc-deploy/my-k3s.env" -UC_REPO="$HOME/devel/understack" -UC_DEPLOY="$HOME/devel/uc-deploy" +UC_DEPLOY="$(pwd)/$(dirname ${BASH_SOURCE[0]})" DEPLOY_NAME="my-k3s" UC_DEPLOY_GIT_URL=git@github.com:myorg/uc-deploy.git UC_DEPLOY_SSH_FILE="$HOME/devel/uc-deploy-key" diff --git a/scripts/gitops-deploy.sh b/scripts/gitops-deploy.sh index b63f0c705..5296e4208 100755 --- a/scripts/gitops-deploy.sh +++ b/scripts/gitops-deploy.sh @@ -24,6 +24,8 @@ fi . "$1" +export UC_REPO="$(git rev-parse --show-toplevel)" + if [ ! -d "${UC_REPO}" ]; then echo "UC_REPO not set to a path." >&2 usage diff --git a/scripts/gitops-secrets-gen.sh b/scripts/gitops-secrets-gen.sh index 81fcc3c50..d221e1980 100755 --- a/scripts/gitops-secrets-gen.sh +++ b/scripts/gitops-secrets-gen.sh @@ -18,7 +18,9 @@ if [ ! -f "$1" ]; then usage fi -source "$1" +. "$1" + +export UC_REPO="$(git rev-parse --show-toplevel)" if [ ! -d "${UC_DEPLOY}" ]; then echo "UC_DEPLOY not set to a path." >&2