Rehaul Gitea role for compose and PostgreSQL

This commit is contained in:
Kris Lamoureux 2022-05-27 00:02:45 -04:00
parent dc520a09e9
commit be6e1596c5
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
5 changed files with 87 additions and 90 deletions

View File

@ -17,7 +17,7 @@ proxy:
- domain: "{{ bitwarden_domain }}"
proxy_pass: "http://127.0.0.1:8080"
- domain: "{{ gitea_domain }}"
proxy_pass: "http://127.0.0.1:3080"
proxy_pass: "http://127.0.0.1:3000"
# docker
docker_users:
@ -34,8 +34,4 @@ bitwarden_install_key: 1yB3Z2gRI0KnnH90C6p
# gitea
gitea_domain: "git.{{ base_domain }}"
gitea_version: 1
gitea_dbversion: latest
gitea_dbpass: password
gitea_ports:
- "222:22"
- "3080:3000"

View File

@ -1,11 +1,16 @@
# container settings
gitea_name: gitea
gitea_dbname: "{{ gitea_name }}-db"
gitea_ports: "222:22"
gitea_sshport: "127.0.0.1:222"
gitea_webport: "127.0.0.1:3000"
gitea_volume: "{{ gitea_name }}"
gitea_rooturl: "http://{{ gitea_domain }}"
gitea_signup: true
# database settings
gitea_dbuser: "{{ gitea_dbname }}"
gitea_dbtype: postgres
gitea_dbhost: host.docker.internal
gitea_dbname: "{{ gitea_name }}"
gitea_dbuser: "{{ gitea_name }}"
# host
gitea_root: "/opt/{{ gitea_name }}/data"
gitea_dbroot: "/opt/{{ gitea_name }}/database"
gitea_root: "{{ docker_root }}/{{ gitea_name }}"

View File

@ -1,85 +1,34 @@
- name: Create Gitea Network
docker_network:
name: "{{ gitea_name }}"
- name: Create Gitea directory
file:
path: "{{ gitea_root }}"
state: directory
- name: Start Gitea's database container
docker_container:
- name: Create Gitea database
postgresql_db:
name: "{{ gitea_dbname }}"
image: mariadb:{{ gitea_dbversion }}
state: started
restart_policy: always
volumes: "{{ gitea_dbroot }}:/var/lib/mysql"
container_default_behavior: "no_defaults"
networks_cli_compatible: true
networks:
- name: "{{ gitea_name }}"
env:
MYSQL_RANDOM_ROOT_PASSWORD: "true"
MYSQL_DATABASE: "{{ gitea_dbname }}"
MYSQL_USER: "{{ gitea_dbuser }}"
MYSQL_PASSWORD: "{{ gitea_dbpass }}"
become: true
become_user: postgres
- name: Start Gitea container (traefik routing)
docker_container:
name: "{{ gitea_name }}"
image: gitea/gitea:{{ gitea_version }}
state: started
restart_policy: always
container_default_behavior: "no_defaults"
networks_cli_compatible: true
ports: "{{ gitea_ports }}"
networks:
- name: "{{ gitea_name }}"
- name: traefik
volumes:
- "{{ gitea_root }}:/data"
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
env:
USER_UID: "1000"
USER_GID: "1000"
DB_TYPE: mysql
DB_HOST: "{{ gitea_dbname }}"
DB_NAME: "{{ gitea_dbname }}"
DB_USER: "{{ gitea_dbuser }}"
DB_PASSWD: "{{ gitea_dbpass }}"
ROOT_URL: "https://{{ gitea_domain }}/"
SSH_DOMAIN: "{{ gitea_domain }}"
DOMAIN: "{{ gitea_domain }}"
labels:
traefik.http.routers.gitea.rule: "Host(`{{ gitea_domain }}`)"
traefik.http.routers.gitea.entrypoints: websecure
traefik.http.routers.gitea.tls.certresolver: letsencrypt
traefik.http.routers.gitea.middlewares: "securehttps@file"
traefik.http.services.gitea.loadbalancer.server.port: "3000"
traefik.docker.network: traefik
traefik.enable: "true"
when: traefik_version is defined
- name: Create Gitea database user
postgresql_user:
db: "{{ gitea_dbname }}"
name: "{{ gitea_dbuser }}"
password: "{{ gitea_dbpass }}"
become: true
become_user: postgres
- name: Start Gitea container
docker_container:
name: "{{ gitea_name }}"
image: gitea/gitea:{{ gitea_version }}
- name: Install Gitea's docker-compose file
template:
src: docker-compose.yml.j2
dest: "{{ gitea_root }}/docker-compose.yml"
- name: Install Gitea's docker-compose variables
template:
src: compose-env.j2
dest: "{{ gitea_root }}/.env"
- name: Start and enable Gitea service
service:
name: "{{ docker_compose_service }}@{{ gitea_name }}"
state: started
restart_policy: always
container_default_behavior: "no_defaults"
networks_cli_compatible: true
ports: "{{ gitea_ports }}"
networks:
- name: "{{ gitea_name }}"
volumes:
- "{{ gitea_root }}:/data"
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
env:
USER_UID: "1000"
USER_GID: "1000"
DB_TYPE: mysql
DB_HOST: "{{ gitea_dbname }}"
DB_NAME: "{{ gitea_dbname }}"
DB_USER: "{{ gitea_dbuser }}"
DB_PASSWD: "{{ gitea_dbpass }}"
ROOT_URL: "https://{{ gitea_domain }}/"
SSH_DOMAIN: "{{ gitea_domain }}"
DOMAIN: "{{ gitea_domain }}"
when: traefik_version is not defined
enabled: true

View File

@ -0,0 +1,17 @@
# {{ ansible_managed }}
gitea_version={{ gitea_version }}
gitea_name={{ gitea_name }}
gitea_domain={{ gitea_domain }}
gitea_rooturl={{ gitea_rooturl }}
gitea_webport={{ gitea_webport }}
gitea_sshport={{ gitea_sshport }}
gitea_dbtype={{ gitea_dbtype }}
gitea_dbhost={{ gitea_dbhost }}
gitea_dbname={{ gitea_dbname }}
gitea_dbuser={{ gitea_dbuser }}
gitea_dbpass={{ gitea_dbpass }}
{% if not gitea_signup %}
gitea_disable_registration=true
{% else %}
gitea_disable_registration=false
{% endif %}

View File

@ -0,0 +1,30 @@
version: '3.7'
services:
gitea:
image: "gitea/gitea:${gitea_version}"
container_name: "${gitea_name}"
ports:
- "${gitea_sshport}:22"
- "${gitea_webport}:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__server__ROOT_URL=${gitea_rooturl}
- GITEA__server__DOMAIN=${gitea_domain}
- GITEA__server__SSH_DOMAIN=${gitea_domain}
- GITEA__database__DB_TYPE=${gitea_dbtype}
- GITEA__database__HOST=${gitea_dbhost}
- GITEA__database__NAME=${gitea_dbname}
- GITEA__database__USER=${gitea_dbuser}
- GITEA__database__PASSWD=${gitea_dbpass}
- GITEA__service__DISABLE_REGISTRATION=${gitea_disable_registration}
volumes:
- {{ gitea_volume }}:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
volumes:
{{ gitea_volume }}: