Compare commits
14 Commits
5ec2bd0c35
...
feat/s3-st
| Author | SHA1 | Date | |
|---|---|---|---|
|
24a1931c47
|
|||
| 2827653bd5 | |||
| 44e1d6d0e6 | |||
| 225489f678 | |||
| 53ad9c161c | |||
| d961d8ffb6 | |||
| aa7c0d4dee | |||
| 093368f6fb | |||
| 143e6be9a0 | |||
| 6193d99e1f | |||
| f9db293f52 | |||
| aa9810d0a8 | |||
| f458119e2c | |||
| c75ffba58c |
174
.gitignore
vendored
174
.gitignore
vendored
@@ -37,7 +37,179 @@ override.tf.json
|
|||||||
.terraformrc
|
.terraformrc
|
||||||
terraform.rc
|
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*
|
*secret*
|
||||||
.vscode
|
.vscode
|
||||||
.env
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
24
Taskfile.yml
24
Taskfile.yml
@@ -1,31 +1,21 @@
|
|||||||
version: 3
|
version: 3
|
||||||
silent: true
|
|
||||||
|
|
||||||
includes:
|
includes:
|
||||||
tf: { taskfile: terraform, dir: terraform }
|
tf: { taskfile: terraform, dir: terraform }
|
||||||
|
|
||||||
tasks:
|
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
|
||||||
|
|
||||||
|
deploy:fast: ansible-playbook playbooks/fast.yml
|
||||||
build: ansible-playbook playbooks/build.yml
|
deploy:slow: ansible-playbook playbooks/slow.yml
|
||||||
deploy: ansible-playbook playbooks/deploy.yml
|
deploy:restore: ansible-playbook playbooks/restore.yml -e "restore_bucket={{.BUCKET}} restore_key={{.KEY}}"
|
||||||
restore: ansible-playbook playbooks/restore.yml -e "restore_bucket={{.BUCKET}} restore_key={{.KEY}}"
|
|
||||||
run:
|
|
||||||
- task: build
|
|
||||||
- task: deploy
|
|
||||||
|
|
||||||
enter:
|
enter:
|
||||||
cmd: aws ssm start-session --target $INSTANCE_ID
|
cmd: aws ssm start-session --target $INSTANCE_ID
|
||||||
env:
|
env:
|
||||||
INSTANCE_ID: { sh: jq -r .instance_id.value < config/infrastructure.secret.tf.json }
|
INSTANCE_ID: { sh: jq -r .instance_id.value < config/infrastructure.secret.json }
|
||||||
AWS_REGION: { sh: jq -r .aws_region < config/ansible.secret.json }
|
AWS_REGION: { sh: jq -r .aws_region < config/ansible.secret.json }
|
||||||
AWS_ACCESS_KEY_ID: { sh: jq -r .aws_access_key < config/ansible.secret.json }
|
AWS_ACCESS_KEY_ID: { sh: jq -r .aws_access_key < config/ansible.secret.json }
|
||||||
AWS_SECRET_ACCESS_KEY: { sh: jq -r .aws_secret_key < config/ansible.secret.json }
|
AWS_SECRET_ACCESS_KEY: { sh: jq -r .aws_secret_key < config/ansible.secret.json }
|
||||||
|
|
||||||
push:
|
|
||||||
dir: gitea
|
|
||||||
cmds:
|
|
||||||
- docker build -t web/git . -f Dockerfile --platform linux/amd64,linux/arm64
|
|
||||||
- docker login code.maximhutz.com
|
|
||||||
- defer: docker logout
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ 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
|
||||||
build:
|
build:
|
||||||
context: gitea
|
context: gitea
|
||||||
dockerfile: Dockerfile.dev
|
dockerfile: Dockerfile.dev
|
||||||
@@ -31,7 +33,7 @@ services:
|
|||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
environment:
|
environment:
|
||||||
AWS_ENDPOINT: localstack:4566
|
AWS_ENDPOINT: localstack:4566
|
||||||
AWS_S3_BUCKET_NAME: test
|
AWS_S3_BUCKET_NAME: backup
|
||||||
AWS_ACCESS_KEY_ID: _
|
AWS_ACCESS_KEY_ID: _
|
||||||
AWS_SECRET_ACCESS_KEY: _
|
AWS_SECRET_ACCESS_KEY: _
|
||||||
BACKUP_CRON_EXPRESSION: "* * * * *"
|
BACKUP_CRON_EXPRESSION: "* * * * *"
|
||||||
@@ -59,7 +61,11 @@ services:
|
|||||||
AWS_ACCESS_KEY_ID: _
|
AWS_ACCESS_KEY_ID: _
|
||||||
AWS_SECRET_ACCESS_KEY: _
|
AWS_SECRET_ACCESS_KEY: _
|
||||||
AWS_ENDPOINT_URL: http://localstack:4566
|
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:
|
volumes:
|
||||||
data:
|
data:
|
||||||
|
|||||||
BIN
gitea/.DS_Store
vendored
BIN
gitea/.DS_Store
vendored
Binary file not shown.
@@ -2,4 +2,5 @@ FROM gitea/gitea:latest-rootless
|
|||||||
|
|
||||||
ADD --chown=git:git config /etc/gitea
|
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
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ FROM gitea/gitea:latest-rootless
|
|||||||
|
|
||||||
ADD --chown=git:git config /etc/gitea
|
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
|
||||||
|
|
||||||
RUN rm /etc/gitea/app.ini
|
RUN rm /etc/gitea/app.ini
|
||||||
|
|||||||
@@ -24,32 +24,18 @@ 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 = git.maximhutz.com
|
# SSH_DOMAIN = %(FULL_DOMAIN)s
|
||||||
BUILTIN_SSH_SERVER_USER = git
|
BUILTIN_SSH_SERVER_USER = git
|
||||||
|
|
||||||
; --- Signed SSL ---
|
|
||||||
PROTOCOL=https
|
PROTOCOL=https
|
||||||
ENABLE_ACME=true
|
ENABLE_ACME=true
|
||||||
ACME_ACCEPTTOS=true
|
ACME_ACCEPTTOS=true
|
||||||
ACME_DIRECTORY=https
|
ACME_DIRECTORY=https
|
||||||
ACME_EMAIL=proxy@maximhutz.com
|
# ACME_EMAIL=%(EMAIL)s
|
||||||
DOMAIN = git.maximhutz.com
|
# DOMAIN = %(FULL_DOMAIN)s
|
||||||
ROOT_URL = https://git.maximhutz.com/
|
# ROOT_URL = %(ROOT_URL)s
|
||||||
HTTP_PORT = 443
|
HTTP_PORT = 443
|
||||||
|
|
||||||
; --- No SSL ---
|
|
||||||
; DOMAIN = git.maximhutz.com
|
|
||||||
; ROOT_URL = http://git.maximhutz.com/
|
|
||||||
; HTTP_PORT = 80
|
|
||||||
|
|
||||||
; --- Self-Signed SSL ---
|
|
||||||
# PROTOCOL = https
|
|
||||||
# ROOT_URL = https://git.maximhutz.com/
|
|
||||||
# DOMAIN = git.maximhutz.com
|
|
||||||
# HTTP_PORT = 443
|
|
||||||
# CERT_FILE = cert.pem
|
|
||||||
# KEY_FILE = key.pem
|
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
DB_TYPE = sqlite3
|
DB_TYPE = sqlite3
|
||||||
|
|
||||||
@@ -108,3 +94,10 @@ DEFAULT_MERGE_STYLE = merge
|
|||||||
|
|
||||||
[repository.signing]
|
[repository.signing]
|
||||||
DEFAULT_TRUST_MODEL = committer
|
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
|
||||||
@@ -28,18 +28,12 @@ SSH_LISTEN_PORT = 2222
|
|||||||
SSH_DOMAIN = localhost
|
SSH_DOMAIN = localhost
|
||||||
BUILTIN_SSH_SERVER_USER = git
|
BUILTIN_SSH_SERVER_USER = git
|
||||||
|
|
||||||
; --- No SSL ---
|
|
||||||
; DOMAIN = localhost
|
|
||||||
; ROOT_URL = http://localhost:80/
|
|
||||||
; HTTP_PORT = 80
|
|
||||||
|
|
||||||
; --- Self-Signed Certificate ---
|
|
||||||
PROTOCOL = https
|
PROTOCOL = https
|
||||||
ROOT_URL = https://localhost:443/
|
ROOT_URL = https://localhost:443/
|
||||||
DOMAIN = localhost
|
DOMAIN = localhost
|
||||||
HTTP_PORT = 443
|
HTTP_PORT = 443
|
||||||
CERT_FILE = cert.pem
|
CERT_FILE = /etc/gitea-custom/cert.pem
|
||||||
KEY_FILE = key.pem
|
KEY_FILE = /etc/gitea-custom/key.pem
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
DB_TYPE = sqlite3
|
DB_TYPE = sqlite3
|
||||||
@@ -101,3 +95,12 @@ DEFAULT_TRUST_MODEL = committer
|
|||||||
|
|
||||||
[oauth2]
|
[oauth2]
|
||||||
JWT_SECRET = x-----------------------------------------x
|
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
BIN
gitea/custom/.DS_Store
vendored
Binary file not shown.
@@ -1,42 +0,0 @@
|
|||||||
- name: Make build artifact.
|
|
||||||
hosts: localhost
|
|
||||||
vars_files: ../config/ansible.secret.json
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: Build image.
|
|
||||||
community.docker.docker_image_build:
|
|
||||||
name: "{{ image_name }}"
|
|
||||||
path: ../gitea
|
|
||||||
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 }}"
|
|
||||||
91
playbooks/fast.yml
Normal file
91
playbooks/fast.yml
Normal 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: 300m
|
||||||
|
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 * * *"
|
||||||
@@ -4,14 +4,13 @@
|
|||||||
gather_facts: false
|
gather_facts: false
|
||||||
vars_files:
|
vars_files:
|
||||||
- ../config/ansible.secret.json
|
- ../config/ansible.secret.json
|
||||||
- ../config/infrastructure.secret.tf.json
|
- ../config/infrastructure.secret.json
|
||||||
vars:
|
vars:
|
||||||
ansible_connection: aws_ssm
|
ansible_connection: aws_ssm
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
ansible_aws_ssm_plugin: "{{ ssm_plugin }}"
|
ansible_aws_ssm_plugin: "{{ ssm_plugin }}"
|
||||||
ansible_aws_ssm_bucket_name: "{{ image_bucket }}"
|
ansible_aws_ssm_bucket_name: "{{ image_bucket }}"
|
||||||
ansible_aws_ssm_instance_id: "{{ instance_id.value }}"
|
ansible_aws_ssm_instance_id: "{{ instance_id.value }}"
|
||||||
|
|
||||||
ansible_aws_ssm_region: "{{ aws_region }}"
|
ansible_aws_ssm_region: "{{ aws_region }}"
|
||||||
ansible_aws_ssm_access_key_id: "{{ aws_access_key }}"
|
ansible_aws_ssm_access_key_id: "{{ aws_access_key }}"
|
||||||
ansible_aws_ssm_secret_access_key: "{{ aws_secret_key }}"
|
ansible_aws_ssm_secret_access_key: "{{ aws_secret_key }}"
|
||||||
|
|||||||
@@ -1,17 +1,54 @@
|
|||||||
|
- name: Make build artifact.
|
||||||
|
hosts: localhost
|
||||||
|
vars_files: ../config/ansible.secret.json
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Build image.
|
||||||
|
community.docker.docker_image_build:
|
||||||
|
name: "{{ image_name }}"
|
||||||
|
path: ../gitea
|
||||||
|
nocache: true
|
||||||
|
rebuild: always
|
||||||
|
pull: true
|
||||||
|
|
||||||
|
- 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.xz
|
||||||
|
format: xz
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Push artifact to S3.
|
||||||
|
amazon.aws.s3_object:
|
||||||
|
bucket: "{{ image_bucket }}"
|
||||||
|
object: "{{ image_key }}"
|
||||||
|
src: ../dist/image.tar.xz
|
||||||
|
mode: put
|
||||||
|
|
||||||
|
region: "{{ aws_region }}"
|
||||||
|
access_key: "{{ aws_access_key }}"
|
||||||
|
secret_key: "{{ aws_secret_key }}"
|
||||||
|
|
||||||
- name: Deploy artifact to instance.
|
- name: Deploy artifact to instance.
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
become: true
|
become: true
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
vars_files:
|
vars_files:
|
||||||
- ../config/ansible.secret.json
|
- ../config/ansible.secret.json
|
||||||
- ../config/infrastructure.secret.tf.json
|
- ../config/infrastructure.secret.json
|
||||||
vars:
|
vars:
|
||||||
ansible_connection: aws_ssm
|
ansible_connection: aws_ssm
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
ansible_aws_ssm_plugin: "{{ ssm_plugin }}"
|
ansible_aws_ssm_plugin: "{{ ssm_plugin }}"
|
||||||
ansible_aws_ssm_bucket_name: "{{ image_bucket }}"
|
ansible_aws_ssm_bucket_name: "{{ image_bucket }}"
|
||||||
ansible_aws_ssm_instance_id: "{{ instance_id.value }}"
|
ansible_aws_ssm_instance_id: "{{ instance_id.value }}"
|
||||||
|
|
||||||
ansible_aws_ssm_region: "{{ aws_region }}"
|
ansible_aws_ssm_region: "{{ aws_region }}"
|
||||||
ansible_aws_ssm_access_key_id: "{{ aws_access_key }}"
|
ansible_aws_ssm_access_key_id: "{{ aws_access_key }}"
|
||||||
ansible_aws_ssm_secret_access_key: "{{ aws_secret_key }}"
|
ansible_aws_ssm_secret_access_key: "{{ aws_secret_key }}"
|
||||||
@@ -45,13 +82,19 @@
|
|||||||
state: started
|
state: started
|
||||||
recreate: true
|
recreate: true
|
||||||
restart_policy: unless-stopped
|
restart_policy: unless-stopped
|
||||||
memory: 425m
|
memory: 300m
|
||||||
memory_swap: 900m
|
memory_swap: 900m
|
||||||
ports: [80:80, 2222:2222, 443:443, "22:22"]
|
ports: [80:80, 2222:2222, 443:443, "22:22"]
|
||||||
env:
|
env:
|
||||||
GITEA__security__INTERNAL_TOKEN: "{{ internal_secret }}"
|
GITEA__security__INTERNAL_TOKEN: "{{ internal_secret }}"
|
||||||
GITEA__server__LFS_JWT_SECRET: "{{ lfs_secret }}"
|
GITEA__server__LFS_JWT_SECRET: "{{ lfs_secret }}"
|
||||||
GITEA__oauth2__JWT_SECRET: "{{ jwt_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:
|
labels:
|
||||||
docker-volume-backup.stop-during-backup: "true"
|
docker-volume-backup.stop-during-backup: "true"
|
||||||
volumes:
|
volumes:
|
||||||
@@ -3,6 +3,7 @@ ansible-compat==24.10.0
|
|||||||
ansible-core==2.18.1
|
ansible-core==2.18.1
|
||||||
ansible-lint==24.12.2
|
ansible-lint==24.12.2
|
||||||
attrs==24.3.0
|
attrs==24.3.0
|
||||||
|
awscli-local==0.22.0
|
||||||
black==24.10.0
|
black==24.10.0
|
||||||
boto3==1.35.95
|
boto3==1.35.95
|
||||||
botocore==1.35.95
|
botocore==1.35.95
|
||||||
@@ -19,6 +20,7 @@ Jinja2==3.1.5
|
|||||||
jmespath==1.0.1
|
jmespath==1.0.1
|
||||||
jsonschema==4.23.0
|
jsonschema==4.23.0
|
||||||
jsonschema-specifications==2024.10.1
|
jsonschema-specifications==2024.10.1
|
||||||
|
localstack-client==2.7
|
||||||
MarkupSafe==3.0.2
|
MarkupSafe==3.0.2
|
||||||
mypy-extensions==1.0.0
|
mypy-extensions==1.0.0
|
||||||
packaging==24.2
|
packaging==24.2
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ version: 3
|
|||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
BACKEND: ../config/backend.secret.tf.json
|
BACKEND: ../config/backend.secret.json
|
||||||
VARIABLES: ../config/variables.secret.tf.json
|
VARIABLES: ../config/variables.secret.json
|
||||||
OUTPUT: ../config/infrastructure.secret.tf.json
|
OUTPUT: ../config/infrastructure.secret.json
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
init: terraform init -backend-config={{.BACKEND}}
|
init: terraform init -backend-config={{.BACKEND}}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
## Install extras.
|
||||||
rpm --rebuilddb
|
rpm --rebuilddb
|
||||||
amazon-linux-extras install docker ansible2 python3.8 -y
|
amazon-linux-extras install docker ansible2 python3.8 -y
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ systemctl start docker
|
|||||||
# Set up the correct version of Python (for Ansible).
|
# Set up the correct version of Python (for Ansible).
|
||||||
ln -sf /usr/bin/python3.8 /usr/bin/python3
|
ln -sf /usr/bin/python3.8 /usr/bin/python3
|
||||||
ln -sf /usr/bin/pip3.8 /usr/bin/pip3
|
ln -sf /usr/bin/pip3.8 /usr/bin/pip3
|
||||||
pip3 install botocore boto3 requests packaging
|
pip3 install botocore boto3 requests packaging --user ssm-user
|
||||||
python3 -m pip install -U pip
|
python3 -m pip install -U pip
|
||||||
|
|
||||||
# Add some swap space.
|
# Add some swap space.
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ resource "aws_eip" "public" {
|
|||||||
domain = "vpc"
|
domain = "vpc"
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_iam_instance_profile" "ssm" {
|
# An instance profile for access via AWS SSM.
|
||||||
|
resource "aws_iam_instance_profile" "ssm" {
|
||||||
name = "SSMInstanceProfile"
|
name = "SSMInstanceProfile"
|
||||||
|
role = "AmazonSSMRoleForInstancesQuickSetup"
|
||||||
}
|
}
|
||||||
|
|
||||||
# The Gitea instance.
|
# The Gitea instance.
|
||||||
@@ -16,9 +18,9 @@ resource "aws_instance" "this" {
|
|||||||
subnet_id = module.vpc.public_subnets[0]
|
subnet_id = module.vpc.public_subnets[0]
|
||||||
|
|
||||||
user_data = file("install.sh")
|
user_data = file("install.sh")
|
||||||
user_data_replace_on_change = true
|
user_data_replace_on_change = false
|
||||||
|
|
||||||
iam_instance_profile = data.aws_iam_instance_profile.ssm.name
|
iam_instance_profile = aws_iam_instance_profile.ssm.name
|
||||||
vpc_security_group_ids = [aws_security_group.public_access.id]
|
vpc_security_group_ids = [aws_security_group.public_access.id]
|
||||||
|
|
||||||
metadata_options {
|
metadata_options {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
locals {
|
locals {
|
||||||
# The IP block for the VPC.
|
# The IP block for the VPC.
|
||||||
vpc_cidr = "10.0.0.0/16"
|
vpc_cidr = "10.0.0.0/16"
|
||||||
|
|
||||||
# Here is the domain name changes.
|
|
||||||
domain_name = "maximhutz.com"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_availability_zones" "all" {}
|
data "aws_availability_zones" "all" {}
|
||||||
@@ -25,15 +22,18 @@ module "vpc" {
|
|||||||
map_public_ip_on_launch = true
|
map_public_ip_on_launch = true
|
||||||
enable_dns_hostnames = true
|
enable_dns_hostnames = true
|
||||||
enable_dns_support = true
|
enable_dns_support = true
|
||||||
|
|
||||||
|
private_route_table_tags = { TableOf = "Main", TableType = "Public" }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only allow HTTP(s) and SSH traffic. Allow full access to internet.
|
# Only allow HTTP(s) and SSH traffic. Allow full access to internet.
|
||||||
resource "aws_security_group" "public_access" {
|
resource "aws_security_group" "public_access" {
|
||||||
vpc_id = module.vpc.vpc_id
|
vpc_id = module.vpc.vpc_id
|
||||||
|
tags = { GroupOf = "Main", GroupType = "Public" }
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_vpc_security_group_ingress_rule" "ingress" {
|
resource "aws_vpc_security_group_ingress_rule" "tcp" {
|
||||||
for_each = toset(["80", "443", "22", "2222", "81", "8080", "4321", "1234"])
|
for_each = toset(["80", "443", "22", "51821"])
|
||||||
|
|
||||||
security_group_id = aws_security_group.public_access.id
|
security_group_id = aws_security_group.public_access.id
|
||||||
|
|
||||||
@@ -43,6 +43,17 @@ resource "aws_vpc_security_group_ingress_rule" "ingress" {
|
|||||||
cidr_ipv4 = "0.0.0.0/0"
|
cidr_ipv4 = "0.0.0.0/0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "aws_vpc_security_group_ingress_rule" "udp" {
|
||||||
|
for_each = toset(["51820", "53"])
|
||||||
|
|
||||||
|
security_group_id = aws_security_group.public_access.id
|
||||||
|
|
||||||
|
from_port = each.value
|
||||||
|
to_port = each.value
|
||||||
|
ip_protocol = "udp"
|
||||||
|
cidr_ipv4 = "0.0.0.0/0"
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_vpc_security_group_egress_rule" "egress" {
|
resource "aws_vpc_security_group_egress_rule" "egress" {
|
||||||
for_each = toset(["-1"])
|
for_each = toset(["-1"])
|
||||||
|
|
||||||
|
|||||||
@@ -25,3 +25,9 @@ output "boot_secret" {
|
|||||||
description = "The access secret to manipulate the codebase repository boot."
|
description = "The access secret to manipulate the codebase repository boot."
|
||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "full_domain" {
|
||||||
|
value = "${var.subdomain}.${var.domain}"
|
||||||
|
description = "The domain of the Gitea instance."
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# The Route53 DNS zone.
|
# The Route53 DNS zone.
|
||||||
data "aws_route53_zone" "main" {
|
data "aws_route53_zone" "main" {
|
||||||
name = local.domain_name
|
name = var.domain
|
||||||
}
|
}
|
||||||
|
|
||||||
# Push all domain traffic through the reverse proxy.
|
# Push all domain traffic through the reverse proxy.
|
||||||
resource "aws_route53_record" "domain" {
|
resource "aws_route53_record" "domain" {
|
||||||
zone_id = data.aws_route53_zone.main.zone_id
|
zone_id = data.aws_route53_zone.main.zone_id
|
||||||
name = "git.${data.aws_route53_zone.main.name}"
|
name = "${var.subdomain}.${data.aws_route53_zone.main.name}"
|
||||||
type = "A"
|
type = "A"
|
||||||
ttl = "60"
|
ttl = "60"
|
||||||
records = [aws_eip.public.public_ip]
|
records = [aws_eip.public.public_ip]
|
||||||
|
|||||||
@@ -27,3 +27,13 @@ variable "boot_role" {
|
|||||||
type = string
|
type = string
|
||||||
description = "The name of the role for boot access."
|
description = "The name of the role for boot access."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "domain" {
|
||||||
|
type = string
|
||||||
|
description = "The name of the domain."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "subdomain" {
|
||||||
|
type = string
|
||||||
|
description = "The name of the subdomain."
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user