5 Commits

Author SHA1 Message Date
79b37f17e2 feat: deployment for runner 2025-10-08 20:11:49 -04:00
7f36507dce feat: ansible proxy jump 2025-10-07 22:39:58 -04:00
767fd3b503 feat: provisioned resources 2025-10-07 21:48:56 -04:00
5f2b51ef09 feat: runner terraform 2025-10-01 23:06:29 -04:00
909fd105e7 chore: removed unused install.sh file 2025-10-01 22:39:22 -04:00
19 changed files with 300 additions and 403 deletions

View File

@@ -8,10 +8,9 @@ tasks:
vault: ansible-vault edit vault.yml {{.CLI_ARGS}} vault: ansible-vault edit vault.yml {{.CLI_ARGS}}
provision: ansible-playbook playbooks/provision.yml {{.CLI_ARGS}} provision: ansible-playbook playbooks/provision.yml {{.CLI_ARGS}}
deploy: ansible-playbook playbooks/deploy.yml {{.CLI_ARGS}} deploy:gitea: ansible-playbook playbooks/deploy.yml {{.CLI_ARGS}}
destroy: ansible-playbook playbooks/destroy.yml {{.CLI_ARGS}} deploy:runner: ansible-playbook playbooks/runner.yml {{.CLI_ARGS}}
restore: ansible-playbook playbooks/restore.yml {{.CLI_ARGS}} restore: ansible-playbook playbooks/restore.yml {{.CLI_ARGS}}
runner: ansible-playbook playbooks/runner.yml {{.CLI_ARGS}}
assets: assets:
- cp ./assets/icon.png ./gitea/custom/public/assets/img/logo.png - cp ./assets/icon.png ./gitea/custom/public/assets/img/logo.png
@@ -20,16 +19,13 @@ tasks:
- cp ./assets/logo.svg ./gitea/custom/public/assets/img/favicon.svg - cp ./assets/logo.svg ./gitea/custom/public/assets/img/favicon.svg
- cp ./assets/logo.png ./gitea/custom/public/assets/img/apple-touch-icon.png - cp ./assets/logo.png ./gitea/custom/public/assets/img/apple-touch-icon.png
enter:gitea:
enter: cmd: ssh {{.GITEA}}
cmd: ssh -i {{.KEY}} -p 2222 root@{{.IP}}
vars: vars:
KEY: { sh: ansible-vault view vault.yml | yq -r ".secret.private_ssh_key_path" } GITEA: { sh: cat ./variables.yml | yq -r ".variables.gitea_host" }
IP: { sh: cat dist/terraform_outputs.yml | jq -r ".server_ip.value" }
enter-runner: enter:runner:
cmd: ssh -i {{.KEY}} -o ProxyCommand="ssh -i {{.KEY}} -p 2222 -W %h:%p root@{{.IP}}" root@{{.RUNNER_IP}} cmd: ssh -J {{.GITEA}} {{.RUNNER}}
vars: vars:
KEY: { sh: ansible-vault view vault.yml | yq -r ".secret.private_ssh_key_path" } GITEA: { sh: cat ./variables.yml | yq -r ".variables.gitea_host" }
IP: { sh: cat dist/terraform_outputs.yml | jq -r ".server_ip.value" } RUNNER: { sh: cat ./variables.yml | yq -r ".variables.runner_host" }
RUNNER_IP: { sh: cat dist/terraform_outputs.yml | jq -r ".runner_ip.value" }

View File

@@ -3,8 +3,6 @@ callbacks_enabled = profile_tasks
localhost_warning = False localhost_warning = False
vault_password_file = vault.key vault_password_file = vault.key
interpreter_python = /usr/bin/python3.11 interpreter_python = /usr/bin/python3.11
editor = code --wait
remote_tmp = /tmp/.ansible/tmp
[inventory] [inventory]
inventory_unparsed_warning = False inventory_unparsed_warning = False

View File

@@ -91,9 +91,6 @@ DEFAULT_MERGE_STYLE = merge
[repository.signing] [repository.signing]
DEFAULT_TRUST_MODEL = committer DEFAULT_TRUST_MODEL = committer
[actions]
ENABLED = true
[storage] [storage]
STORAGE_TYPE = minio STORAGE_TYPE = minio
MINIO_USE_SSL = true MINIO_USE_SSL = true

View File

@@ -96,9 +96,6 @@ DEFAULT_TRUST_MODEL = committer
[oauth2] [oauth2]
JWT_SECRET = x-----------------------------------------x JWT_SECRET = x-----------------------------------------x
[actions]
ENABLED = true
[storage] [storage]
STORAGE_TYPE = minio STORAGE_TYPE = minio
MINIO_ENDPOINT = localstack:4566 MINIO_ENDPOINT = localstack:4566

View File

