feat: gitea now standalone

This commit is contained in:
2025-02-07 16:47:38 -05:00
parent 6ba433d53c
commit 7ae2cd6588
10 changed files with 182 additions and 25 deletions

View File

@@ -5,7 +5,7 @@
- name: Build image.
community.docker.docker_image_build:
name: "{{ image_name }}"
path: ../image
path: ../gitea
nocache: true
rebuild: always
pull: true

View File

@@ -20,7 +20,7 @@
mode: get
bucket: "{{ image_bucket }}"
object: "{{ image_key }}"
dest: /root/image.tar.xz
dest: /root/image.tar.gz
region: "{{ aws_region }}"
access_key: "{{ aws_access_key }}"
@@ -28,9 +28,13 @@
- name: Load image.
community.docker.docker_image_load:
path: /root/image.tar.xz
path: /root/image.tar.gz
register: image
- name: Create a volume.
community.docker.docker_volume:
name: data
- name: Run image.
community.docker.docker_container:
name: server
@@ -40,16 +44,32 @@
restart_policy: unless-stopped
memory: 425m
memory_swap: 900m
ports: [80:80, 2222:2222]
ports: [80:80, 2222:2222, 443:443]
env:
GITEA__security__INTERNAL_TOKEN: "{{ internal_secret }}"
GITEA__server__LFS_JWT_SECRET: "{{ lfs_secret }}"
GITEA__oauth2__JWT_SECRET: "{{ jwt_secret }}"
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 }}"
BOOT_URI: "s3://{{ boot_bucket }}/{{ boot_key }}"
volumes:
- /root/boot:/var/lib/gitea
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
BACKUP_CRON_EXPRESSION: "0 0 * * *"

51
playbooks/restore.yml Normal file
View File

@@ -0,0 +1,51 @@
- 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: 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: "{{ boot_bucket }}"
object: "{{ boot_key }}"
dest: /home/ssm-user/backup.tar.xz
mode: get
- name: Ensure backup directory exists.
ansible.builtin.file:
path: /home/ssm-user/data
state: directory
mode: '0777'
- name: Extract backup.
ansible.builtin.unarchive:
src: /home/ssm-user/backup.tar.xz
dest: /home/ssm-user/data
remote_src: true
- name: Restart containers.
community.docker.docker_container:
name: "{{ item }}"
state: started
loop: [server, backup]