6 Commits

Author SHA1 Message Date
Max
b6b4978e68 feat: stuff 2025-12-22 10:14:58 -05:00
Max
b41d9f0e82 feat: basic routing to caddy 2025-06-22 04:02:13 -04:00
Max
06646e7ec7 feat: added config edit to taskfile 2025-06-22 03:47:54 -04:00
Max
80270b9a93 feat: created vaults, added to config 2025-06-22 03:44:41 -04:00
Max
2827653bd5 feat: works on production 2025-02-19 00:57:32 -05:00
Max
44e1d6d0e6 feat: S3 storage for development environmne 2025-02-18 23:25:42 -05:00
34 changed files with 279 additions and 1078 deletions

4
.gitignore vendored
View File

@@ -212,6 +212,4 @@ cython_debug/
*secret* *secret*
.vscode .vscode
.DS_Store .DS_Store
*.key
*.out

View File

@@ -2,25 +2,12 @@ version: 3
tasks: tasks:
dev: dev:
- docker compose down - docker compose -f compose.dev.yml rm -fsv
- docker volume prune -f - docker compose -f compose.dev.yml up --build --force-recreate --no-deps
- docker compose up --build --force-recreate
vault: ansible-vault edit vault.yml {{.CLI_ARGS}} deploy:fast: ansible-playbook playbooks/fast.yml
provision: ansible-playbook playbooks/provision.yml {{.CLI_ARGS}} deploy:slow: ansible-playbook playbooks/slow.yml {{.CLI_ARGS}}
deploy: ansible-playbook playbooks/deploy.yml {{.CLI_ARGS}} deploy:restore: ansible-playbook playbooks/restore.yml -e "restore_bucket={{.BUCKET}} restore_key={{.KEY}}"
restore: ansible-playbook playbooks/restore.yml {{.CLI_ARGS}}
assets:
- cp ./assets/icon.png ./gitea/custom/public/assets/img/logo.png
- cp ./assets/icon.svg ./gitea/custom/public/assets/img/logo.svg
- cp ./assets/logo.png ./gitea/custom/public/assets/img/favicon.png
- cp ./assets/logo.svg ./gitea/custom/public/assets/img/favicon.svg
- cp ./assets/logo.png ./gitea/custom/public/assets/img/apple-touch-icon.png
vault: ansible-vault edit vault.yml
enter: inventory: ansible-vault edit inventory.ini
cmd: ssh -i {{.KEY}} -p 2222 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" }

View File