@@ -11,7 +11,7 @@
ansible_ssh_host: "{{ server_ip.value }}" ansible_ssh_host: "{{ server_ip.value }}"
ansible_user: root ansible_user: root
ansible_port: 22 ansible_port: 22
ansible_private_key_file: "{{ secret.private_ssh_key_path }}" ansible_private_key_file: "{{ secret.private_gitea_ssh_key_path }}"
- name: Switch port to 2222. - name: Switch port to 2222.
hosts: server_fresh hosts: server_fresh
@@ -41,10 +41,7 @@
- name: Add remote host. - name: Add remote host.
ansible.builtin.add_host: ansible.builtin.add_host:
name: server name: server
ansible_ssh_host: "{{ server_ip.value }}" ansible_ssh_host: "{{ variables.gitea_host }}"
ansible_user: root
ansible_port: 2222
ansible_private_key_file: "{{ secret.private_ssh_key_path }}"
- name: Install Docker. - name: Install Docker.
gather_facts: true gather_facts: true
@@ -55,10 +52,10 @@
tasks: tasks:
- name: Install PIP. - name: Install PIP.
ansible.builtin.apt: ansible.builtin.apt:
state: present
update_cache: true
name: name:
- python3-pip - python3-pip
state: present
update_cache: true
- name: Install needed packages. - name: Install needed packages.
ansible.builtin.pip: ansible.builtin.pip:
@@ -108,41 +105,6 @@
- docker-buildx-plugin - docker-buildx-plugin
- docker-compose-plugin - docker-compose-plugin
- name: Enable NAT for private network.
hosts: server
gather_facts: false
tasks:
- name: Enable IP forwarding.
ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: "1"
sysctl_set: true
reload: true
- name: Add NAT masquerade rule.
ansible.builtin.iptables:
table: nat
chain: POSTROUTING
source: "10.0.1.0/24"
jump: MASQUERADE
state: present
- name: Allow forwarding from private network.
ansible.builtin.iptables:
chain: DOCKER-USER
source: "10.0.1.0/24"
jump: ACCEPT
action: insert
state: present
- name: Allow established/related return traffic.
ansible.builtin.iptables:
chain: DOCKER-USER
ctstate: ESTABLISHED,RELATED
jump: ACCEPT
action: insert
state: present
- name: Deploy artifact to instance. - name: Deploy artifact to instance.
hosts: server hosts: server
tags: tags:
@@ -171,7 +133,7 @@
ansible.builtin.file: ansible.builtin.file:
path: /root/data path: /root/data
state: directory state: directory
mode: "0777" mode: '0777'
- name: Run image. - name: Run image.
community.docker.docker_container: community.docker.docker_container:

View File

@@ -1,15 +0,0 @@
- name: Destroy terraform infrastructure.
hosts: localhost
gather_facts: false
vars_files:
- ../vault.yml
tasks:
- name: Destroy Terraform.
community.general.terraform:
project_path: "../terraform"
state: "absent"
init_reconfigure: true
force_init: true
backend_config: "{{ terraform.backend }}"
variables: "{{ terraform.variables }}"
complex_vars: true

View File

@@ -6,18 +6,17 @@
tasks: tasks:
- name: Reconfigure and plan. - name: Reconfigure and plan.
community.general.terraform: community.general.terraform:
project_path: "../terraform" project_path: '../terraform'
state: "planned" state: "planned"
plan_file: plan.out plan_file: plan.out
init_reconfigure: true # init_reconfigure: true
force_init: true
backend_config: "{{ terraform.backend }}" backend_config: "{{ terraform.backend }}"
variables: "{{ terraform.variables }}" variables: "{{ terraform.variables }}"
complex_vars: true complex_vars: true
- name: Apply. - name: Apply.
community.general.terraform: community.general.terraform:
project_path: "../terraform" project_path: '../terraform'
state: "present" state: "present"
plan_file: plan.out plan_file: plan.out
backend_config: "{{ terraform.backend }}" backend_config: "{{ terraform.backend }}"
@@ -36,4 +35,32 @@
ansible.builtin.copy: ansible.builtin.copy:
content: "{{ terraform_apply.outputs }}" content: "{{ terraform_apply.outputs }}"
dest: ../dist/terraform_outputs.yml dest: ../dist/terraform_outputs.yml
mode: "0755" 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 Gitea host.
community.general.ssh_config:
host: "{{ variables.gitea_host }}"
hostname: "{{ server_ip.value }}"
remote_user: root
forward_agent: true
user: user
port: 2222
identity_file: "{{ secret.private_gitea_ssh_key_path }}"
- name: Add Runner host.
community.general.ssh_config:
host: "{{ variables.runner_host }}"
remote_user: root
user: user
identity_file: "{{ secret.private_runner_ssh_key_path }}"
proxyjump: "{{ variables.gitea_host }}"
hostname: 10.0.10.17

View File

@@ -8,10 +8,7 @@
- name: Add remote host. - name: Add remote host.
ansible.builtin.add_host: ansible.builtin.add_host:
name: server name: server
ansible_ssh_host: "{{ server_ip.value }}" ansible_ssh_host: "{{ variables.gitea_host }}"
ansible_user: root
ansible_port: 2222
ansible_private_key_file: "{{ secret.private_ssh_key_path }}"
- name: Deploy artifact to instance. - name: Deploy artifact to instance.
hosts: server hosts: server
@@ -33,17 +30,17 @@
object: "{{ secret.restore.key | mandatory(msg='You must specify the key of the data.') }}" object: "{{ secret.restore.key | mandatory(msg='You must specify the key of the data.') }}"
dest: /root/snapshot.tar.gz dest: /root/snapshot.tar.gz
mode: get mode: get
endpoint_url: "{{ secret.restore.endpoint }}"
region: "{{ secret.restore.region }}" region: "{{ secret.restore.region }}"
access_key: "{{ secret.restore.access_key }}" access_key: "{{ secret.restore.access_key }}"
secret_key: "{{ secret.restore.secret_key }}" secret_key: "{{ secret.restore.secret_key }}"
endpoint_url: "{{ secret.restore.endpoint | mandatory(msg='You must specify the S3 URL.') }}"
ignore_nonexistent_bucket: true ignore_nonexistent_bucket: true
- name: Ensure backup directory exists. - name: Ensure backup directory exists.
ansible.builtin.file: ansible.builtin.file:
path: /root/restore path: /root/restore
state: directory state: directory
mode: "0777" mode: '0777'
- name: Extract backup. - name: Extract backup.
ansible.builtin.unarchive: ansible.builtin.unarchive:
@@ -56,13 +53,13 @@
remote_src: true remote_src: true
src: /root/restore/backup/my-app-backup/ src: /root/restore/backup/my-app-backup/
dest: /root/data/ dest: /root/data/
mode: "0777" mode: '0777'
- name: Update permissions. - name: Update permissions.
ansible.builtin.file: ansible.builtin.file:
path: /root/data path: /root/data
recurse: true recurse: true
mode: "0777" mode: '0777'
owner: 1000 owner: 1000
group: 1000 group: 1000

