Skip to content

Commit

Permalink
try to use https
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeket committed Jul 7, 2024
1 parent de75002 commit 68195fe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/push-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ jobs:
TF_VAR_TG_ADMIN_GROUP_IDS: ${{ secrets.TG_ADMIN_GROUP_IDS }}
TF_VAR_GOOGLEVERIFICATION: ${{ secrets.GOOGLEVERIFICATION }}
TF_TOKEN_app_terraform_io: ${{ secrets.TF_API_TOKEN }}
TF_VAR_DOMAIN: ${{ secrets.DOMAIN }}
TF_VAR_CERTBOT_EMAIL: ${{ secrets.CERTBOT_EMAIL }}
run: tofu apply -input=false -auto-approve
2 changes: 1 addition & 1 deletion docker/docker-compose.prod.tls-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- "80:80"
- "443:443"
environment:
- CERTBOT_EMAIL=${CERTBOT_EMAIL}
- CERTBOT_EMAIL=${CERTBOT_EMAIL:?error}
volumes:
- nginx-secrets:/etc/letsencrypt
- ./nginx-conf/user_conf.d:/etc/nginx/user_conf.d
Expand Down
9 changes: 9 additions & 0 deletions infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ data "cloudinit_config" "config" {
content = templatefile("${path.module}/templates/user-data.sh.tftpl",
{
REPO_URL = local.REPO_URL
DOMAIN = var.DOMAIN
CERTBOT_EMAIL = var.CERTBOT_EMAIL
})
}

Expand Down Expand Up @@ -58,6 +60,13 @@ resource "digitalocean_domain" "hytky" {
name = "hytky.org"
}

resource "digitalocean_record" "root" {
domain = digitalocean_domain.hytky.name
type = "A"
name = "@"
value = digitalocean_droplet.webserver.ipv4_address
}

resource "digitalocean_record" "www" {
domain = digitalocean_domain.hytky.name
type = "A"
Expand Down
10 changes: 8 additions & 2 deletions infrastructure/templates/user-data.sh.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ git clone ${REPO_URL} /opt/webapp
mv /opt/secrets/.* /opt/webapp/
rmdir /opt/secrets

%{ if DOMAIN != "" }
echo "NEXTAUTH_URL=https://${DOMAIN}" | tee -a /opt/webapp/.env
sed -i '' 's/sub.yourdomain.org/${DOMAIN}/g' /opt/webapp/docker/nginx-conf/user_conf.d/tls.conf
export CERTBOT_EMAIL=${CERTBOT_EMAIL}
docker compose -f /opt/webapp/docker/docker-compose.prod.tls-registry.yml up -d
%{ else }
IP=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1 | awk -F. '$1>=1 && $1<=126 || $1>=128 && $1<=191' | head -n 1)
echo "NEXTAUTH_URL=http://$IP" | tee -a /opt/webapp/.env

docker compose -f /opt/webapp/docker/docker-compose.prod.from-registry.yml up -d
docker compose -f /opt/webapp/docker/docker-compose.prod.from-registry.yml up -d
%{ endif }
13 changes: 13 additions & 0 deletions infrastructure/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
variable "DOMAIN" {
description = "Domain Name"
type = string
default = ""
}

variable "CERTBOT_EMAIL" {
description = "The email address to use for Let's Encrypt"
type = string
default = ""
sensitive = true
}

variable "do_token" {
description = "Digital Ocean Token"
type = string
Expand Down

0 comments on commit 68195fe

Please sign in to comment.