22 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
Max
225489f678 feat: change security group tags, not name 2025-02-18 15:18:20 -05:00
Max
53ad9c161c feat: added tags to parts of vpc module, to use with proxy 2025-02-18 15:16:06 -05:00
Max
d961d8ffb6 fix: no ds_store 2025-02-13 22:09:15 -05:00
Max
aa7c0d4dee fix: gitignore is proper 2025-02-13 22:08:34 -05:00
Max
093368f6fb chore: requirements.txt is correct now 2025-02-13 22:07:37 -05:00
Max
143e6be9a0 style: renaming scheme for config files 2025-02-13 15:35:00 -05:00
Max
6193d99e1f chore: cleaned up ansible playbooks 2025-02-13 15:13:55 -05:00
Max
f9db293f52 feat: faster deployment options using Gitea OCI registry 2025-02-13 12:46:18 -05:00
Max
aa9810d0a8 feat: abstracted all domain instances away to the configuration files 2025-02-12 15:50:49 -05:00
Max
f458119e2c feat: dont change on install 2025-02-12 00:12:05 -05:00
Max
c75ffba58c chore: removed .DS_Store 2025-02-11 23:13:18 -05:00
Max
5ec2bd0c35 feat: moved to git subdomain 2025-02-11 23:10:57 -05:00
Max
116c683300 fix: restore command now seperated 2025-02-11 21:18:55 -05:00
Max
f7a0a3e868 feat: separated taskfiles 2025-02-11 16:30:21 -05:00
Max
0c5a7ef7f3 feat: using self signed certs 2025-02-10 15:12:51 -05:00
Max
7ae2cd6588 feat: gitea now standalone 2025-02-07 16:47:38 -05:00
29 changed files with 542 additions and 315 deletions

BIN
.DS_Store vendored

Binary file not shown.

174
.gitignore vendored
View File

@@ -37,7 +37,179 @@ override.tf.json
.terraformrc
terraform.rc
# ---> Ansible
*.retry
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
*secret*
.vscode
.env
.DS_Store

View File

@@ -1,28 +1,13 @@
version: 3
env: { TF: terraform -chdir=terraform }
silent: true
tasks:
dev: docker compose -f compose.dev.yml up --build --force-recreate --no-deps
dev:
- docker compose -f compose.dev.yml rm -fsv
- docker compose -f compose.dev.yml up --build --force-recreate --no-deps
tf/init: $TF init -backend-config=backend.tfvars
tf/plan: $TF plan -var-file=secret.tfvars
tf/destroy: $TF destroy
tf/format: $TF fmt -recursive
tf/apply:
- $TF apply -var-file=secret.tfvars
- $TF output -json > secrets.tf.json
deploy:fast: ansible-playbook playbooks/fast.yml
deploy:slow: ansible-playbook playbooks/slow.yml {{.CLI_ARGS}}
deploy:restore: ansible-playbook playbooks/restore.yml -e "restore_bucket={{.BUCKET}} restore_key={{.KEY}}"
build: ansible-playbook playbooks/build.yml
deploy: ansible-playbook playbooks/deploy.yml
run:
- task: build
- task: deploy
enter:
cmd: aws ssm start-session --target $INSTANCE_ID
env:
INSTANCE_ID: { sh: jq -r .instance_id.value < secrets.tf.json }
AWS_REGION: { sh: jq -r .aws_region < secrets/gitea.json }
AWS_ACCESS_KEY_ID: { sh: jq -r .aws_access_key < secrets/gitea.json }
AWS_SECRET_ACCESS_KEY: { sh: jq -r .aws_secret_key < secrets/gitea.json }
vault: ansible-vault edit vault.yml
inventory: ansible-vault edit inventory.ini

View File

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

View File

@@ -3,8 +3,10 @@ services:
# Gitea itself.
gitea:
container_name: web-git-instance
restart: unless-stopped
depends_on:
- backup
- bucket-script
build:
context: gitea
dockerfile: Dockerfile.dev
@@ -15,6 +17,7 @@ services:
ports:
- 80:80
- 443:443
- 3000:3000
- 2222:2222
labels:
- docker-volume-backup.stop-during-backup=true
@@ -30,7 +33,7 @@ services:
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
AWS_ENDPOINT: localstack:4566
AWS_S3_BUCKET_NAME: test
AWS_S3_BUCKET_NAME: backup
AWS_ACCESS_KEY_ID: _
AWS_SECRET_ACCESS_KEY: _
BACKUP_CRON_EXPRESSION: "* * * * *"
@@ -58,7 +61,11 @@ services:
AWS_ACCESS_KEY_ID: _
AWS_SECRET_ACCESS_KEY: _
AWS_ENDPOINT_URL: http://localstack:4566
command: '"aws s3api create-bucket --bucket test"'
command: |
"
aws s3api create-bucket --bucket backup
aws s3api create-bucket --bucket storage
"
volumes:
data:

