Compare commits

..

3 Commits

Author SHA1 Message Date
2401368316 feat: nginx proxy manager 2025-10-12 17:32:07 -04:00
8ca2011d77 feat: add yq to pip requirements 2025-10-08 21:21:02 -04:00
c42a638a53 feat: provision proxy 2025-10-08 21:18:39 -04:00
13 changed files with 332 additions and 104 deletions

View File

@@ -10,4 +10,4 @@ tasks:
cmd: ssh -i {{.KEY}} root@{{.IP}}
vars:
KEY: { sh: ansible-vault view vault.yml | yq -r ".secret.private_ssh_key_path" }
IP: { sh: cat dist/terraform_outputs.yml | jq -r ".server_ip.value" }
IP: { sh: cat dist/terraform_outputs.yml | jq -r ".proxy_ip.value" }

139
playbooks/deploy.yml Normal file
View File

@@ -0,0 +1,139 @@
- name: Set up real host.
gather_facts: false
hosts: localhost
tags:
- deploy
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
- ../variables.yml
tasks:
- name: Add remote host.
ansible.builtin.add_host:
name: server
ansible_ssh_host: "{{ variables.proxy_host }}"
- name: Set-up NAT.
gather_facts: false
hosts: server
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Install PIP.
ansible.builtin.apt:
name:
- python3-pip
- ifupdown
state: present
update_cache: true
- name: Install needed packages.
ansible.builtin.pip:
name:
- botocore
- boto3
- packaging
state: present
break_system_packages: true
- name: Set-up the network interfaces.
ansible.builtin.blockinfile:
dest: /etc/network/interfaces
marker: "# NAT CONFIG {marker}"
content: |
auto eth0
iface eth0 inet dhcp
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '{{ network_cidr.value }}' -o eth0 -j MASQUERADE
- name: Install Docker.
gather_facts: true
hosts: server
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Download Docker repository key.
ansible.builtin.apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
- name: Download Docker repository.
ansible.builtin.apt_repository:
repo: "deb https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
state: present
- name: Remove bad packages.
ansible.builtin.apt:
state: absent
package:
- docker.io
- docker-doc
- docker-compose
- podman-docker
- containerd
- runc
- name: Download Docker dependencies.
ansible.builtin.apt:
state: present
package:
- ca-certificates
- curl
- name: Download Docker packages.
ansible.builtin.apt:
state: present
update_cache: true
package:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
- name: Set-up reverse proxy.
gather_facts: false
hosts: server
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Set-up folders.
ansible.builtin.file:
path: "{{ item }}"
state: directory
recurse: true
loop: [/root/data, /root/letsencrypt]
- name: Set-up manager.
community.docker.docker_container:
name: proxy-manager
image: 'jc21/nginx-proxy-manager:latest'
state: started
restart_policy: unless-stopped
ports: ['80:80', '443:443', '81:81']
labels: { docker-volume-backup.stop-during-backup: "true" }
volumes:
- /root/data:/data
- /root/letsencrypt:/etc/letsencrypt
- name: Run backup.
community.docker.docker_container:
name: proxy-backup
image: offen/docker-volume-backup:v2
state: started
restart_policy: unless-stopped
volumes:
- /root/data:/backup/data:ro
- /root/letsencrypt:/backup/letsencrypt:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
env:
AWS_S3_BUCKET_NAME: "{{ secret.bucket.name }}"
AWS_S3_PATH: "{{ secret.bucket.key }}"
AWS_REGION: "{{ secret.bucket.region }}"
AWS_ACCESS_KEY_ID: "{{ secret.bucket.access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ secret.bucket.secret_key }}"
AWS_ENDPOINT: "{{ secret.bucket.endpoint }}"
BACKUP_CRON_EXPRESSION: "0 0 * * *"

View File

