Skip to content

Commit

Permalink
Deployment script for dsteele.dev (#7)
Browse files Browse the repository at this point in the history
* added script for personal site setup

* initial fixes from testing

* initial site setup & deployment

* minor fixes

* added git pull

* try changes to confs

* another one

* removed pushd/popd

* finished fixes & got deployed

* removed pushd/popd
  • Loading branch information
dills122 authored Dec 16, 2023
1 parent c9e20e9 commit 8067a6d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 31 deletions.
22 changes: 22 additions & 0 deletions .docker/nginx/conf.d/prod/dsteele.dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
gzip on;
gzip_static on;
gunzip on;
gzip_types text/plain text/css application/json application/javascript application/octet-stream text/xml application/xml application/xml+rss text/javascript image/x-icon image/webp;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;

listen 80;
listen [::]:80;
server_name dsteele.dev www.dsteele.dev;

root /var/www/html/dsteele.dev;

index index.html index.htm;

location ^~ /assets/ {
gzip_static on;
expires 12h;
add_header Cache-Control public;
}
}
20 changes: 1 addition & 19 deletions .docker/nginx/conf.d/prod/umami.dsteele.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ server {
gzip_min_length 1000;

listen 80;
listen [::]:80;
server_name umami.dsteele.dev www.umami.dsteele.dev;

location / {
Expand All @@ -18,22 +19,3 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}
}

server {
if ($host = www.umami.dsteele.dev) {
return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = umami.dsteele.dev) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 80 default_server;
listen [::]:80 default_server;

server_name umami.dsteele.dev www.umami.dsteele.dev;
return 404; # managed by Certbot

}
3 changes: 2 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ users:

runcmd:
- /usr/bin/git clone https://github.com/dills122/backbone-infa.git backbone-src
# - sudo rm -rf /etc/nginx/conf.d/* && sudo rm -rf /etc/nginx/sites-available/* # remove all default files
- 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
Expand All @@ -40,8 +41,8 @@ runcmd:
- sudo chmod +x /usr/local/bin/ufw-docker
- sudo ufw-docker install
- sudo systemctl restart ufw
- /usr/bin/bash ./backbone-src/scripts/certbot.sh
- /usr/bin/bash ./backbone-src/scripts/umami-setup.sh
- /usr/bin/bash ./backbone-src/scripts/personal-site-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
Expand Down
24 changes: 16 additions & 8 deletions scripts/certbot.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#!/bin/bash

domain="dsteele.dev"
umami_sub_domain="umami"
DOMAINDEFAULT="dsteele.dev"
domain="${1:-$DOMAINDEFAULT}"
sub_domain="$2"
ssl_email="dylansteele57@gmail.com"

# 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-available/
generateSSL() {
local full_domain=$1
# Copy Nginx config files
sudo cp ~/backbone-src/.docker/nginx/conf.d/prod/${full_domain}.conf /etc/nginx/sites-available/

sudo nginx -t
sudo nginx -t

sudo certbot --nginx --non-interactive --agree-tos --redirect -d ${umami_sub_domain}.${domain} -d www.${umami_sub_domain}.${domain} -m ${ssl_email}
sudo certbot --nginx --non-interactive --agree-tos --redirect -d ${full_domain} -d www.${full_domain} -m ${ssl_email}
}

if [ -n "$sub_domain" ]; then
generateSSL "$sub_domain.$domain"
else
generateSSL "$domain"
fi
19 changes: 19 additions & 0 deletions scripts/personal-site-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

remote_path="/var/www/html/dsteele.dev"

/usr/bin/git clone https://github.com/dills122/dsteele.dev.git

cd ./dsteele.dev

git pull

mkdir $remote_path

/usr/bin/bash build-deploy.sh $remote_path

/usr/bin/bash ~/backbone-src/scripts/certbot.sh dsteele.dev

cd ..

sudo systemctl restart nginx
8 changes: 5 additions & 3 deletions scripts/umami-setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

/usr/bin/bash certbot.sh dsteele.dev umami

git clone https://github.com/mikecao/umami.git

pushd umami
cd ./umami

sudo npm i -g yarn
yarn install
Expand All @@ -11,6 +13,6 @@ yarn install
echo "DATABASE_URL=postgresql://main:Ba21tedao23094!@localhost:5432/mydb" >.env

docker pull ghcr.io/mikecao/umami:postgresql-latest
docker-compose up -d
docker compose up -d

popd
cd ..

0 comments on commit 8067a6d

Please sign in to comment.