This commit is contained in:
Kris Lamoureux 2022-05-24 21:15:10 -04:00
parent 209ff57a4a
commit e1c8dc55d3
11 changed files with 103 additions and 92 deletions

View File

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

View File

@ -1,5 +1,5 @@
bitwarden_name: bitwarden bitwarden_name: bitwarden
bitwarden_root: "/opt/{{ bitwarden_name }}" bitwarden_root: "{{ docker_root }}/{{ bitwarden_name }}"
bitwarden_database: "{{ bitwarden_name }}" bitwarden_database: "{{ bitwarden_name }}"
bitwarden_standalone: false bitwarden_standalone: false
bitwarden_production: false bitwarden_production: false

View File

@ -0,0 +1,3 @@
docker_root: /var/lib/docker-compose
docker_compose: /usr/bin/docker-compose
docker_compose_service: compose

View File

@ -4,6 +4,22 @@
state: present state: present
update_cache: true update_cache: true
- name: Create docker-compose root
file:
path: "{{ docker_root }}"
state: directory
- name: Install docker-compose systemd service
template:
src: docker-compose.service.j2
dest: "/etc/systemd/system/{{ docker_compose_service }}@.service"
register: compose_systemd
- name: Reload systemd manager configuration
systemd:
daemon_reload: true
when: compose_systemd.changed
- name: Add users to docker group - name: Add users to docker group
user: user:
name: "{{ item }}" name: "{{ item }}"

View File

@ -0,0 +1,14 @@
[Unit]
Description=%i docker-compose service
PartOf=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory={{ docker_root }}/%i
ExecStart={{ docker_compose }} up -d --remove-orphans
ExecStop={{ docker_compose }} down
[Install]
WantedBy=multi-user.target

View File

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

View File

@ -1,85 +1,20 @@
- name: Create Gitea Network - name: Create Gitea directory
docker_network: file:
name: "{{ gitea_name }}" path: "{{ gitea_root }}"
state: directory
- name: Start Gitea's database container - name: Install Gitea's docker-compose file
docker_container: template:
name: "{{ gitea_dbname }}" src: docker-compose.yml.j2
image: mariadb:{{ gitea_dbversion }} dest: "{{ gitea_root }}/docker-compose.yml"
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 }}"
- name: Start Gitea container (traefik routing) - name: Install Gitea's docker-compose variables
docker_container: template:
name: "{{ gitea_name }}" src: compose-env.j2
image: gitea/gitea:{{ gitea_version }} dest: "{{ gitea_root }}/.env"
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: Start Gitea container - name: Start and enable Gitea service
docker_container: service:
name: "{{ gitea_name }}" name: "{{ docker_compose_service }}@{{ gitea_name }}"
image: gitea/gitea:{{ gitea_version }}
state: started state: started
restart_policy: always enabled: true
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

View File

@ -0,0 +1,10 @@
# {{ ansible_managed }}
gitea_version={{ gitea_version }}
gitea_name={{ gitea_name }}
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 }}

View File

@ -0,0 +1,25 @@
version: '3.7'
services:
gitea:
image: "gitea/gitea:${gitea_version}"
container_name: "${gitea_name}"
ports:
- "${gitea_webport}:3000"
- "${gitea_sshport}:22"
- "127.0.0.1:5432:5432"
environment:
- USER_UID=1000
- USER_GID=1000
- 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}
volumes:
- {{ gitea_volume }}:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
volumes:
gitea:

View File

@ -62,6 +62,7 @@
file: file:
path: /etc/letsencrypt/renewal-hooks/post path: /etc/letsencrypt/renewal-hooks/post
state: directory state: directory
when: proxy.production is defined and proxy.production
- name: Install nginx post renewal hook - name: Install nginx post renewal hook
copy: copy:

View File

@ -1,3 +1,11 @@
{% if item.https is not defined or item.https %}
server {
listen 80;
server_name {{ item.domain }};
return 301 https://{{ item.domain }}$request_uri;
}
{% endif %}
server { server {
listen 443 ssl; listen 443 ssl;
server_name {{ item.domain }}; server_name {{ item.domain }};