View File

@@ -1,50 +1,40 @@
- name: Set up runner host via jumphost. - name: Set up for fresh host.
gather_facts: false gather_facts: false
hosts: localhost hosts: localhost
vars_files: vars_files:
- ../vault.yml - ../vault.yml
- ../dist/terraform_outputs.yml - ../variables.yml
tasks: tasks:
- name: Add gitea server as jumphost. - name: Add runner host.
ansible.builtin.add_host:
name: server
ansible_ssh_host: "{{ server_ip.value }}"
ansible_user: root
ansible_port: 2222
ansible_private_key_file: "{{ secret.private_ssh_key_path }}"
- name: Add runner host (via jumphost).
ansible.builtin.add_host: ansible.builtin.add_host:
name: runner name: runner
ansible_ssh_host: "{{ runner_ip.value }}" ansible_ssh_host: "{{ variables.runner_host }}"
ansible_user: root ansible_ssh_extra_args: "-J {{ variables.gitea_host }}"
ansible_private_key_file: "{{ secret.private_ssh_key_path }}"
ansible_ssh_common_args: >-
-o ProxyCommand="ssh -i {{ secret.private_ssh_key_path }} -p 2222 -W %h:%p root@{{ server_ip.value }}"
- name: Install Docker on runner. - name: Add Gitea host.
ansible.builtin.add_host:
name: gitea
ansible_ssh_host: "{{ variables.gitea_host }}"
- name: Install Docker.
gather_facts: true gather_facts: true
hosts: runner hosts: runner
vars_files: vars_files:
- ../vault.yml - ../vault.yml
- ../dist/terraform_outputs.yml - ../dist/terraform_outputs.yml
tasks: tasks:
- name: Set DNS resolver.
ansible.builtin.copy:
content: "nameserver 185.12.64.2\n"
dest: /etc/resolv.conf
mode: "0644"
- name: Install PIP. - name: Install PIP.
ansible.builtin.apt: ansible.builtin.apt:
state: present
update_cache: true
name: name:
- python3-pip - python3-pip
state: present
update_cache: true
- name: Install needed packages. - name: Install needed packages.
ansible.builtin.pip: ansible.builtin.pip:
name: name:
- botocore
- boto3
- packaging - packaging
state: present state: present
break_system_packages: true break_system_packages: true
@@ -76,7 +66,6 @@
package: package:
- ca-certificates - ca-certificates
- curl - curl
- jq
- name: Download Docker packages. - name: Download Docker packages.
ansible.builtin.apt: ansible.builtin.apt:
@@ -89,90 +78,36 @@
- docker-buildx-plugin - docker-buildx-plugin
- docker-compose-plugin - docker-compose-plugin
- name: Configure swap on runner. - name: Get registration token for Runner.
hosts: runner hosts: gitea
gather_facts: false gather_facts: false
tasks: tasks:
- name: Create swapfile. - name: Get registration token.
ansible.builtin.command: community.docker.docker_container_exec:
cmd: fallocate -l 2G /swapfile container: server
creates: /swapfile command: gitea actions grt
register: output
- name: Set swapfile permissions. - name: Set fact.
ansible.builtin.file: ansible.builtin.set_fact:
path: /swapfile registration_token: "{{ output.stdout }}"
mode: "0600" delegate_to: localhost
delegate_facts: true
- name: Check if swap is active. - name: Deploy Runner.
ansible.builtin.command:
cmd: swapon --show=NAME --noheadings
register: swap_status
changed_when: false
- name: Format swapfile.
ansible.builtin.command:
cmd: mkswap /swapfile
when: "'/swapfile' not in swap_status.stdout"
changed_when: true
- name: Enable swapfile.
ansible.builtin.command:
cmd: swapon /swapfile
when: "'/swapfile' not in swap_status.stdout"
changed_when: true
- name: Add swapfile to fstab.
ansible.posix.mount:
path: none
src: /swapfile
fstype: swap
opts: sw
state: present
- name: Register and start Gitea runner.
hosts: runner hosts: runner
gather_facts: false gather_facts: true
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
vars:
gitea_hostname: "{{ server_fqdn.value }}"
gitea_internal_url: "https://{{ gitea_hostname }}"
tasks: tasks:
- name: Create runner data volume. - name: Deploy image.
community.docker.docker_volume:
name: runner-data
state: present
- name: Generate runner config.
ansible.builtin.copy:
dest: /root/runner-config.yaml
mode: "0644"
content: |
runner:
insecure: true
capacity: 1
cache:
enabled: false
container:
options: "--add-host {{ gitea_hostname }}:10.0.1.2 --memory=1536m"
valid_volumes:
- /var/run/docker.sock
- name: Start Gitea runner container.
community.docker.docker_container: community.docker.docker_container:
name: gitea-runner name: runner
image: gitea/act_runner:latest image: docker.io/gitea/act_runner:nightly
state: started
recreate: true
restart_policy: unless-stopped
etc_hosts: "{{ {gitea_hostname: '10.0.1.2'} }}"
volumes:
- runner-data:/data
- /var/run/docker.sock:/var/run/docker.sock
- /root/runner-config.yaml:/config.yaml:ro
env: env:
GITEA_INSTANCE_URL: "{{ gitea_internal_url }}" CONFIG_FILE: /config.yaml
GITEA_RUNNER_REGISTRATION_TOKEN: "{{ secret.runner_registration_token }}" GITEA_INSTANCE_URL: git.maximhutz.com
GITEA_RUNNER_NAME: "runner-01" GITEA_RUNNER_REGISTRATION_TOKEN: "{{ hostvars['localhost']['registration_token'] }}"
CONFIG_FILE: "/config.yaml" GITEA_RUNNER_NAME: "Main Runner"
volumes:
- ./config.yaml:/config.yaml
- ./data:/data
- /var/run/docker.sock:/var/run/docker.sock