@@ -1,30 +0,0 @@
- name: Deploy artifact to instance.
hosts: localhost
vars_files:
- ../config/proxy.json
- ../secrets/infrastructure.secret.json
vars:
ansible_connection: aws_ssm
ansible_python_interpreter: /usr/bin/python3
ansible_aws_ssm_plugin: "{{ ssm_plugin }}"
ansible_aws_ssm_bucket_name: "{{ image_bucket }}"
ansible_aws_ssm_instance_id: "{{ public_instance_id.value }}"
ansible_aws_ssm_region: "{{ aws_region }}"
ansible_aws_ssm_access_key_id: "{{ aws_access_key }}"
ansible_aws_ssm_secret_access_key: "{{ aws_secret_key }}"
tasks:
- name: Run image.
community.docker.docker_container:
name: server
image: "jc21/nginx-proxy-manager:latest"
state: started
recreate: true
restart_policy: always
ports: ["80:80", "443:443", "81:81", "22:22"]
env:
INITIAL_ADMIN_EMAIL: "{{ email }}"
INITIAL_ADMIN_PASSWORD: "{{ password }}"
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt

View File

@@ -9,7 +9,8 @@
project_path: '../terraform'
state: "planned"
plan_file: plan.out
# init_reconfigure: true
init_reconfigure: true
force_init: true
backend_config: "{{ terraform.backend }}"
variables: "{{ terraform.variables }}"
complex_vars: true
@@ -36,3 +37,23 @@
content: "{{ terraform_apply.outputs }}"
dest: ../dist/terraform_outputs.yml
mode: '0755'
- name: Update SSH config.
hosts: localhost
gather_facts: false
tags: hosts
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
- ../variables.yml
tasks:
- name: Add proxy host.
community.general.ssh_config:
host: "{{ variables.proxy_host }}"
hostname: "{{ proxy_ip.value }}"
remote_user: root
forward_agent: true
user: user
port: 22
identity_file: "{{ secret.private_ssh_key_path }}"

View File

@@ -2,8 +2,10 @@ ansible==11.1.0
ansible-compat==24.10.0
ansible-core==2.18.1
ansible-lint==24.12.2
argcomplete==3.6.2
attrs==24.3.0
awscli-local==0.22.0
bcrypt==5.0.0
black==24.10.0
boto3==1.35.95
botocore==1.35.95
@@ -17,6 +19,7 @@ filelock==3.16.1
go-task-bin==3.44.1
idna==3.10
importlib_metadata==8.5.0
invoke==2.2.1
Jinja2==3.1.5
jmespath==1.0.1
jsonschema==4.23.0
@@ -25,9 +28,11 @@ localstack-client==2.7
MarkupSafe==3.0.2
mypy-extensions==1.0.0
packaging==24.2
paramiko==4.0.0
pathspec==0.12.1
platformdirs==4.3.6
pycparser==2.22
PyNaCl==1.6.0
python-dateutil==2.9.0.post0
PyYAML==6.0.2
referencing==0.35.1
@@ -38,7 +43,10 @@ ruamel.yaml==0.18.10
s3transfer==0.10.4
six==1.17.0
subprocess-tee==0.4.2
tomlkit==0.13.3
urllib3==2.3.0
wcmatch==10.0
xmltodict==1.0.2
yamllint==1.35.1
yq==3.4.3
zipp==3.21.0

View File