BIN
gitea/.DS_Store vendored

Binary file not shown.

View File

@@ -2,4 +2,5 @@ FROM gitea/gitea:latest-rootless
ADD --chown=git:git config /etc/gitea
ADD --chown=git:git custom /etc/gitea-custom
ENV GITEA_CUSTOM /etc/gitea-custom
ENV GITEA_CUSTOM=/etc/gitea-custom

View File

@@ -2,7 +2,12 @@ FROM gitea/gitea:latest-rootless
ADD --chown=git:git config /etc/gitea
ADD --chown=git:git custom /etc/gitea-custom
ENV GITEA_CUSTOM /etc/gitea-custom
ENV GITEA_CUSTOM=/etc/gitea-custom
RUN rm /etc/gitea/app.ini
RUN mv /etc/gitea/dev.app.ini /etc/gitea/app.ini
WORKDIR /etc/gitea-custom
RUN gitea cert --host localhost --ca

View File

@@ -23,13 +23,18 @@ OFFLINE_MODE = true
DISABLE_SSH = false
START_SSH_SERVER = true
SSH_PORT = 22
SSH_LISTEN_PORT = 2222
SSH_DOMAIN = maximhutz.com
SSH_LISTEN_PORT = 22
# SSH_DOMAIN = %(FULL_DOMAIN)s
BUILTIN_SSH_SERVER_USER = git
DOMAIN = code.maximhutz.com
ROOT_URL = https://code.maximhutz.com/
HTTP_PORT = 80
PROTOCOL=https
ENABLE_ACME=true
ACME_ACCEPTTOS=true
ACME_DIRECTORY=https
# ACME_EMAIL=%(EMAIL)s
# DOMAIN = %(FULL_DOMAIN)s
# ROOT_URL = %(ROOT_URL)s
HTTP_PORT = 443
[database]
DB_TYPE = sqlite3
@@ -89,3 +94,10 @@ DEFAULT_MERGE_STYLE = merge
[repository.signing]
DEFAULT_TRUST_MODEL = committer
[storage]
STORAGE_TYPE = minio
MINIO_ENDPOINT = s3.us-east-1.amazonaws.com
MINIO_BUCKET = myrica-faya
MINIO_USE_SSL = true
MINIO_INSECURE_SKIP_VERIFY = false

View File

@@ -17,18 +17,23 @@ TEMP_PATH = /tmp/gitea/uploads
[server]
APP_DATA_PATH = /var/lib/gitea
LFS_START_SERVER = true
OFFLINE_MODE = true
LFS_JWT_SECRET = x-----------------------------------------x
DISABLE_SSH = false
START_SSH_SERVER = true
SSH_PORT = 2222
SSH_LISTEN_PORT = 2222
BUILTIN_SSH_SERVER_USER = git
LFS_START_SERVER = true
OFFLINE_MODE = true
SSH_DOMAIN = localhost
BUILTIN_SSH_SERVER_USER = git
PROTOCOL = https
ROOT_URL = https://localhost:443/
DOMAIN = localhost
ROOT_URL = http://localhost:80/
HTTP_PORT = 80
LFS_JWT_SECRET = x-----------------------------------------x
HTTP_PORT = 443
CERT_FILE = /etc/gitea-custom/cert.pem
KEY_FILE = /etc/gitea-custom/key.pem
[database]
DB_TYPE = sqlite3
@@ -90,3 +95,12 @@ DEFAULT_TRUST_MODEL = committer
[oauth2]
JWT_SECRET = x-----------------------------------------x
[storage]
STORAGE_TYPE = minio
MINIO_ENDPOINT = localstack:4566
MINIO_ACCESS_KEY_ID = test
MINIO_SECRET_ACCESS_KEY = test
MINIO_BUCKET = storage
MINIO_USE_SSL = false
MINIO_INSECURE_SKIP_VERIFY = true

BIN
gitea/custom/.DS_Store vendored

Binary file not shown.

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,41 +0,0 @@
- name: Make build artifact.
hosts: localhost
vars_files: ../secrets/gitea.json
tasks:
- name: Build image.
community.docker.docker_image_build:
name: "{{ image_name }}"
path: ../image
nocache: true
rebuild: always
pull: true
- name: Make temp file.
ansible.builtin.tempfile:
suffix: .tar
register: tar_file
- name: Push image to archive.
community.docker.docker_image:
name: "{{ image_name }}"
archive_path: "{{ tar_file.path }}"
source: local
- name: Compress archive to artifact.
register: compress_image
community.general.archive:
path: "{{ tar_file.path }}"
dest: "{{ tar_file.path }}.xz"
format: xz
mode: "0644"
- name: Push artifact to S3.
amazon.aws.s3_object:
bucket: "{{ image_bucket }}"
object: "{{ image_key }}"
src: "{{ tar_file.path }}.xz"
mode: put
region: "{{ aws_region }}"
access_key: "{{ aws_access_key }}"
secret_key: "{{ aws_secret_key }}"