View File

@@ -2,44 +2,45 @@
# Manual edits may be lost in future updates. # Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" { provider "registry.terraform.io/hashicorp/aws" {
version = "6.27.0" version = "6.12.0"
hashes = [ hashes = [
"h1:emgTfB1LXSFYh9uAwgsRMoMIN5Wz7jNNKq3rqC0EHWk=", "h1:8u90EMle+I3Auh4f/LPP6fEfRsAF6xCFnUZF4b7ngEs=",
"zh:177a24b806c72e8484b5cabc93b2b38e3d770ae6f745a998b54d6619fd0e8129", "zh:054bcbf13c6ac9ddd2247876f82f9b56493e2f71d8c88baeec142386a395165d",
"zh:4ac4a85c14fb868a3306b542e6a56c10bd6c6d5a67bc0c9b8f6a9060cf5f3be7", "zh:195489f16ad5621db2cec80be997d33060462a3b8d442c890bef3eceba34fa4d",
"zh:552652185bc85c8ba1da1d65dea47c454728a5c6839c458b6dcd3ce71c19ccfc", "zh:3461ef14904ab7de246296e44d24c042f3190e6bead3d7ce1d9fda63dcb0f047",
"zh:60284b8172d09aee91eae0856f09855eaf040ce3a58d6933602ae17c53f8ed04", "zh:44517a0035996431e4127f45db5a84f53ce80730eae35629eda3101709df1e5c",
"zh:6be38d156756ca61fb8e7c752cc5d769cd709686700ac4b230f40a6e95b5dbc9", "zh:4b0374abaa6b9a9debed563380cc944873e4f30771dd1da7b9e812a49bf485e3",
"zh:7a409138fae4ef42e3a637e37cb9efedf96459e28a3c764fc4e855e8db9a7485", "zh:531468b99465bd98a89a4ce2f1a30168dfadf6edb57f7836df8a977a2c4f9804",
"zh:8070cf5224ed1ed3a3e9a59f7c30ff88bf071c7567165275d477c1738a56c064", "zh:6a95ed7b4852174aa748d3412bff3d45e4d7420d12659f981c3d9f4a1a59a35f",
"zh:894439ef340a9a79f69cd759e27ad11c7826adeca27be1b1ca82b3c9702fa300", "zh:88c2d21af1e64eed4a13dbb85590c66a519f3ecc54b72875d4bb6326f3ef84e7",
"zh:89d035eebf08a97c89374ff06040955ddc09f275ecca609d0c9d58d149bef5cf",
"zh:985b1145d724fc1f38369099e4a5087141885740fd6c0b1dbc492171e73c2e49",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:a80b47ae8d1475201c86bd94a5dcb9dd4da5e8b73102a90820b68b66b76d50fd", "zh:a8b648470bb5df098e56b1ec5c6a39e0bbb7b496b23a19ea9f494bf48d4a122a",
"zh:d3395be1556210f82199b9166a6b2e677cee9c4b67e96e63f6c3a98325ad7ab0", "zh:b23fb13efdb527677db546bc92aeb2bdf64ff3f480188841f2bfdfa7d3d907c1",
"zh:db0b869d09657f6f1e4110b56093c5fcdf9dbdd97c020db1e577b239c0adcbce", "zh:be5858a1951ae5f5a9c388949c3e3c66a3375f684fb79b06b1d1db7a9703b18e",
"zh:ffc72e680370ae7c21f9bd3082c6317730df805c6797427839a6b6b7e9a26a01", "zh:c368e03a7c922493daf4c7348faafc45f455225815ef218b5491c46cea5f76b7",
"zh:e31e75d5d19b8ac08aa01be7e78207966e1faa3b82ed9fe3acfdc2d806be924c",
"zh:ea84182343b5fd9252a6fae41e844eed4fdc3311473a753b09f06e49ec0e7853",
] ]
} }
provider "registry.terraform.io/hetznercloud/hcloud" { provider "registry.terraform.io/hetznercloud/hcloud" {
version = "1.57.0" version = "1.52.0"
constraints = "~> 1.45" constraints = "~> 1.45"
hashes = [ hashes = [
"h1:xpAcuja19Ts7bCpmULKdBw4dEBJhF/eL6AjM4xDBEAI=", "h1:LTjrLuC+4F1Kv4TxS9e7LVVkG8/S4QQ7X4ORblvKTbc=",
"zh:016ecc39328f34f6c0ffa413598f354824f7878c89cd031f123edb4bc8a687a2", "zh:1e9bb6b6a2ea5f441638dbae2d60fbe04ff455f58a18c740b8b7913e2197d875",
"zh:10b362dc0847200c987214b129b5f85e2f7d8ad417261a1d2dd04ab74de15603", "zh:29c122e404ba331cfbadacc7f1294de5a31c9dfd60bdfe3e1b402271fc8e419c",
"zh:194647d9a61dca4f411f44580316b88a11095d7a99679d445f9b0f2c1ba976c4", "zh:2bd0ae2f0bb9f16b7753f59a08e57ac7230f9c471278d7882f81406b9426c8c7",
"zh:1d8aafe2ce7890696385bb3a0c3286e7ee3020416d337f59935406e4c6f91de6", "zh:4383206971873f6b5d81580a9a36e0158924f5816ebb6206b0cf2430e4e6a609",
"zh:594585616210fb232fad4ebda2387ecd3f483931e00eff988fca83add6ce7cfc", "zh:47e2ca1cfa18500e4952ab51dc357a0450d00a92da9ea03e452f1f3efe6bbf75",
"zh:65e50be33ffb85580546f119839e1293591cc6d4db729d809931d0408b6ae408", "zh:8e9fe90e3cea29bb7892b64da737642fc22b0106402df76c228a3cbe99663278",
"zh:7d4ed5bd8c477ec304142e2160203a76a0d09c93d224950bda253172b2571038", "zh:a2d69350a69c471ddb63bcc74e105e585319a0fc0f4d1b7f70569f6d2ece5824",
"zh:90a70a70a266b78c8216903e711904e6969b3957d182602b5d788602ec9ef323", "zh:a97abcc254e21c294e2d6b0fc9068acfd63614b097dda365f1c56ea8b0fd5f6b",
"zh:abb8e28e96fb8de270995873de980896b7cb53cfc550f02c50eaa42884624ba9", "zh:aba8d72d4fe2e89c922d5446d329e5c23d00b28227b4666e6486ba18ea2ec278",
"zh:bbf34dca2de6e105ca7204222162a0402d8e9e9a28e1de5ffbaa2c0d6270a059", "zh:ad36c333978c2d9e4bc43dcadcbff42fe771a8c5ef53d028bcacec8287bf78a7",
"zh:c1a9edb693d632dcb5c3c9ee84c97138e08eadb9354e28592efd581f68ac0385", "zh:cdb1e6903b9d2f0ad8845d4eb390fbe724ee2435fb045baeab38d4319e637682",
"zh:dadbf1368fae314fe8dcb99ebefbc78409f3fc0e3808cd92ea573b8eee1cae98", "zh:df77b08757f3f36b8aadb33d73362320174047044414325c56a87983f48b5186",
"zh:e713e00ca27348abd18da2eeff861905e84050e3e7e008f14a0c63c70ab2ff84", "zh:e07513d5ad387247092b5ae1c87e21a387fc51873b3f38eee616187e38b090a7",
"zh:e2be02bdc59343ff4b9e26c3b93db7680aaf3e6ed13c8c4c4b144c74c2689915",
] ]
} }

