refactor(bootstrap)!: create a temporary git server for the seed repo

Instead of relying on GitHub
This commit is contained in:
Khue Doan 2022-10-14 19:02:10 +07:00
parent 014cc8f571
commit 873a27c490
6 changed files with 36 additions and 18 deletions

View File

@ -47,6 +47,7 @@ test:
clean:
docker compose --project-directory ./metal/roles/pxe_server/files down
docker rm --force homelab-seed-repo
dev:
make -C metal cluster env=dev

View File

@ -1,13 +1,41 @@
#!/bin/sh
VALUES="values.yaml"
set -eu
kubectl get ingress gitea --namespace gitea \
|| VALUES="values-seed.yaml"
ADDITIONAL_VALUES=""
# If the Gitea service does not exist, it means that this is the first installation, clone from a seed repo instead
# ArgoCD will automatically switch to Gitea once the repository is clonable
if ! kubectl get service gitea-http --namespace gitea; then
# Use Ansible to get a consistent output with ../metal
CONTROLLER_IP="$(\
ANSIBLE_LOAD_CALLBACK_PLUGINS=true \
ANSIBLE_STDOUT_CALLBACK=json \
ansible localhost -m ansible.builtin.setup -a 'filter=ansible_default_ipv4' \
| jq --raw-output '.plays[0].tasks[0].hosts.localhost.ansible_facts.ansible_default_ipv4.address' \
)"
# Create a temporary git server
SEED_REPO="${PWD}/seed-repo/homelab.git"
[ -d "${SEED_REPO}" ] || git clone --bare ../.. "${SEED_REPO}"
git -C "${SEED_REPO}" update-server-info
git -C "${SEED_REPO}" fetch --all
docker start homelab-seed-repo || docker run \
--volume "${PWD}/seed-repo:/usr/share/nginx/html:ro" \
--publish 8000:80 \
--rm \
--detach \
--name homelab-seed-repo \
nginx:latest
ADDITIONAL_VALUES="gitops.repo=http://${CONTROLLER_IP}:8000/homelab.git"
fi
echo "${ADDITIONAL_VALUES}"
helm template \
--include-crds \
--namespace argocd \
--values "${VALUES}" \
--set "${ADDITIONAL_VALUES}" \
argocd . \
| kubectl apply -n argocd -f -

2
bootstrap/root/seed-repo/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -1,2 +0,0 @@
gitops:
repo: https://github.com/khuedoan/homelab

View File

@ -16,7 +16,7 @@ repositories:
owner: ops
private: false
migrate:
source: https://github.com/khuedoan/homelab
source: http://192.168.1.24:8000/homelab.git # TODO
mirror: false
# TODO create webhook (use a global one?)
# webhooks:

11
scripts/configure vendored
View File

@ -13,7 +13,6 @@ import sys
from rich.prompt import Confirm, Prompt
default_seed_repo = "https://github.com/khuedoan/homelab"
default_domain = "khuedoan.com"
default_timezone = "Asia/Ho_Chi_Minh"
default_terraform_workspace = "khuedoan"
@ -44,7 +43,6 @@ def main() -> None:
editor = Prompt.ask("Select text editor", default='nvim')
domain = Prompt.ask("Enter your domain", default=default_domain)
seed_repo = Prompt.ask("Enter seed repo", default=default_seed_repo)
timezone = Prompt.ask("Enter time zone", default=default_timezone)
find_and_replace(
@ -60,15 +58,6 @@ def main() -> None:
]
)
find_and_replace(
pattern=default_seed_repo,
replacement=seed_repo,
paths=[
"bootstrap",
"platform"
]
)
find_and_replace(
pattern=default_timezone,
replacement=timezone,