View File

@@ -1,55 +0,0 @@
- name: Deploy artifact to instance.
hosts: localhost
become: true
vars_files:
- ../secrets/gitea.json
- ../secrets.tf.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:
- name: Fetch image.
amazon.aws.s3_object:
mode: get
bucket: "{{ image_bucket }}"
object: "{{ image_key }}"
dest: /root/image.tar.xz
region: "{{ aws_region }}"
access_key: "{{ aws_access_key }}"
secret_key: "{{ aws_secret_key }}"
- name: Load image.
community.docker.docker_image_load:
path: /root/image.tar.xz
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]
env:
GITEA__security__INTERNAL_TOKEN: "{{ internal_secret }}"
GITEA__server__LFS_JWT_SECRET: "{{ lfs_secret }}"
GITEA__oauth2__JWT_SECRET: "{{ jwt_secret }}"
AWS_REGION: "{{ boot_region.value }}"
AWS_ACCESS_KEY_ID: "{{ boot_id.value }}"
AWS_SECRET_ACCESS_KEY: "{{ boot_secret.value }}"
BOOT_URI: "s3://{{ boot_bucket }}/{{ boot_key }}"
volumes:
- /root/boot:/var/lib/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro

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 * * *"

66
playbooks/restore.yml Normal file
View File

@@ -0,0 +1,66 @@
- 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_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:
- name: Stop server.
community.docker.docker_container:
name: "{{ item }}"
state: stopped
loop: [server, backup]
- name: Copy backup from S3.
environment:
region: "{{ boot_region.value }}"
access_key: "{{ boot_id.value }}"
secret_key: "{{ boot_secret.value }}"
amazon.aws.s3_object:
bucket: "{{ restore_bucket | mandatory(msg='You must specify the bucket of the data.') }}"
object: "{{ restore_key | mandatory(msg='You must specify the key of the data.') }}"
dest: /home/ssm-user/backup.tar.gz
mode: get
- name: Ensure backup directory exists.
ansible.builtin.file:
path: /home/ssm-user/backup
state: directory
mode: '0777'
- name: Extract backup.
ansible.builtin.unarchive:
src: /home/ssm-user/backup.tar.gz
dest: /home/ssm-user/backup
remote_src: true
- name: Move backup files to data folder.
ansible.builtin.copy:
remote_src: true
src: /home/ssm-user/backup/backup/my-app-backup/
dest: /home/ssm-user/data/
mode: '0777'
- name: Update permissions.
ansible.builtin.file:
path: /home/ssm-user/data
recurse: true
mode: '0777'
owner: 1000
group: 1000
- name: Restart containers.
community.docker.docker_container:
name: "{{ item }}"
state: started
loop: [server, backup]

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

@@ -3,6 +3,7 @@ ansible-compat==24.10.0
ansible-core==2.18.1
ansible-lint==24.12.2
attrs==24.3.0
awscli-local==0.22.0
black==24.10.0
boto3==1.35.95
botocore==1.35.95
@@ -19,6 +20,7 @@ Jinja2==3.1.5
jmespath==1.0.1
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
localstack-client==2.7
MarkupSafe==3.0.2
mypy-extensions==1.0.0
packaging==24.2

3
router/Caddyfile Normal file
View File

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

View File

@@ -1,24 +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 = "5.83.1"
hashes = [
"h1:Yy3K7R7881H72rQDzG6qjZVkrWA6DGJzfE21TionY7w=",
"zh:0313253c78f195973752c4d1f62bfdd345a9c99c1bc7a612a8c1f1e27d51e49e",
"zh:108523f3e9ebc93f7d900c51681f6edbd3f3a56b8a62b0afc31d8214892f91e0",
"zh:175b9bf2a00bea6ac1c73796ad77b0e00dcbbde166235017c49377d7763861d8",
"zh:1c8bf55b8548bbad683cd6d7bdb03e8840a00b2422dc1529ffb9892820657130",
"zh:22338f09bae62d5ff646de00182417f992548da534fee7d98c5d0136d4bd5d7a",
"zh:92de1107ec43de60612be5f6255616f16a9cf82d88df1af1c0471b81f3a82c16",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:9c7bfb7afea330e6d90e1466125a8cba3db1ed4043c5da52f737459c89290a6e",
"zh:ba59b374d477e5610674b70f5abfe0408e8f809390347372751384151440d3d0",
"zh:bd1c433966002f586d63cb1e3e16326991f238bc6beeb2352be36ec651917b0b",
"zh:ca2b4d1d02651c15261fffa4b142e45def9a22c6069353f0f663fd2046e268f8",
"zh:d8ed98c748f7a3f1a72277cfee9afe346aca39ab319d17402277852551d8f14a",
"zh:ed3d8bc89de5f35f3c5f4802ff7c749fda2e2be267f9af4a850694f099960a72",
"zh:f698732a4391c3f4d7079b4aaa52389da2a460cac5eed438ed688f147d603689",
"zh:f9f51b17f2978394954e9f6ab9ef293b8e11f1443117294ccf87f7f8212b3439",
]
}