View File

@@ -1,31 +0,0 @@
#!/bin/sh
## Install extras.
rpm --rebuilddb
amazon-linux-extras install docker ansible2 python3.8 -y
# Make Docker work.
systemctl enable docker
systemctl start docker
# Set up the correct version of Python (for Ansible).
ln -sf /usr/bin/python3.8 /usr/bin/python3
ln -sf /usr/bin/pip3.8 /usr/bin/pip3
pip3 install botocore boto3 requests packaging --user ssm-user
python3 -m pip install -U pip
# Add some swap space.
dd if=/dev/zero of=/swapfile bs=128M count=8
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
# Stop SSH (because we have SSM.)
service sshd stop
# Install Docker Compose.
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# ERROR: SSM User not created yet.
sudo usermod -aG docker ssm-user

View File

@@ -1,3 +1,17 @@
resource "hcloud_network" "network" {
name = "network"
ip_range = "10.0.0.0/16"
}
resource "hcloud_network_subnet" "subnet" {
type = "cloud"
network_id = hcloud_network.network.id
network_zone = "eu-central"
ip_range = "10.0.10.0/24"
}
/* -------------------------------------------------------------------------- */
resource "hcloud_primary_ip" "public_ip" { resource "hcloud_primary_ip" "public_ip" {
name = "repository-public-ip" name = "repository-public-ip"
datacenter = local.datacenter datacenter = local.datacenter
@@ -6,23 +20,31 @@ resource "hcloud_primary_ip" "public_ip" {
auto_delete = false auto_delete = false
} }
resource "hcloud_ssh_key" "ssh_key" { resource "hcloud_ssh_key" "gitea_ssh_key" {
name = "repository-ssh-key" name = "repository-ssh-key"
public_key = file(var.public_ssh_key_path) public_key = file(var.public_gitea_ssh_key_path)
} }
resource "hcloud_server" "server_instance" { resource "hcloud_server" "gitea_server_instance" {
name = "repository-server" name = "repository-gitea-server"
image = local.server_image image = local.server_image
server_type = local.server_type server_type = local.server_type
datacenter = local.datacenter datacenter = local.datacenter
ssh_keys = [hcloud_ssh_key.ssh_key.id] ssh_keys = [hcloud_ssh_key.gitea_ssh_key.id]
public_net { public_net {
ipv4_enabled = true ipv4_enabled = true
ipv4 = hcloud_primary_ip.public_ip.id ipv4 = hcloud_primary_ip.public_ip.id
ipv6_enabled = false ipv6_enabled = false
} }
network {
network_id = hcloud_network.network.id
ip = local.gitea_ip
alias_ips = [ ]
}
depends_on = [ hcloud_network_subnet.subnet ]
} }
resource "hcloud_firewall" "server_firewall" { resource "hcloud_firewall" "server_firewall" {
@@ -58,25 +80,34 @@ resource "hcloud_firewall" "server_firewall" {
resource "hcloud_firewall_attachment" "server_fw_attachment" { resource "hcloud_firewall_attachment" "server_fw_attachment" {
firewall_id = hcloud_firewall.server_firewall.id firewall_id = hcloud_firewall.server_firewall.id
server_ids = [hcloud_server.server_instance.id] server_ids = [hcloud_server.gitea_server_instance.id]
}
/* -------------------------------------------------------------------------- */
resource "hcloud_ssh_key" "runner_ssh_key" {
name = "repository-runner-ssh-key"
public_key = file(var.public_runner_ssh_key_path)
} }
resource "hcloud_server" "runner_instance" { resource "hcloud_server" "runner_instance" {
name = "runner-server" name = "repository-runner-server"
image = local.server_image image = local.server_image
server_type = local.server_type server_type = local.server_type
datacenter = local.datacenter datacenter = local.datacenter
ssh_keys = [hcloud_ssh_key.ssh_key.id] ssh_keys = [hcloud_ssh_key.runner_ssh_key.id]
network {
network_id = hcloud_network.network.id
ip = local.runner_ip
alias_ips = [ ]
}
public_net { public_net {
ipv4_enabled = false ipv4_enabled = false
ipv6_enabled = false ipv6_enabled = false
} }
network { depends_on = [ hcloud_network_subnet.subnet ]
network_id = hcloud_network.private_network.id
ip = local.runner_ip
} }
depends_on = [hcloud_network_subnet.private_subnet]
}

View File

@@ -1,24 +0,0 @@
resource "hcloud_network" "private_network" {
name = "repository-network"
ip_range = local.network_cidr
}
resource "hcloud_network_subnet" "private_subnet" {
network_id = hcloud_network.private_network.id
type = "cloud"
network_zone = local.network_zone
ip_range = local.subnet_cidr
}
resource "hcloud_server_network" "server_network" {
server_id = hcloud_server.server_instance.id
network_id = hcloud_network.private_network.id
ip = local.server_ip
}
resource "hcloud_network_route" "nat_route" {
network_id = hcloud_network.private_network.id
destination = "0.0.0.0/0"
gateway = local.server_ip
}

View File

@@ -1,6 +1,12 @@
output "server_ip" { output "server_ip" {
description = "The public address of the server." description = "The public address of the server."
value = hcloud_server.server_instance.ipv4_address value = hcloud_server.gitea_server_instance.ipv4_address
sensitive = false
}
output "runner_ip" {
description = "The internal address of the CI runner."
value = local.runner_ip
sensitive = false sensitive = false
} }
@@ -9,9 +15,3 @@ output "server_fqdn" {
value = "${local.subdomain}.${local.domain}" value = "${local.subdomain}.${local.domain}"
sensitive = false sensitive = false
} }
output "runner_ip" {
description = "The private network address of the runner."
value = local.runner_ip
sensitive = false
}

View File

@@ -8,7 +8,7 @@ terraform {
required_providers { required_providers {
hcloud = { hcloud = {
source = "hetznercloud/hcloud" source = "hetznercloud/hcloud"
version = "~> 1.57" version = "~> 1.45"
} }
} }
} }

13
terraform/routing.tf Normal file
View File

@@ -0,0 +1,13 @@
# 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 = "${local.subdomain}.${data.aws_route53_zone.main.name}"
type = "A"
ttl = "60"
records = [hcloud_primary_ip.public_ip.ip_address]
}

View File

@@ -1,16 +1,14 @@
locals { locals {
datacenter = "hel1-dc2" datacenter = "fsn1-dc14"
server_type = "cx23" server_type = "cx22"
server_image = "debian-12" server_image = "debian-12"
domain = "maximhutz.com" domain = "maximhutz.com"
subdomain = "git" subdomain = "git"
network_zone = "eu-central"
network_cidr = "10.0.0.0/16" network_cidr = "10.0.0.0/16"
subnet_cidr = "10.0.1.0/24" gitea_ip = "10.0.10.16"
server_ip = "10.0.1.2" runner_ip = "10.0.10.17"
runner_ip = "10.0.1.3"
} }
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
@@ -21,8 +19,13 @@ variable "hcloud_token" {
type = string type = string
} }
variable "public_ssh_key_path" { variable "public_gitea_ssh_key_path" {
description = "The location of the public key used to access the repository server." description = "The location of the public key used to access the repository Gitea server."
type = string
}
variable "public_runner_ssh_key_path" {
description = "The location of the public key used to access the repository Gitea Action runner."
type = string type = string
} }