@@ -1,8 +1,9 @@
[defaults] [defaults]
callbacks_enabled = profile_tasks
localhost_warning = False localhost_warning = False
vault_password_file = vault.key inventory = inventory.ini
interpreter_python = /usr/bin/python3.11 host_key_checking = False
interpreter_python = /usr/bin/python3
vault_password_file = secret.key
[inventory] [inventory]
inventory_unparsed_warning = False inventory_unparsed_warning = False
@@ -10,4 +11,4 @@ inventory_unparsed_warning = False
[ssh_connection] [ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -o IdentityAgent=none ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -o IdentityAgent=none
pipelining = True pipelining = True
retries = 2 retries = 256

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -3,6 +3,7 @@ services:
# Gitea itself. # Gitea itself.
gitea: gitea:
container_name: web-git-instance container_name: web-git-instance
restart: unless-stopped
depends_on: depends_on:
- backup - backup
- bucket-script - bucket-script

View File

@@ -4,4 +4,3 @@ ADD --chown=git:git config /etc/gitea
ADD --chown=git:git custom /etc/gitea-custom ADD --chown=git:git custom /etc/gitea-custom
ENV GITEA_CUSTOM=/etc/gitea-custom ENV GITEA_CUSTOM=/etc/gitea-custom
ENV BUCKET_KEY=""

View File

@@ -4,7 +4,7 @@ RUN_MODE = prod
WORK_PATH = /var/lib/gitea WORK_PATH = /var/lib/gitea
[ui] [ui]
DEFAULT_THEME = gitea-light DEFAULT_THEME = gitea-dark
[repository] [repository]
ROOT = /var/lib/gitea/git/repositories ROOT = /var/lib/gitea/git/repositories
@@ -24,12 +24,16 @@ DISABLE_SSH = false
START_SSH_SERVER = true START_SSH_SERVER = true
SSH_PORT = 22 SSH_PORT = 22
SSH_LISTEN_PORT = 22 SSH_LISTEN_PORT = 22
# SSH_DOMAIN = %(FULL_DOMAIN)s
BUILTIN_SSH_SERVER_USER = git BUILTIN_SSH_SERVER_USER = git
PROTOCOL=https PROTOCOL=https
ENABLE_ACME=true ENABLE_ACME=true
ACME_ACCEPTTOS=true ACME_ACCEPTTOS=true
ACME_DIRECTORY=https ACME_DIRECTORY=https
# ACME_EMAIL=%(EMAIL)s
# DOMAIN = %(FULL_DOMAIN)s
# ROOT_URL = %(ROOT_URL)s
HTTP_PORT = 443 HTTP_PORT = 443
[database] [database]
@@ -93,5 +97,7 @@ DEFAULT_TRUST_MODEL = committer
[storage] [storage]
STORAGE_TYPE = minio STORAGE_TYPE = minio
MINIO_ENDPOINT = s3.us-east-1.amazonaws.com
MINIO_BUCKET = myrica-faya
MINIO_USE_SSL = true MINIO_USE_SSL = true
MINIO_INSECURE_SKIP_VERIFY = false MINIO_INSECURE_SKIP_VERIFY = false

View File

@@ -4,7 +4,7 @@ RUN_MODE = prod
WORK_PATH = /var/lib/gitea WORK_PATH = /var/lib/gitea
[ui] [ui]
DEFAULT_THEME = gitea-light DEFAULT_THEME = gitea-dark
[repository] [repository]
ROOT = /var/lib/gitea/git/repositories ROOT = /var/lib/gitea/git/repositories

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 819 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 819 B

View File

@@ -2,7 +2,7 @@
<div role="main" <div role="main"
aria-label="{{if .IsSigned}}{{ctx.Locale.Tr "dashboard"}}{{else}}{{ctx.Locale.Tr "home"}}{{end}}" class="page-content home"> aria-label="{{if .IsSigned}}{{ctx.Locale.Tr "dashboard"}}{{else}}{{ctx.Locale.Tr "home"}}{{end}}" class="page-content home">
<div class="tw-mb-8 tw-px-8"> <div class="tw-mb-8 tw-px-8">
<div class="center tw-gap-4"> <div class="center">
<img class="logo" width="220" height="220" src="{{AssetUrlPrefix}}/img/logo.svg" alt="{{ctx.Locale.Tr "logo"}}"> <img class="logo" width="220" height="220" src="{{AssetUrlPrefix}}/img/logo.svg" alt="{{ctx.Locale.Tr "logo"}}">
<div class="hero"> <div class="hero">
<h1 class="ui icon header title">{{AppName}}</h1> <h1 class="ui icon header title">{{AppName}}</h1>

26
inventory.ini Normal file
View File

@@ -0,0 +1,26 @@
$ANSIBLE_VAULT;1.1;AES256
36326131353430646433363636333433313266666434623134633136373566306534323231373637
6532386232643232343464393964623065326639643866640a353461626332623134613530663136
35643737623066313565633035623161366631663630663664313736613063303333373634353064
3333376338656539640a313561666239643466616161383561613833323765356238393034663865
36643538346263653263646334343063326464656264633461363136383530393931393764356534
38663963303737666632363239613836386235343730383530363536386165616339376435326639
37333866323262336637383431323538393334393136623838343766636634316338633566343366
32306461396134373161633437373730383933343865326363326435393232646163663461666437
36613664633633306264656230363862306661363930376666616630363036396639643639343336
65653162303435663166383934343936313935643936656235383930616539393239643634323237
38613032323336333764633339396163306665666430333762343631383430613463666339323361
63333964313832366532363334623236626232633132653639333231386663333865663665343530
33613364386531633561373537353432643332663735663833663532373763383237316331306366
64616462323739623833303661353764623537313432646137336230383830643761646131386263
33663034303064373066363731653737363033373163386466663734643065613039336330313664
37666332623264346132343638623332323661363338623335366230323737333961613035646366
63316164316135633136326337363464373036383433333830646131363533363338383262623261
63353737343236356561323738396631333133366338366538356232663834316230333265626562
32363862396362376332383131316665383166386631336631656231636130323339623032386535
38383339636339633961393632393063613261653061623465356238306330346464333039393134
37356232626434646566346464636131396339646663383333393963336332313931656436353334
36303039643837663130336362656636393737633962396531326231383862646631613061323737
32346166396139383231663233356233646634633361346564356366343834313835343332363565
66303933353231386331326462366239336361386638383861326662613732373661306330616334
6634

View File

@@ -1,201 +0,0 @@
- name: Set up for fresh host.
gather_facts: false
hosts: localhost
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Add remote host.
ansible.builtin.add_host:
name: server_fresh
ansible_ssh_host: "{{ server_ip.value }}"
ansible_user: root
ansible_port: 22
ansible_private_key_file: "{{ secret.private_ssh_key_path }}"
- name: Switch port to 2222.
hosts: server_fresh
ignore_unreachable: true
gather_facts: false
tasks:
- name: Update SSH port.
ansible.builtin.lineinfile:
dest: "/etc/ssh/sshd_config"
regexp: "^Port"
line: "Port 2222"
- name: Restart service.
ansible.builtin.service:
name: ssh
state: restarted
- name: Set up real host.
gather_facts: false
hosts: localhost
tags:
- deploy
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Add remote 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: Install Docker.
gather_facts: true
hosts: server
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Install PIP.
ansible.builtin.apt:
state: present
update_cache: true
name:
- python3-pip
- name: Install needed packages.
ansible.builtin.pip:
name:
- botocore
- boto3
- packaging
state: present
break_system_packages: true
- 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: Deploy artifact to instance.
hosts: server
tags:
- deploy
gather_facts: false
vars_files:
- ../variables.yml
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Copy gitea folder.
ansible.builtin.copy:
src: ../gitea/
dest: /root/gitea/
mode: preserve
- name: Build image.
community.docker.docker_image_build:
name: "{{ variables.image_name }}"
path: /root/gitea
nocache: true
rebuild: always
pull: true
- name: Create data directory.
ansible.builtin.file:
path: /root/data
state: directory
mode: '0777'
- name: Run image.
community.docker.docker_container:
name: server
image: "{{ variables.image_name }}"
state: started
recreate: true
restart_policy: unless-stopped
memory: 425m
memory_swap: 900m
ports: [80:80, 443:443, "22:22"]
env:
# Secrets.
GITEA__security__INTERNAL_TOKEN: "{{ secret.internal }}"
GITEA__server__LFS_JWT_SECRET: "{{ secret.lfs }}"
GITEA__oauth2__JWT_SECRET: "{{ secret.jwt }}"
GITEA__server__ACME_EMAIL: "acme@maximhutz.me"
GITEA__server__SSH_DOMAIN: "{{ server_fqdn.value }}"
GITEA__server__DOMAIN: "{{ server_fqdn.value }}"
GITEA__server__ROOT_URL: "https://{{ server_fqdn.value }}/"
# General S3 storage information.
GITEA__storage__MINIO_BUCKET: "{{ secret.bucket.name }}"
GITEA__storage__MINIO_ENDPOINT: "{{ secret.bucket.endpoint }}"
GITEA__storage__MINIO_ACCESS_KEY_ID: "{{ secret.bucket.access_key }}"
GITEA__storage__MINIO_SECRET_ACCESS_KEY: "{{ secret.bucket.secret_key }}"
# Set storage to specific S3 bucket path.
GITEA__storage_0x2E_attachments__MINIO_BASE_PATH: "{{ secret.storage.key }}/attachments"
GITEA__storage_0x2E_lfs__MINIO_BASE_PATH: "{{ secret.storage.key }}/lfs"
GITEA__storage_0x2E_avatars__MINIO_BASE_PATH: "{{ secret.storage.key }}/avatars"
GITEA__storage_0x2E_repo_0X2D_archive___MINIO_BASE_PATH: "{{ secret.storage.key }}/repo-archive"
GITEA__storage_0x2E_repo_0X2D_avatars__MINIO_BASE_PATH: "{{ secret.storage.key }}/repo-avatars"
GITEA__storage_0x2E_packages__MINIO_BASE_PATH: "{{ secret.storage.key }}/packages"
GITEA__storage_0x2E_actions_log__MINIO_BASE_PATH: "{{ secret.storage.key }}/actions_log"
GITEA__storage_0x2E_actions_artifacts__MINIO_BASE_PATH: "{{ secret.storage.key }}/actions_artifacts"
labels:
docker-volume-backup.stop-during-backup: "true"
volumes:
- /root/data:/var/lib/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- name: Run backup.
community.docker.docker_container:
name: backup
image: offen/docker-volume-backup:v2
state: started
recreate: true
restart_policy: unless-stopped
volumes:
- /root/data:/backup/my-app-backup:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
env:
AWS_S3_BUCKET_NAME: "{{ secret.bucket.name }}"
AWS_S3_PATH: "{{ secret.backup.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 * * *"

91
playbooks/fast.yml Normal file
View File

@@ -0,0 +1,91 @@
- name: Make build artifact.
hosts: localhost
vars_files:
- ../config/ansible.secret.json
- ../config/infrastructure.secret.json
gather_facts: false
tasks:
- name: Log into Docker.
community.docker.docker_login:
registry_url: '{{ full_domain.value }}'
username: '{{ username }}'
password: '{{ api_key }}'
reauthorize: true
- name: Build image.
community.docker.docker_image_build:
name: "{{ full_domain.value }}/{{ image_name }}:latest"
path: ../gitea
nocache: true
rebuild: always
pull: true
outputs: [{ type: image, push: true }]
platform:
- linux/amd64
- linux/arm64/v8
- name: Log out of Docker.
community.docker.docker_login:
state: absent
- name: Deploy artifact to instance.
hosts: localhost
become: true
gather_facts: false
vars_files:
- ../config/ansible.secret.json
- ../config/infrastructure.secret.json
vars:
ansible_connection: aws_ssm
ansible_aws_ssm_plugin: "{{ ssm_plugin }}"
ansible_aws_ssm_bucket_name: "{{ image_bucket }}"
ansible_aws_ssm_instance_id: "{{ instance_id.value }}"
ansible_python_interpreter: /usr/bin/python3
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: "{{ full_domain.value }}/{{ image_name }}:latest"
state: started
recreate: true
restart_policy: unless-stopped
memory: 425m
memory_swap: 900m
ports: [80:80, 2222:2222, 443:443, "22:22"]
env:
GITEA__security__INTERNAL_TOKEN: "{{ internal_secret }}"
GITEA__server__LFS_JWT_SECRET: "{{ lfs_secret }}"
GITEA__oauth2__JWT_SECRET: "{{ jwt_secret }}"
GITEA__server__ACME_EMAIL: "{{ email }}"
GITEA__server__SSH_DOMAIN: "{{ full_domain.value }}"
GITEA__server__DOMAIN: "{{ full_domain.value }}"
GITEA__server__ROOT_URL: "https://{{ full_domain.value }}/"
GITEA__storage__MINIO_ACCESS_KEY_ID: "{{ minio_access_key }}"
GITEA__storage__MINIO_SECRET_ACCESS_KEY: "{{ minio_secret_key }}"
labels:
docker-volume-backup.stop-during-backup: "true"
volumes:
- /home/ssm-user/data:/var/lib/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- name: Run backup.
community.docker.docker_container:
name: backup
image: offen/docker-volume-backup:v2
state: started
recreate: true
restart_policy: unless-stopped
volumes:
- /home/ssm-user/data:/backup/my-app-backup:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
env:
AWS_S3_BUCKET_NAME: "{{ boot_bucket }}"
AWS_S3_PATH: "{{ boot_key }}"
AWS_REGION: "{{ boot_region.value }}"
AWS_ACCESS_KEY_ID: "{{ boot_id.value }}"
AWS_SECRET_ACCESS_KEY: "{{ boot_secret.value }}"
BACKUP_CRON_EXPRESSION: "0 0 * * *"

View File

@@ -1,39 +0,0 @@
- name: Deploy terraform infrastructure.
hosts: localhost
gather_facts: false
vars_files:
- ../vault.yml
tasks:
- name: Reconfigure and plan.
community.general.terraform:
project_path: '../terraform'
state: "planned"
plan_file: plan.out
init_reconfigure: true
force_init: true
backend_config: "{{ terraform.backend }}"
variables: "{{ terraform.variables }}"
complex_vars: true
- name: Apply.
community.general.terraform:
project_path: '../terraform'
state: "present"
plan_file: plan.out
backend_config: "{{ terraform.backend }}"
variables: "{{ terraform.variables }}"
complex_vars: true
register: terraform_apply
- name: Create secret directory.
ansible.builtin.file:
path: ../dist
recurse: true
mode: "0755"
state: directory
- name: Send outputs to file.
ansible.builtin.copy:
content: "{{ terraform_apply.outputs }}"
dest: ../dist/terraform_outputs.yml
mode: '0755'

View File

@@ -1,25 +1,19 @@
- name: Set up real host.
gather_facts: false
hosts: localhost
vars_files:
- ../vault.yml
- ../dist/terraform_outputs.yml
tasks:
- name: Add remote 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: Deploy artifact to instance. - name: Deploy artifact to instance.
hosts: server hosts: localhost
become: true become: true
gather_facts: false gather_facts: false
vars_files: vars_files:
- ../vault.yml - ../config/ansible.secret.json
- ../dist/terraform_outputs.yml - ../config/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: "{{ 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: tasks:
- name: Stop server. - name: Stop server.
community.docker.docker_container: community.docker.docker_container:
@@ -28,39 +22,38 @@
loop: [server, backup] loop: [server, backup]
- name: Copy backup from S3. - name: Copy backup from S3.
environment:
region: "{{ boot_region.value }}"
access_key: "{{ boot_id.value }}"
secret_key: "{{ boot_secret.value }}"
amazon.aws.s3_object: amazon.aws.s3_object:
bucket: "{{ secret.restore.bucket | mandatory(msg='You must specify the bucket of the data.') }}" bucket: "{{ restore_bucket | mandatory(msg='You must specify the bucket of the data.') }}"
object: "{{ secret.restore.key | mandatory(msg='You must specify the key of the data.') }}" object: "{{ restore_key | mandatory(msg='You must specify the key of the data.') }}"
dest: /root/snapshot.tar.gz dest: /home/ssm-user/backup.tar.gz
mode: get mode: get
region: "{{ secret.restore.region }}"
access_key: "{{ secret.restore.access_key }}"
secret_key: "{{ secret.restore.secret_key }}"
endpoint_url: "{{ secret.restore.endpoint | mandatory(msg='You must specify the S3 URL.') }}"
ignore_nonexistent_bucket: true
- name: Ensure backup directory exists. - name: Ensure backup directory exists.
ansible.builtin.file: ansible.builtin.file:
path: /root/restore path: /home/ssm-user/backup
state: directory state: directory
mode: '0777' mode: '0777'
- name: Extract backup. - name: Extract backup.
ansible.builtin.unarchive: ansible.builtin.unarchive:
src: /root/snapshot.tar.gz src: /home/ssm-user/backup.tar.gz
dest: /root/restore dest: /home/ssm-user/backup
remote_src: true remote_src: true
- name: Move backup files to data folder. - name: Move backup files to data folder.
ansible.builtin.copy: ansible.builtin.copy:
remote_src: true remote_src: true
src: /root/restore/backup/my-app-backup/ src: /home/ssm-user/backup/backup/my-app-backup/
dest: /root/data/ dest: /home/ssm-user/data/
mode: '0777' mode: '0777'
- name: Update permissions. - name: Update permissions.
ansible.builtin.file: ansible.builtin.file:
path: /root/data path: /home/ssm-user/data
recurse: true recurse: true
mode: '0777' mode: '0777'
owner: 1000 owner: 1000

19
playbooks/route.yml Normal file
View File

@@ -0,0 +1,19 @@
- name: "Create route to instance."
hosts: router
gather_facts: false
tasks:
- name: Modify base Caddyfile.
ansible.builtin.blockinfile:
dest: ~/app/caddy/etc/Caddyfile
marker: '# GITEA {mark}'
content: "{{ lookup('file', '../router/Caddyfile') }}"
notify:
- Restart Caddy.
handlers:
- name: Restart Caddy.
ansible.builtin.systemd_service:
name: container-caddy
state: restarted
enabled: true
scope: user

84
playbooks/slow.yml Normal file
View File

@@ -0,0 +1,84 @@
- name: Make build artifact.
hosts: localhost
vars_files: ../config/ansible.secret.json
gather_facts: false
vars:
image_name: "service/gitea"
tasks:
- name: Build image.
community.docker.docker_image_build:
name: "{{ image_name }}"
path: ../gitea
nocache: true
rebuild: always
pull: true
- name: Create build directory.
ansible.builtin.file:
path: ../dist
state: directory
mode: '0777'
- name: Push image to archive.
community.docker.docker_image:
name: "{{ image_name }}"
archive_path: ../dist/image.tar
source: local
- name: Compress archive to artifact.
register: compress_image
community.general.archive:
path: ../dist/image.tar
dest: ../dist/image.tar.gz
format: gz
mode: "0644"
- name: Deploy artifact to instance.
hosts: compute
gather_facts: false
tasks:
- name: Create data directory.
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: '0777'
loop:
- ~/app
- ~/app/gitea
- name: Pull image to remote.
ansible.posix.synchronize:
src: ../dist/image.tar.gz
dest: ~/app/gitea/image.tar.gz
- name: Load image.
containers.podman.podman_load:
path: ~/app/gitea/image.tar.gz
register: image
# - name: Run image.
# community.docker.docker_container:
# name: server
# image: "{{ image.image_names[0] }}"
# state: started
# recreate: true
# restart_policy: unless-stopped
# memory: 425m
# memory_swap: 900m
# ports: [80:80, 2222:2222, 443:443, "22:22"]
# env:
# GITEA__security__INTERNAL_TOKEN: "{{ internal_secret }}"
# GITEA__server__LFS_JWT_SECRET: "{{ lfs_secret }}"
# GITEA__oauth2__JWT_SECRET: "{{ jwt_secret }}"
# GITEA__server__ACME_EMAIL: "{{ email }}"
# GITEA__server__SSH_DOMAIN: "{{ full_domain.value }}"
# GITEA__server__DOMAIN: "{{ full_domain.value }}"
# GITEA__server__ROOT_URL: "https://{{ full_domain.value }}/"
# GITEA__storage__MINIO_ACCESS_KEY_ID: "{{ minio_access_key }}"
# GITEA__storage__MINIO_SECRET_ACCESS_KEY: "{{ minio_secret_key }}"
# labels:
# docker-volume-backup.stop-during-backup: "true"
# volumes:
# - /home/ssm-user/data:/var/lib/gitea
# - /etc/timezone:/etc/timezone:ro
# - /etc/localtime:/etc/localtime:ro

View File

@@ -14,7 +14,6 @@ charset-normalizer==3.4.1
click==8.1.8 click==8.1.8
cryptography==44.0.0 cryptography==44.0.0
filelock==3.16.1 filelock==3.16.1
go-task-bin==3.44.1
idna==3.10 idna==3.10
importlib_metadata==8.5.0 importlib_metadata==8.5.0
Jinja2==3.1.5 Jinja2==3.1.5

3
router/Caddyfile Normal file
View File

@@ -0,0 +1,3 @@
code.maximhutz.com {
respond "WIP!"
}

View File

@@ -1,45 +0,0 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "6.27.0"
hashes = [
"h1:emgTfB1LXSFYh9uAwgsRMoMIN5Wz7jNNKq3rqC0EHWk=",
"zh:177a24b806c72e8484b5cabc93b2b38e3d770ae6f745a998b54d6619fd0e8129",
"zh:4ac4a85c14fb868a3306b542e6a56c10bd6c6d5a67bc0c9b8f6a9060cf5f3be7",
"zh:552652185bc85c8ba1da1d65dea47c454728a5c6839c458b6dcd3ce71c19ccfc",
"zh:60284b8172d09aee91eae0856f09855eaf040ce3a58d6933602ae17c53f8ed04",
"zh:6be38d156756ca61fb8e7c752cc5d769cd709686700ac4b230f40a6e95b5dbc9",
"zh:7a409138fae4ef42e3a637e37cb9efedf96459e28a3c764fc4e855e8db9a7485",
"zh:8070cf5224ed1ed3a3e9a59f7c30ff88bf071c7567165275d477c1738a56c064",
"zh:894439ef340a9a79f69cd759e27ad11c7826adeca27be1b1ca82b3c9702fa300",
"zh:89d035eebf08a97c89374ff06040955ddc09f275ecca609d0c9d58d149bef5cf",
"zh:985b1145d724fc1f38369099e4a5087141885740fd6c0b1dbc492171e73c2e49",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:a80b47ae8d1475201c86bd94a5dcb9dd4da5e8b73102a90820b68b66b76d50fd",
"zh:d3395be1556210f82199b9166a6b2e677cee9c4b67e96e63f6c3a98325ad7ab0",
"zh:db0b869d09657f6f1e4110b56093c5fcdf9dbdd97c020db1e577b239c0adcbce",
"zh:ffc72e680370ae7c21f9bd3082c6317730df805c6797427839a6b6b7e9a26a01",
]
}
provider "registry.terraform.io/hetznercloud/hcloud" {
version = "1.57.0"
constraints = "~> 1.45"
hashes = [
"h1:xpAcuja19Ts7bCpmULKdBw4dEBJhF/eL6AjM4xDBEAI=",
"zh:016ecc39328f34f6c0ffa413598f354824f7878c89cd031f123edb4bc8a687a2",
"zh:10b362dc0847200c987214b129b5f85e2f7d8ad417261a1d2dd04ab74de15603",
"zh:194647d9a61dca4f411f44580316b88a11095d7a99679d445f9b0f2c1ba976c4",
"zh:1d8aafe2ce7890696385bb3a0c3286e7ee3020416d337f59935406e4c6f91de6",
"zh:594585616210fb232fad4ebda2387ecd3f483931e00eff988fca83add6ce7cfc",
"zh:65e50be33ffb85580546f119839e1293591cc6d4db729d809931d0408b6ae408",
"zh:7d4ed5bd8c477ec304142e2160203a76a0d09c93d224950bda253172b2571038",
"zh:90a70a70a266b78c8216903e711904e6969b3957d182602b5d788602ec9ef323",
"zh:abb8e28e96fb8de270995873de980896b7cb53cfc550f02c50eaa42884624ba9",
"zh:bbf34dca2de6e105ca7204222162a0402d8e9e9a28e1de5ffbaa2c0d6270a059",
"zh:c1a9edb693d632dcb5c3c9ee84c97138e08eadb9354e28592efd581f68ac0385",
"zh:dadbf1368fae314fe8dcb99ebefbc78409f3fc0e3808cd92ea573b8eee1cae98",
"zh:e713e00ca27348abd18da2eeff861905e84050e3e7e008f14a0c63c70ab2ff84",
]
}

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,62 +0,0 @@
resource "hcloud_primary_ip" "public_ip" {
name = "repository-public-ip"
datacenter = local.datacenter
type = "ipv4"
assignee_type = "server"
auto_delete = false
}
resource "hcloud_ssh_key" "ssh_key" {
name = "repository-ssh-key"
public_key = file(var.public_ssh_key_path)
}
resource "hcloud_server" "server_instance" {
name = "repository-server"
image = local.server_image
server_type = local.server_type
datacenter = local.datacenter
ssh_keys = [hcloud_ssh_key.ssh_key.id]
public_net {
ipv4_enabled = true
ipv4 = hcloud_primary_ip.public_ip.id
ipv6_enabled = false
}
}
resource "hcloud_firewall" "server_firewall" {
name = "repository-server-firewall"
# Allow ICMP.
rule {
direction = "in"
protocol = "icmp"
source_ips = ["0.0.0.0/0", "::/0"]
}
# Allow all out.
rule {
direction = "out"
protocol = "tcp"
port = "any"
destination_ips = ["0.0.0.0/0", "::/0"]
}
# Poke holes for applications, and SSH.
dynamic "rule" {
for_each = ["80", "443", "22", "2222"]
content {
direction = "in"
protocol = "tcp"
port = rule.value
source_ips = ["0.0.0.0/0", "::/0"]
}
}
}
resource "hcloud_firewall_attachment" "server_fw_attachment" {
firewall_id = hcloud_firewall.server_firewall.id
server_ids = [hcloud_server.server_instance.id]
}