@@ -2,45 +2,45 @@
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "6.12.0"
version = "6.16.0"
hashes = [
"h1:8u90EMle+I3Auh4f/LPP6fEfRsAF6xCFnUZF4b7ngEs=",
"zh:054bcbf13c6ac9ddd2247876f82f9b56493e2f71d8c88baeec142386a395165d",
"zh:195489f16ad5621db2cec80be997d33060462a3b8d442c890bef3eceba34fa4d",
"zh:3461ef14904ab7de246296e44d24c042f3190e6bead3d7ce1d9fda63dcb0f047",
"zh:44517a0035996431e4127f45db5a84f53ce80730eae35629eda3101709df1e5c",
"zh:4b0374abaa6b9a9debed563380cc944873e4f30771dd1da7b9e812a49bf485e3",
"zh:531468b99465bd98a89a4ce2f1a30168dfadf6edb57f7836df8a977a2c4f9804",
"zh:6a95ed7b4852174aa748d3412bff3d45e4d7420d12659f981c3d9f4a1a59a35f",
"zh:88c2d21af1e64eed4a13dbb85590c66a519f3ecc54b72875d4bb6326f3ef84e7",
"h1:eBjQq1U3AZ+mkEgE6cC8z6Qw4DIV23tNmM8tCcuqXuk=",
"zh:11b5c11fc47aa7537d3acfb3156c9206ce465c2c0db4478914d1ba9493a27f38",
"zh:1de5c4ef8096ab6a4fe8e528c5a1d772a57de74ef4de98996071987d0d6a7696",
"zh:1eaaaa02503e34e57494831ea32b3327482857b01011b40753ec37c502719ee0",
"zh:367159ac72b344802e72631505894b1e7c04211f59d17c137cc9528acfb3b940",
"zh:449bb91e861d16ce80aabe148b40fa20ee4250c934cf467f6c21cf2206be1b5f",
"zh:45b4757e15a9887bf1d6dce07cbbbff365399759bb920456cf30cae47f0b0170",
"zh:4d2824050f8f2d3916a3363e0eeeab6c2c5a0912323029c4c7dc6e93ff3cfbc1",
"zh:6f363f811d20d7bd3e558d6da2cff0506c78ccea5956f919e531b22fdc7300c8",
"zh:7ab0990fc172a1343e4af6d7540be43adba989ee1b422b9d54c3369247155cea",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:a8b648470bb5df098e56b1ec5c6a39e0bbb7b496b23a19ea9f494bf48d4a122a",
"zh:b23fb13efdb527677db546bc92aeb2bdf64ff3f480188841f2bfdfa7d3d907c1",
"zh:be5858a1951ae5f5a9c388949c3e3c66a3375f684fb79b06b1d1db7a9703b18e",
"zh:c368e03a7c922493daf4c7348faafc45f455225815ef218b5491c46cea5f76b7",
"zh:e31e75d5d19b8ac08aa01be7e78207966e1faa3b82ed9fe3acfdc2d806be924c",
"zh:ea84182343b5fd9252a6fae41e844eed4fdc3311473a753b09f06e49ec0e7853",
"zh:9eaae66cc57aa07a392eb9cb3fc115a5f446ffe9f51a7f45ffaefc7a64c17b31",
"zh:aee7dbba84823ed9ca93afb0579c78605588f9355e23ec1aafa22ac4a77c45c3",
"zh:be18792d2a52bbc06e6d21dc69c7ec7134e7aaf9e8bca5fd48d2edc8c1f9085e",
"zh:d2fb28162a6ed080fefe1d16b20be86652568e930aa777f186ecfcac66af6c43",
"zh:e1ffb80f46b64c26742417abe454af9c0d3920a8636698574c0a558e66cad535",
]
}
provider "registry.terraform.io/hetznercloud/hcloud" {
version = "1.52.0"
version = "1.54.0"
constraints = "~> 1.45"
hashes = [
"h1:LTjrLuC+4F1Kv4TxS9e7LVVkG8/S4QQ7X4ORblvKTbc=",
"zh:1e9bb6b6a2ea5f441638dbae2d60fbe04ff455f58a18c740b8b7913e2197d875",
"zh:29c122e404ba331cfbadacc7f1294de5a31c9dfd60bdfe3e1b402271fc8e419c",
"zh:2bd0ae2f0bb9f16b7753f59a08e57ac7230f9c471278d7882f81406b9426c8c7",
"zh:4383206971873f6b5d81580a9a36e0158924f5816ebb6206b0cf2430e4e6a609",
"zh:47e2ca1cfa18500e4952ab51dc357a0450d00a92da9ea03e452f1f3efe6bbf75",
"zh:8e9fe90e3cea29bb7892b64da737642fc22b0106402df76c228a3cbe99663278",
"zh:a2d69350a69c471ddb63bcc74e105e585319a0fc0f4d1b7f70569f6d2ece5824",
"zh:a97abcc254e21c294e2d6b0fc9068acfd63614b097dda365f1c56ea8b0fd5f6b",
"zh:aba8d72d4fe2e89c922d5446d329e5c23d00b28227b4666e6486ba18ea2ec278",
"zh:ad36c333978c2d9e4bc43dcadcbff42fe771a8c5ef53d028bcacec8287bf78a7",
"zh:cdb1e6903b9d2f0ad8845d4eb390fbe724ee2435fb045baeab38d4319e637682",
"zh:df77b08757f3f36b8aadb33d73362320174047044414325c56a87983f48b5186",
"zh:e07513d5ad387247092b5ae1c87e21a387fc51873b3f38eee616187e38b090a7",
"zh:e2be02bdc59343ff4b9e26c3b93db7680aaf3e6ed13c8c4c4b144c74c2689915",
"h1:EhA+n+6dzWKlBxyRabPUArCKseyCfAYlYFBB7Yt3TvI=",
"zh:1b55c18929e6667fece7b6b462b9b298a09660e0d5173ef22fda780187e739c3",
"zh:1fbf44f714a213ca42e131d2cc257791701b1b788061fc720e7293f7853eb874",
"zh:2392d902158dfa6a8ac4dc1f0435662bb2e2cc788464d71bcc66c6326ff2c390",
"zh:2d5977b3ae947b341db17a0ff71ac9b6b9aa7ff4f1e84bf7cc1e428ccc42b77a",
"zh:31c3a9ef4ffc4bd270f0418099a2027a13b3a48f5c585acb04363f89285fd348",
"zh:34d3a40752fa9f18fac0c9b52ea65b363e3ca3dec040d36c461408d4a54548ee",
"zh:61028bbd9f7787b89fc71304765089831e3ba8f9fcde130ab2b79c7f50fa0736",
"zh:68fe4c68e3835aa096ba11e22eec73fbc05dc4dbc01e7e3fbccf9c4b9b78519c",
"zh:6a32dba16b3bda886682675ff4a1409ceaaff1dcaad35a2d063371d32490be54",
"zh:7754f879a0026f4d2372885f89e4960a74f42e11c914d1ee4e8156c076549cd5",
"zh:8f7d5bde3ec240fb8e7d33f26a4ab46ca26272ea494ce7ea3800f0928bc82b36",
"zh:aa4dd2e088be83be04ba9b8a839f45fed84e154c681599a4fa83ec09d9940f94",
"zh:bf931451103f9739c888bd980f9d7bdb3172f9247df41efb738667c4cef73840",
"zh:f3873dcaeb70ab58aaa63d79dfbc19e2ec82607291912253f8cb76f46a074e66",
]
}

