From a92dd3bee534cc8d44561d99f1bb5ea6ff9bd8f4 Mon Sep 17 00:00:00 2001 From: Dylan Steele Date: Thu, 14 Dec 2023 20:55:15 -0500 Subject: [PATCH] fixed bugs with terraform & umami setup --- .../prod/{default.conf => umami.dsteele.dev.conf} | 0 app.yaml | 7 +++++++ droplet.tf | 12 +++--------- scripts/certbot.sh | 6 +++--- scripts/umami-setup.sh | 7 +++++-- 5 files changed, 18 insertions(+), 14 deletions(-) rename .docker/nginx/conf.d/prod/{default.conf => umami.dsteele.dev.conf} (100%) diff --git a/.docker/nginx/conf.d/prod/default.conf b/.docker/nginx/conf.d/prod/umami.dsteele.dev.conf similarity index 100% rename from .docker/nginx/conf.d/prod/default.conf rename to .docker/nginx/conf.d/prod/umami.dsteele.dev.conf diff --git a/app.yaml b/app.yaml index 36c2290..0440c66 100644 --- a/app.yaml +++ b/app.yaml @@ -12,6 +12,7 @@ packages: - nginx - certbot - python3-certbot-nginx + - npm # Add users to the system. Users are added after groups are added. users: @@ -28,6 +29,11 @@ users: runcmd: - /usr/bin/git clone https://github.com/dills122/backbone-infa.git backbone-src + - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + - export NVM_DIR="$HOME/.nvm" + - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + - nvm alias default lts/iron - sudo ufw allow 'Nginx Full' - sudo ufw deny 6379 # Lockdown redis port from the outside world - sudo wget -O /usr/local/bin/ufw-docker https://github.com/chaifeng/ufw-docker/raw/master/ufw-docker @@ -38,5 +44,6 @@ runcmd: - /usr/bin/bash ./backbone-src/scripts/umami-setup.sh - sudo systemctl restart nginx - /usr/bin/docker update --restart unless-stopped $(docker ps -q) + - sudo echo "0 12 * * * terraform /usr/bin/certbot renew --quiet" >/etc/cron.d/certbot_renew final_message: "The system is finally up, after $UPTIME seconds" diff --git a/droplet.tf b/droplet.tf index 19234f3..49a89e7 100644 --- a/droplet.tf +++ b/droplet.tf @@ -1,11 +1,3 @@ -data "template_file" "userdata" { - template = file("${path.module}/app.yaml") - - vars = { - pub_key = var.ssh_public_key != "default" ? var.ssh_public_key : file(var.ssh_public_key_path) - } -} - # Setup a DO droplet resource "digitalocean_droplet" "backbone_server_1" { image = var.droplet_image @@ -15,7 +7,9 @@ resource "digitalocean_droplet" "backbone_server_1" { ssh_keys = [ var.ssh_key_fingerprint ] - user_data = data.template_file.userdata.rendered + user_data = templatefile("${path.module}/app.yaml", { + pub_key = var.ssh_public_key != "default" ? var.ssh_public_key : file(var.ssh_public_key_path) + }) } ################################################################################ diff --git a/scripts/certbot.sh b/scripts/certbot.sh index ee8c943..4825a0f 100644 --- a/scripts/certbot.sh +++ b/scripts/certbot.sh @@ -4,10 +4,10 @@ domain="dsteele.dev" umami_sub_domain="umami" ssl_email="dylansteele57@gmail.com" -#TODO fix issue with nginx config/ cert install; cant have listen 80 and 443 in same server, certbot doesnt remove the 80 -sudo rm -rf /etc/nginx/conf.d/* && sudo rm -rf /etc/nginx/sites-enabled/default +# Need to update the naming to the url of site ex. umami.dsteele.dev +sudo rm -rf /etc/nginx/conf.d/* && sudo rm -rf /etc/nginx/sites-available/* # Copy Nginx config files -sudo cp ~/backbone-src/.docker/nginx/conf.d/prod/* /etc/nginx/sites-enabled/ +sudo cp ~/backbone-src/.docker/nginx/conf.d/prod/* /etc/nginx/sites-available/ sudo nginx -t diff --git a/scripts/umami-setup.sh b/scripts/umami-setup.sh index f49d2b9..87b3ae9 100644 --- a/scripts/umami-setup.sh +++ b/scripts/umami-setup.sh @@ -4,8 +4,11 @@ git clone https://github.com/mikecao/umami.git pushd umami -npm i -npm run build +sudo npm i -g yarn +yarn install +# yarn build + +echo "DATABASE_URL=postgresql://main:Ba21tedao23094!@localhost:5432/mydb" >.env docker pull ghcr.io/mikecao/umami:postgresql-latest docker-compose up -d