View File

@@ -1,11 +0,0 @@
output "server_ip" {
description = "The public address of the server."
value = hcloud_server.server_instance.ipv4_address
sensitive = false
}
output "server_fqdn" {
description = "The public domain of the server."
value = "${local.subdomain}.${local.domain}"
sensitive = false
}

View File

@@ -1,24 +0,0 @@
terraform {
backend "s3" {
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
}
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "~> 1.45"
}
}
}
provider "hcloud" {
token = var.hcloud_token
}
provider "aws" {
region = var.aws_region
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}

View File

@@ -1,39 +0,0 @@
locals {
datacenter = "fsn1-dc14"
server_type = "cx22"
server_image = "debian-12"
domain = "maximhutz.com"
subdomain = "git"
}
# ---------------------------------------------------------------------------- #
variable "hcloud_token" {
sensitive = true
description = "The hCloud token used to access Hetzner resources."
type = string
}
variable "public_ssh_key_path" {
description = "The location of the public key used to access the repository 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
}

View File

@@ -1,2 +0,0 @@
variables:
image_name: mvhutz/gitea

View File

@@ -1,70 +1,6 @@
$ANSIBLE_VAULT;1.1;AES256 $ANSIBLE_VAULT;1.1;AES256
38643539323537353461336432353537646361303835626434666463643836353464633461383533 66386561623561353461656662653566353665646466336635626561303031383735636666623063
3639353663323362666235373161306135396663323962610a376333313966346136616461393130 3336313938313562323336383765323932666638373232390a653163323131323564306438363864
31626537333832303433393338336631623635393730353165396166623632363561613538373931 31333632326135353966656363633962616165623036373764646433353966616364376162636234
3936366135623865620a623539306562653738663634363266346335343661333766663763643761 3837333961383333640a383732346534346465353062653531353638663465306432396266663534
66393937346664653462393766363563653430353038663439383861336230623861646233373365 3731
38613461376166633730653463656535316265353361643431303433373631356138363036336665
62363066313531313064313633353837623338313761636431383832643433646562323531383336
33343837366635653632316539376162633834363964613138376636666465376234303332643336
36373539656532323264313431323364656438363562363962393135383733656562666635616265
66323637306662663464386235646335363432616437336332656162656337326535336335343432
39356338303430383034383030323737636265353534356130363837373236343262663361313737
37613839613432376532643962663538633231633837343962373233363830646332623237633930
37373066613436636639326334363364323834323931653738653837326363323230643161663762
65353366396666373666383530363861623833393764313865306465303631383664663730643066
66393736323763323538346131663263306566303334366234633864653561393434393562633539
32303034303566616632313737303333326365326564313132376364353466376635646131613065
30646563643239306133313163643032363830653338346335363333316232633164376335373639
33633837313736633735343835353663323165386238636262373937613731323833323634646531
30366134643162623666323331636235333635386262323231626261353938623662323936393731
32383735646631316431633035323933336134356363663732633230636535373238633632636566
38373136323862366333303737376337366438373231343339383163333661613530366362313738
38633736373530613032323431366239633236656432633936663939306265316638643163383064
63326666663865663966333730356435356234343562393630343466393164393466303561316536
63663630393234623961366639323030313739616235653830356364663731366537343866333831
33336639653535316632613236343033393930623464343838653436643234343332623539306331
65663663373333303931326330663664663330353539376530303838643264356164633135626335
61613739336237666330373138373132346631666366666235346662363839383263323939383138
39656137343362636432343737616565646163623130623939616336616332616533303261656665
36306364643064643364666237663630376165303232313763383464313462353831306562666535
39363930396439633432373330636637313636316365306532333265626433333563343333323064
36393161383135346535623833396466323332323537316431646134343165353966613331313563
63326538643038346634323664393565656263323765363334353631616362343835666133383538
35626334363366323832636366346166373638666132623931633963663336363230316431356666
31636135303532313537666261393238396666326264323566646230663434323931323030343433
30356438323032353164333762653630656430306562313036353631663033646666363165623431
65613736393163363564326362303766363833623665343563326437383436336261346634343535
65343062373731623439623033323939343137326531316562383962363161666166646138393333
39353564303738396538613663633430653532643234656366653934333637376635363933313237
64303762303138613335393938306137346336393966666532313963653635643738306436316230
64623165656265393938326335656636386437643432383430376138393964643164646638633065
66396635343435353633636637613933306536306161633238386162633361313639303933653436
66303365366463353439386336313134316265306663646531376266306662366466653132323233
37623061663132633539313963396434353734643339393164353066653838346337306464643437
64623631393235636137666464653431323661326163626639396635666434633939653566343030
32643364316131336537613237373561653766383834353765633639343964383134313265303632
35656534666662663732353238333830326531393262633039356332386439653963346661346535
35376432663663336430653861323266373033383634626337366334363133303430616663353931
31643134653161646665646561643764336635623333653933643231663863653032666330383537
65333534323331396262633163343662663966653336616330323365666133653139623761316333
39616566386365383134393836373134633763373936616365363238323934623734313161396135
39656135383731623661646361373531643630643137343934393539656334373335636132353130
31323333336264366435636435653961366165386431313532656631666138336431333366623664
35316566666366393665333131313434353266356366373930373339636530613530653738633738
33646531363634343761343438396338656264326163616162306431366432616434316231366465
63623962383465626437363664653431396630343231356134353331666461613865326164653532
62653535343830346363636534366366373337653764353431623565626663376461666438653839
32633031333833613532613465623764386661616363643033613261613632653636643066303162
39393133646633613464393161313464663233396133633264346431626538663037663732386136
39653863303030343639353836373731303239666262363432373565326365346566643137653730
39623663353161626564383166383432656538383935343331646339636333366364646330373435
62666432336330636135393231356339366639626234656633656531353031623434663034383164
64316131316432373533363764393934323061393034663761363562313865666635303733613862
35633363386663316636326333393634353564393935643562663962303564383530343762323466
64376164383337633436616563303761373533383132346131313465653336366463346166343534
36316266613037353361306637353065313761656463373632633737663263333265336532323461
38343566636131663736393266303063333835373438313162383634323239666638303061636639
37313430383161316365363136353331393764613830653264373835633532303066666166326138
33373330633737383139613337393739626535626435383364393865393838393636663135653634
6334