View File

@@ -1,2 +1,4 @@
variables: variables:
image_name: mvhutz/gitea image_name: mvhutz/gitea
gitea_host: repository_gitea
runner_host: repository_runner

152
vault.yml
View File

@@ -1,73 +1,81 @@
$ANSIBLE_VAULT;1.1;AES256 $ANSIBLE_VAULT;1.1;AES256
61653436663266303862366531643735316166303031643931616464323034653564316364616664 34666138303266383336633235633037626261343833333763333463373261376165393735313230
3161386538393961346666383461636364393464333565340a616436303039623931303365333931 6133336466363137653966393733373236373161663434350a356634326634346530336632653535
36303933303862316236376537346533313330316239336366363430386161363162323435383330 66386136393434616639626634376236656666656362346130343964356536393634616165303531
3561373930663862390a666133383630326464356561383566653035363938643461613964353261 6636396336303361320a353135303264313361373762303466383731313266666635316566383630
66653633616233646361656233363263633438336662386461623439323466353030336364313663 33363332623266343834633962663837383433303034336661633235616565333837623064396137
36383037313238303365363162653731323663653932646465303837643532363238653239646536 65373761343937666430336137656465643962336561346630626638343064306330323636366234
35623334346434646463396565313866333862316430613336323734323232623632323865646236 38363035323061663266663466336638366236346162373338396538333637613834353235613061
34613666363465663138343733663634636436326130303730333666623232356261353861343064 38313339353262643232613832623963376638643439666333333031356162303834363933313833
38653063346138313435393461393361643462656264656531643338323631323865363731303564 35336332316337353936313963343636636464656639313930613133333866303933336635663737
34623132663634336362373730313664613238323130626261383762353933373166643063396563 65663237663865313566666133666161626539376463363439313365333366323561653666616533
36636230323565396361386164653037623532373166623665363234383261376464396163643862 61383334383230663330326236366262323464633432613562313239613031666261626334323666
37356338313638396261653637663930656236366666346365343335303239333265333665356335 61616534343436356631383764383139386630656165376461313432643136653463306435353261
38363062353462636636303735643961626462396439663864636230333134303233616436373765 65313363383339353434663139303961393865353230646138633161626235636437636135653763
62633361643737633535303435343566613630316562303132393062623532353366366531653164 30313736366263303866313466333464303666396334643531343734623562636439616239663737
61386634653463653164336532303732636335343266346264363361623166376533643962623563 32653536646234343435376365623466346131353262663261653438666137386662326332343263
38643830316333356133653334366332653235383965383766373665356139313438663631373063 38343966373931326232393838613763653731383038373338353863303264366162373966613563
64313764353536633466393764323062363531373038306437396665383134373635623363663239 36363137636236643663373837383161386266313963363437663835663037316230373466643466
38623461303165306132323430316436653664643166653764386663393662306339616666353338 61353931653031313133393163353639373736636139366430653865663335303230306662393632
37366631383937623064653534613930306331303565623366353263613537306636353732313964 30666435633434656434313736323732383135383638383334393433333530646661396232383635
31376430386234353735353866376332356561353761333461616463663831313364666437646139 35363430313837373136643230386666623436383239336339623565356630303766333832306261
62643233373066343363316362613236393333646634666366316530623537313633653236393336 63396565623164633466356437316233386561313932626262613162326332306638363130613533
37323831313834626263303933343132343535336661363563336235313038653330323061616365 62363665363032646565643036636233323966373362663163373165323934383263316232323965
64323431306234306266346564346462663335313830366435356433303837363130643034336131 39663733346637663735613434326239633337613933633765306261616363396465623565346136
63643036343631343862376262333362396137396366663031653263313462656662363066313461 35336333363461653163343436633963343830306264333665393338363039636139343934353361
63666666373835633936313332613030303863386563376638316565613230633762666337646538 39613664383134663766623165386266623661356230396535346166653761633831663566366339
30313837356636636333663032666166636364376537336132393765306339376639643238303537 65353933663861333539336130633262303038633639333137313232363535636531353435303635
35376336393931643634633134303463653036393435383234353863613266663166336235393431 39306433633261303634616533666230396566616131363435383662363432613634386266373966
61333134393035613835356462303232366164653865393861333965646535376132633061383531 38323933303164323565326534326364646562316539643132616364646137323735373236633637
37616139633431383463373836636337623434366161366262326534346163366638353164646132 36646337356333643766393464626633643263313437343932306634363532626563646163353661
62616338646530376264633038373765373138346334626237386662616466636533376165613133 65636461663736663136366462346462633065313763666532303532366538386239383465323966
39613134346130623137396536353564616165376632623736353435643133313565306234333631 36333465313338613635373336306266643862623262306237666235633532373163356630303163
30393861343338393031323765306332363634343830333965333131326536363361303839633238 32353563623162303465376237313264646132656565313335653964323233636562613664316538
31643430613838353838363065333264313330313934316130313835326562646465656264313738 32383737316362356365613064393662316434303932643136313866326235636632353135373735
30333035633733626561316162633137623139343064316264383066656566613164306166613266 38656536623134623263656338356436656137313563353366666366643535393662356433376237
31393966373865366263303031343638326565336665376131366231353364386163346662343037 30343961653363376162626333323261316635333366366131343136383362386131396466383662
39306439633264386534643732346637323039313566653864323764663332363437316135383537 32393361383534636662663439363630663064383834363036396463383362666637646436326462
35396439306533306334303466616136643762656463393435376534383835636530663565663663 36653734353036613139653462363563613635643166333262623533316330666166613239613136
31353836626536613466363363643638323433626531623636353735393530373638313465356162 30366662333666653038303035323163323438323535366339646539323063373761346337373163
33373466333363393634363935613034373436653133313835396133363766663135366633633661 63393833373663356635646236616564353936366437633766616333656538366263353664363031
35353032656239663930363230373135663562356532633838613639666539376632383239316533 65303462623737323638326661326134303635353065323666616331323933646531376239626630
62366230313762303335616462343566396466653565306130346538653530363261616262353539 35383232316666643166646232383837646262306331663337663961653861613536616632663764
31356336316436396461626631623536356433343838633034646630343930373565666139613338 39326331373633336661346133316434623434306636643839306136363734353330663237366564
31343163373466666532346436313535353736613965653539613930343463336231323932393163 32353237306633626564633034383466306239323833343838316638663065323834666438666135
37623533613836616437653638633638313362623638636437383762396438623631326462313834 36643832646434633262393634333264333964383433643866356232613536396339353536346538
36326133376331383464356364633031346639343165333461663538376336306539336438323361 62383832393033336133346435303463626165643463326538353864343565373830636635663237
39336536373163306632373531643563656534623838373639313164313239663966653236663434 38653239393061353334326662633735643238333231663437343238613730383937363834623664
37313439383032663033313135333765353833613665356139343631653861643264646562316630 37363661636230636632383331613264383064366238396163373838343062646432653462616635
63333234393363323833613438323133663531633733303864366636393961333662316439616263 38313835333437653734336162326662346466633533623565376262653134373730356337623165
39623039613339653930653732383363343530343539623437663836323538646136653465633764 62376464623438343165323037653631326565613737313062666232663130643638643165343466
34336237386237646533626236653262626539323866393830636532353462373730363232663366 30636261343730366233643634643963363061346361663732663336393239623934313561626461
63623631616236323037383635376261623439386532303631653861613433653064633137666365 33636365383863343138343964303630643463633732623462636465323464353063353134636430
36636566623563363764343232373731383564366233303536373266326637396133376462656166 37653764396236386233313766393339323735623139633966336237363061326431636566376137
36396264343464306233616561656535356463353334396435386464653935373862653035393237 30366636663235613136303462363035623135636461343638323266663661616335326332353034
38666362353462643930363361326634396166316334326362363165356264383063313137353834 62333130373830613363396331613336616531313064356165613930373230383234363561346632
30616336303761626236653836653332623738303261393632363930376232343434393764363365 64346635646338356430313536353436626265383561643166346561356430663238636561653363
66316134643039393235383562356232323161623835653365393232616332313837303064323336 62386365363466663931333663373737646563363639356161613464373534643965653236356639
30666330623432373536616433653164363639613363363963383262663939613564323334343636 63636237666332643966353131656435613933663230363665376333346563616634316430373235
38626263626265626137336231343231306437333732303639393138663535613533346433306434 33643738326164656664643730376266666236333631393634356133633432373031613030663464
66363032666162313538306631643430376465316536653631353530303038623536633034613335 61613964346133663638623038323161316665653436306533633438383563333465643731373537
32343233643436323863376163366439613239633665626264663463633766366639643835653031 64333531653437373531306631363533643736326462343138323739356463383465626638626164
38643439323666313663383662383161326633316161313030653835363863646264656437316436 62653862643032356264396461363530346633336230326166323563323830646464656633356430
39316461663238393330643535313137626432386566373163363363363432363061376462363031 33323163626633303639613138343765626633323563303236396164376336396362306265363365
63373163633530653133373830363061623739333338643561353330366331636333393638663738 38663237323533336263323636643536343963346337313938343262323366666130383339323337
66303831626165396533353035396464363861623462333033636536336536636138363633613033 31396361316438333262656231356566363635343465383265633133343338376363303962343131
62376236373231306238633266396335346439363334376464636664386361313263303865323365 34363537643731633735663635653163386264383334366134626230396439666439313963373934
31616630623934363761636532666433393233313161646666613330616565623562346534653563 38373237383239336333656235613963623766343565653865623861353735366638356137313161
63396563346162643565356330383436323461313665336437303866353939373334663062633437 63643735656463633063386239383961663230326665616233343634366531623561613732393131
34393763323935353433336133666138326235653037636465333463313830623433656634393061 34623665333866343962306234623538306234653264373534633062363263653638303736666537
65656462663061386361633638393232306165346663363931353036346439643365373930306466 32383832343939353438663738636537333834383934666536303233313763616434373663313737
37666531303637383165653737633736303235613863343733663965616237356661643961653637 65313465313161656565376532386564646435373062313964633033616564393632623338666261
64373634393030386337373535613238303431613739613337663337313338626431643165656239 62363034643363303337353565326438313832636165316363393238353531383837616337366530
34623164636363366333 36663733376436336639633431313263373337313239303563313962663361653633356637616239
64616665623563656137313537346238393432636235326164303165303136356264646634623438
61633334303539616366653763383134643764323735333163353036373961353738386630643030
61333861316565363536386465316637613065356235633335363834613733386130343132363130
33663866656163386265303163613164303538333462343233343930346261663430383038343833
34666439633562356633633666653338396131383531666238383962613737376531376638643265
34313464313136356532313439616365386133653334383266383564333562663366386631656663
37643837336138336237336462393937333437623665323063383464353662653865343433613164
36346433653537656264