View File

@@ -10,6 +10,12 @@ resource "hcloud_network_subnet" "subnet" {
ip_range = local.subnet_cidr
}
resource "hcloud_network_route" "privNet" {
network_id = hcloud_network.network.id
destination = "0.0.0.0/0"
gateway = local.proxy_ip
}
/* -------------------------------------------------------------------------- */
resource "hcloud_primary_ip" "public_ip" {
@@ -44,7 +50,10 @@ resource "hcloud_server" "server_instance" {
alias_ips = [ ]
}
depends_on = [ hcloud_network_subnet.subnet ]
depends_on = [
hcloud_network_subnet.subnet,
hcloud_primary_ip.public_ip
]
}
resource "hcloud_firewall" "server_firewall" {
@@ -72,12 +81,16 @@ resource "hcloud_firewall" "server_firewall" {
source_ips = [local.network_cidr]
}
# Poke holes for SSH.
rule {
direction = "in"
protocol = "tcp"
port = "22"
source_ips = ["0.0.0.0/0", "::/0"]
# Poke holes for applications, and SSH.
dynamic "rule" {
for_each = ["80", "443", "22", "81"]
content {
direction = "in"
protocol = "tcp"
port = rule.value
source_ips = ["0.0.0.0/0", "::/0"]
}
}
}

View File

@@ -3,3 +3,9 @@ output "proxy_ip" {
value = hcloud_server.server_instance.ipv4_address
sensitive = false
}
output "network_cidr" {
description = "The CIDR of the private network."
value = local.network_cidr
sensitive = false
}

View File

@@ -16,3 +16,9 @@ terraform {
provider "hcloud" {
token = var.hcloud_token
}
provider "aws" {
region = var.aws_region
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}

14
terraform/routing.tf Normal file
View File

@@ -0,0 +1,14 @@
# The Route53 DNS zone.
data "aws_route53_zone" "main" {
name = local.domain
}
# Push all domain traffic through the reverse proxy.
resource "aws_route53_record" "domain" {
zone_id = data.aws_route53_zone.main.zone_id
name = "*.${data.aws_route53_zone.main.name}"
type = "A"
ttl = "60"
records = [hcloud_primary_ip.public_ip.ip_address]
}

View File

@@ -4,11 +4,10 @@ locals {
server_image = "debian-12"
domain = "maximhutz.com"
subdomain = "git"
network_cidr = "10.0.0.0/16"
subnet_cidr = "10.0.0.0/24"
proxy_ip = "10.0.0.1"
network_cidr = "10.10.0.0/16"
subnet_cidr = "10.10.0.0/24"
proxy_ip = "10.10.0.10"
}
# ---------------------------------------------------------------------------- #
@@ -23,3 +22,21 @@ variable "public_ssh_key_path" {
description = "The location of the public key used to access the repository Gitea server."
type = string
}
variable "aws_region" {
description = "The region of the AWS account."
type = string
sensitive = true
}
variable "aws_access_key" {
description = "The access key of the account."
type = string
sensitive = true
}
variable "aws_secret_key" {
description = "The secret key of the account."
type = string
sensitive = true
}

2
variables.yml Normal file
View File

@@ -0,0 +1,2 @@
variables:
proxy_host: proxy

View File

@@ -1,30 +1,62 @@
$ANSIBLE_VAULT;1.1;AES256
38333261303366343839373165613636393661343736353965626337393536393262626464616539
3631326530663433363636393566346234323765393334300a613539383066636433373639613835
63633761323963303933356562666133323538333330613838333938656536376165356630313134
3631343432323363620a353865303632313333306666643265386237366139653066663434303630
30396330616163313962393532353430396533353738346165346361643838623164383663336232
37636565616333636432333139326239306235363236353130623364656239363532303163356533
63656336303466336532656366313133633765373131323436343862653338336230363162353666
62353163396666396366666531343033636464626264613761333930666636343564383261373530
66666661666266636562383264383337366561343639376638396133303132613463323561343738
38626133386634653566393065333161313766376237373335663565326635393639363865396230
34646634666161613239656363643635666136386532643663656133363162313963626166616162
39393138313333383232346535396565303437363034383261313433636562373061333839343564
39353165643234366338393262653363303264313764636535393633623532323764313839623933
33303031646164313937353837393638303433666437373733336232653231663562646130373936
64343331316366376561623366353565376534336338656165653133646134623961663835626239
66323331623138363231363435356265353462623334333963613962356261313965363531653832
38363130373066313264326636346332343632613834666361646631316533666239313637313635
32316664653339653430386233626561346262306433363261336230353937353531346237643164
64656333653230643961666361376161373231623863316534373431326630623730643931313730
39376539626237616139393463373266393033396631646235333031303338616138623538323633
30386566336234643664613866343666636164633962376432666266326237626363346664306535
37303435613634353538373730303861356338363063383136313366343233626233363561636231
36653762366132623136323539393631326532343636353762633332653461376231653166333636
64373065386365316363376362363732353361386338613632633733386234363632656632346535
32356362636139636635616166383237316538306166343261636363303638396362383232373064
35346661626336623364336536346139386335373235623561613063353961383830383437336161
31613234636635303164396166333562396630393761333761653132306438326163313534313734
32393966333336363435666330646532383430303933313161333733376264633464373466363265
6137
33396339353933616166653538396231653965383432663433313161393539383937303635393565
6262633463303635663231313032613236326336316233380a373536633834303438313236366438
61313430323738393534343262653064663437663734393633643062363064366639393565353764
3930323766656531630a666362306538323930656330386261633264636130386134643965616534
32633036323661336238633464316637643138623766333832666331363831316235616161656231
34663333326531306232326136383033393664373130353135396633346462353865316461616334
66633237366163303936653137323939363464383065373566613163656635333636653339306237
35356163623537376637386262633163623538613261323566656566323938336264313636383936
66323839343336666638303830396163306666633461343934356333643230326433363761636231
65343436353463396536636663366362653065353163303636306164366638353964363930333562
30323661323935643065653062393265386536656134356632323764656634316562363734323165
35656465343763336636626461343436366363306530653434303637623737613034626362303931
31303736623361616363643661646335383039356531626239353830646566333135653264303239
64303163666166386336646434333237653433656565353032616634313261336535633365373961
38633936363266303264663033376662383632616362363939326565656535386231316237623761
32613830383036626534623631313961323534303931356637326461633739623430353734373530
35376663326130393534373735653562373234396437653238323630333733313365636330393835
32613230303035656530346238623034336236356630653236353362633131663237386330303933
30376465646261663065663737613639393361633466316538656166396432663432656430653438
66396439323339646662306436643062346339373463343031643563366531356432336562333537
31326337613739343333326136336439306563333433613736383762656332313632346335613836
39396330373030373661373565373361626333333631386433316566646661376263633866303530
63626462366437383539666434313866373838333863633934313235363265626132646535303638
39343966613234326661313539386232646230363961353537613931633839303635623866316534
61623639613336633037343135663363343664633233656466326132363262336235316237333561
38613038386439363865636665333939346662383235393662303335633866633664386264386432
30303636346533633234313833303339633134393131396232633734626130393137363361393764
65366234626532633066656131653439333639353162363931393035343462646261383238636230
38363330313137366234306334353264343232333035646236616537313136313332363966653435
33663538393064373430383030653331623039363635643138363333373532656432326338346336
65626363616430636464316334303664353633363364313136636665323263373461663339323166
30636438626265316433363861363763623263303533656632373961333966613561373436303361
66323732353230343238353438386563393264333265363864383861366233393830623863376664
65353930303338323533326337616636323433646235346161613437643964396231656231623935
34663365343131373434343766366132656534343732623639663138663863383337303830636638
64323537656165363061346265636266333838633163663963643564616234373930366632373762
65393936383538643331366232333637353133326266383933393561383539393562353366366435
31356163386633623039373830336432356361663632356233653865656531663162383135333533
64306331376461393566353433633238316637366538613635383862656262663461303335663831
63623839373462336531316462373138323136383463666561383661633761613832623633663664
65663232666537663433653662613363623336346161363832643662373666383436396634616462
35656230383739326537323737636266303563653232623634643036613765646335303137303733
65616339333366653835383331643332376635613837663763616235663838663762386130663732
39376433303633383463623139366237666230333137383838343432626130386161653936353662
63323661376538356339626431333036633538633065643665323832303431393166383163633737
36323464616138616633326464633238303861643235303431336137666432313261616536663039
61306231663661396265333438376164333561616661386538313462366466623537393263643464
32326439343863613464313365613630383133353262343732323339616664383261343364643566
65363234383062356131343439383266343733656661653063366139303766356264626262613532
32633135626633656166376639303738303435643662313439663330643530393965663363616166
38653438306361623134666631653230306136336438366662303264666531633539343635393130
37346539363533386465623936326232613062633336633262353235303762623530653333623639
62376131646164343339656636353332303263636531626230313766636661636233366136316638
35383436636266636237333231613930366466346432356134613232306163653839346637356562
62633931303432616436396131666434333238363563353465323236336162643339376434393736
36663735313866616633666638363832656234363835383961323561313662643438316666646535
37626266353932373063633963616431666535306531393037616431653061323436316636653962
30393537363232666634343663346435616362663731653834613831303531376566303038376436
38303934633233396361623534356631383536363461356137323865373434363437653330383538
38646161613439346232326434646136663861383963336363643931303830613237353363306663
6133