From 7f1c16a3ed5566e1b74569117eff42dbfea9441b Mon Sep 17 00:00:00 2001 From: Derek Crudgington Date: Fri, 17 Mar 2023 15:07:46 +0000 Subject: [PATCH] Added Gitea and Caddy --- lib/caddy.sh | 82 ++++++++++++++++++++++++++++++++ lib/gitea.sh | 117 ++++++++++++++++++++++++++++++++++++++++++++++ lib/postgresql.sh | 4 ++ 3 files changed, 203 insertions(+) create mode 100644 lib/caddy.sh create mode 100644 lib/gitea.sh diff --git a/lib/caddy.sh b/lib/caddy.sh new file mode 100644 index 0000000..dd9741c --- /dev/null +++ b/lib/caddy.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# +# Caddy Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +config_caddy() { + echo -ne "\n* Configuring /federated/apps/caddy container.." + spin & + SPINPID=$! + + if [ ! -d "/federated/apps/caddy" ]; then + mkdir -p /federated/apps/caddy/data/data + mkdir -p /federated/apps/caddy/data/etc/caddy + fi + + DOMAIN_ARRAY=(${DOMAIN//./ }) + DOMAIN_FIRST=${DOMAIN_ARRAY[0]} + DOMAIN_LAST=${DOMAIN_ARRAY[1]} + +cat > /federated/apps/caddy/docker-compose.yml < /federated/apps/caddy/.env < /federated/apps/caddy/data/etc/caddy/Caddyfile < /dev/null +echo -ne "done." +} +start_caddy() { + # Start service with command to make sure it's up before proceeding + start_service "caddy" "nc -z 172.99.0.31 2019 &> /dev/null" + + kill -9 $SPINPID &> /dev/null + echo -ne "done." +} diff --git a/lib/gitea.sh b/lib/gitea.sh new file mode 100644 index 0000000..576cb63 --- /dev/null +++ b/lib/gitea.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# +# Gitea Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +config_gitea() { + echo -ne "\n* Configuring /federated/apps/gitea container.." + spin & + SPINPID=$! + + if [ ! -d "/federated/apps/gitea" ]; then + mkdir -p /federated/apps/gitea/data/data + fi + + DOMAIN_ARRAY=(${DOMAIN//./ }) + DOMAIN_FIRST=${DOMAIN_ARRAY[0]} + DOMAIN_LAST=${DOMAIN_ARRAY[1]} + +cat > /federated/apps/gitea/docker-compose.yml < /federated/apps/gitea/.env < /federated/apps/gitea/data/creategitea.sh </dev/null | awk -F: '{ print \$4 }' | awk -F\" '{ print \$2 }'\` + +# Create the repository hugowebsite +curl -k -X POST http://gitea.$DOMAIN:3000/api/v1/user/repos -H "content-type: application/json" -H "Authorization: token \$GITEA_TOKEN_2" --data '{"name":"hugowebsite","auto_init":true,"default_branch":"master"}' + +# Create the webhook inside the hugowebsite repository +curl -X 'POST' \ + 'http://gitea.$DOMAIN:3000/api/v1/repos/gitea/hugowebsite/hooks' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -H "Authorization: token \$GITEA_TOKEN_2" \ + -d '{ + "active": true, + "config": { + "content_type": "json", + "url": "https://www.$DOMAIN/webhook", + "secret": "$WEBHOOK_SECRET" + }, + "events": [ + "push" + ], + "type": "gitea" +}' +EOF +chmod +x /federated/apps/gitea/data/creategitea.sh + +kill -9 $SPINPID &> /dev/null +echo -ne "done." +} +start_gitea() { + # Start service with command to make sure it's up before proceeding + start_service "gitea" "nc -z 172.99.0.30 3000 &> /dev/null" + + mv /federated/apps/gitea/data/creategitea.sh /federated/apps/gitea/data/data/creategitea.sh + docker exec --user 1000 gitea gitea admin user create --admin --username gitea --password $ADMINPASS --email admin@$DOMAIN + [ $? -ne 0 ] && fail "Couldn't run gitea user create inside /federated/apps/gitea container" + + docker exec -it gitea /data/creategitea.sh + [ $? -ne 0 ] && fail "Couldn't run creategitea.sh inside /federated/apps/gitea container" + + GITEA_TOKEN_1=`docker exec -it gitea curl -H "Content-Type: application/json" -d '{"name":"gitea1"}' -u gitea:$ADMINPASS http://gitea.$DOMAIN:3000/api/v1/users/gitea/tokens 2>/dev/null | awk -F: '{ print $4 }' | awk -F\" '{ print $2 }'` + [ $? -ne 0 ] && fail "Couldn't run gitea curl to get token inside /federated/apps/gitea container" + + kill -9 $SPINPID &> /dev/null + echo -ne "done." +} diff --git a/lib/postgresql.sh b/lib/postgresql.sh index 7ca244f..1c07b0d 100644 --- a/lib/postgresql.sh +++ b/lib/postgresql.sh @@ -79,6 +79,7 @@ LISTMONK_SECRET=$(create_password); MATRIX_SECRET=$(create_password); BASEROW_SECRET=$(create_password); CALCOM_SECRET=$(create_password); +GITEA_SECRET=$(create_password); # cat postgresql/data/docker-entrypoint-initdb.d/init.sql cat > /federated/apps/postgresql/data/docker-entrypoint-initdb.d/init.sql < /dev/null