View File

@@ -1,28 +0,0 @@
data "aws_s3_bucket" "storage_bucket" {
bucket = var.boot_bucket
}
data "aws_iam_policy_document" "boot" {
statement {
effect = "Allow"
actions = ["s3:*", "s3-object-lambda:*"]
resources = ["${data.aws_s3_bucket.storage_bucket.arn}/${var.boot_key}"]
}
}
resource "aws_iam_policy" "boot" {
name = "${var.boot_role}Policy"
description = "The policy that manages the Gitea Boot."
policy = data.aws_iam_policy_document.boot.json
}
module "boot_user" {
source = "terraform-aws-modules/iam/aws//modules/iam-user"
version = "5.52.2"
create_iam_user_login_profile = false
name = "${var.boot_role}User"
password_reset_required = false
policy_arns = [aws_iam_policy.boot.arn]
}

View File

@@ -1,28 +0,0 @@
#!/bin/sh
amazon-linux-extras install docker ansible2 python3.8 -y
# Make Docker work.
systemctl enable docker
systemctl start docker
sudo usermod -aG docker ssm-user
# 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
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.)
sudo 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
docker-compose version

View File

@@ -1,25 +0,0 @@
data "aws_iam_instance_profile" "ssm" {
name = "SSMInstanceProfile"
}
# The Gitea instance.
resource "aws_instance" "gitea" {
# ami = data.aws_ami.amazon-linux-2.id
ami = "ami-0adec96dc0cdc7bca"
instance_type = "t4g.nano"
subnet_id = data.aws_subnet.subnet.id
user_data = file("install.sh")
user_data_replace_on_change = true
iam_instance_profile = data.aws_iam_instance_profile.ssm.name
root_block_device {
volume_type = "gp3"
volume_size = 8
}
tags = {
Name = "Codebase: Gitea"
}
}

View File

@@ -1,6 +0,0 @@
data "aws_subnet" "subnet" {
tags = {
SubnetType = "Private"
SubnetOf = "Main"
}
}

View File

@@ -1,27 +0,0 @@
output "instance_id" {
value = aws_instance.gitea.id
description = "The instance ID of the Gitea instance."
}
output "ip_address" {
value = aws_instance.gitea.private_ip
description = "The Gitea IP address."
}
output "boot_region" {
value = var.aws_region
description = "The region to manipulate the codebase repository boot."
sensitive = true
}
output "boot_id" {
value = module.boot_user.iam_access_key_id
description = "The access id to manipulate the codebase repository boot."
sensitive = true
}
output "boot_secret" {
value = module.boot_user.iam_access_key_secret
description = "The access secret to manipulate the codebase repository boot."
sensitive = true
}

View File

@@ -1,11 +0,0 @@
terraform {
# The backend is stored in an S3 bucket.
backend "s3" {}
}
# Access AWS through the IaC roles.
provider "aws" {
region = var.aws_region
access_key = var.aws_access
secret_key = var.aws_secret
}

View File

@@ -1,29 +0,0 @@
variable "aws_region" {
type = string
description = "The AWS region things are created in."
}
variable "aws_access" {
type = string
description = "The access key to generate the Gitea instance."
}
variable "aws_secret" {
type = string
description = "The access secret to generate the Gitea instance."
}
variable "boot_bucket" {
type = string
description = "The name of the bucket to store the boot in."
}
variable "boot_key" {
type = string
description = "The path that will hold the boot data."
}
variable "boot_role" {
type = string
description = "The name of the role for boot access."
}

6
vault.yml Normal file
View File

@@ -0,0 +1,6 @@
$ANSIBLE_VAULT;1.1;AES256
66386561623561353461656662653566353665646466336635626561303031383735636666623063
3336313938313562323336383765323932666638373232390a653163323131323564306438363864
31333632326135353966656363633962616165623036373764646433353966616364376162636234
3837333961383333640a383732346534346465353062653531353638663465306432396266663534
3731