From f56d5d4ba8e063a9273ee91d53be2e34daacf73d Mon Sep 17 00:00:00 2001 From: Quentin Duchemin Date: Tue, 27 Apr 2021 00:22:08 +0200 Subject: [PATCH] Add Gitea --- all.yml | 2 + inv/host_vars/new.chosto.me/secrets.yml | 38 +++++++------ roles/gitea/tasks/main.yml | 25 ++++++++ roles/gitea/templates/docker-compose.yml.j2 | 60 ++++++++++++++++++++ roles/gitea/vars/main.yml | 6 ++ roles/lychee/templates/docker-compose.yml.j2 | 8 +-- 6 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 roles/gitea/templates/docker-compose.yml.j2 create mode 100644 roles/gitea/vars/main.yml diff --git a/all.yml b/all.yml index 90e3a99..22eb4d7 100644 --- a/all.yml +++ b/all.yml @@ -22,3 +22,5 @@ tags: ["docker", "lychee"] - role: "web" tags: ["docker", "web"] + - role: "gitea" + tags: ["docker", "gitea"] diff --git a/inv/host_vars/new.chosto.me/secrets.yml b/inv/host_vars/new.chosto.me/secrets.yml index ce91bcd..eac3679 100644 --- a/inv/host_vars/new.chosto.me/secrets.yml +++ b/inv/host_vars/new.chosto.me/secrets.yml @@ -1,18 +1,22 @@ $ANSIBLE_VAULT;1.1;AES256 -30666166383930623566383530643039346135323862643935353063396638333462393530333363 -3862636461353565353331663163323362663635396666370a336633623666343361613035316632 -30663833623362393139343237326137643537343036336635663930343330303663393235653661 -3339396266373636300a653733666236646637343735373931613033666532636437363965323461 -39633032616233663464343635313838616431356363363333356265343030376337646137313436 -39613230393965333764366465353361366361336661386464303763663739613435373735346139 -35353131303038633561336464366162636362316538363735653730383531306363326138636265 -36383936623162613335356430383934356435353039353437393063653739356165323637343738 -35636433343139656631643636393232333431333039656136393734383639373066323364323766 -66316638636237353164623861303639343930396162633866313730613066393361643661666633 -63346263326165326239623232303335336332643265303465353364616530373065383961363537 -64333339393934623838333863353532353735383137626234363562353264373661633032333363 -37386534636664653239356432623232643031633731323336313839633633643630653862376461 -37366336396237353939663365366137323766393238373036346531393231396665616364653465 -64643438643963333438353363333237323233663730313732313665303238643863316463326262 -30663531346432373235353065316132336265306136326339316530343232356131663034616662 -65633730343337623736396461623737393337633165643264396531646461306564 +62393336373634306239663131626365326563313035353232363839373664613363393061326136 +3164613334343462636263363233386236306132353766610a653036303738646363653837323934 +31653132653230616236366162613662623664643965323762613939396265616231643065373265 +3762666535353531390a303664653334396634643264393838323334373062356161353764363332 +64336365383639643464376131323164383062613734623134616337663735386334613063376236 +65346331373639366537333239373638336262613239356334613162623363363334353665353433 +65636461663965623463326161333534333265666435653063623761626130303332633636373131 +38383634366638636435363362303066623664663037393261376666313439356362663164613762 +64616239336464333364386665626230356637333761616535336361333935663837656664333864 +32646430653531326431333832316633343435633534316139336636626338616265663036656635 +65626330326438383964646130616639626533313436613835663762663932633230353862336364 +33636130336434623838646436383861656361353832663534366533383133323433376161396336 +30666564633366373063613664643766346137666361613836376361373432623364613264343765 +37356432383764343131393737653437383637626237653931626665333839373938323139363665 +35396336363330313334373139383963633432336530386564626562646163353465366166626631 +30353164646531326634363965353739386362626364666565376262613330643132323334613966 +64326463393633633563633139313033636132336161303730646232656139363966613137643633 +62663562356332613536386337363362643839373038313463613631656335623664393563346635 +63663533356131363335383961376662613738326264333030373239643530613637393866656265 +64656130663563613236323734613737353838306134333830346365363635656264393536383332 +3132 diff --git a/roles/gitea/tasks/main.yml b/roles/gitea/tasks/main.yml index e69de29..9a9a65c 100644 --- a/roles/gitea/tasks/main.yml +++ b/roles/gitea/tasks/main.yml @@ -0,0 +1,25 @@ +--- +- name: Create Gitea directory + file: + path: "{{ gitea_folder_name }}" + state: directory + owner: "{{ base_user_name }}" + group: "{{ base_user_name }}" + mode: 0755 + +- name: Copy Gitea Compose file + template: + src: docker-compose.yml.j2 + # Remove .j2 extension + dest: "{{ gitea_folder_name }}/docker-compose.yml" + owner: "{{ base_user_name }}" + group: "{{ base_user_name }}" + mode: 0644 + +- name: Ensure container is up to date + community.docker.docker_compose: + project_src: "{{ gitea_folder_name }}" + remove_orphans: yes + pull: yes + recreate: smart + state: present diff --git a/roles/gitea/templates/docker-compose.yml.j2 b/roles/gitea/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..13f368e --- /dev/null +++ b/roles/gitea/templates/docker-compose.yml.j2 @@ -0,0 +1,60 @@ +version: "{{ compose_version }}" + +networks: + proxy: + name: "{{ traefik_network }}" + db: + name: gitea_db + +volumes: + app: + name: gitea_app + db: + name: gitea_db + +services: + server: + image: gitea/gitea:{{ gitea_version }} + container_name: gitea + environment: + USER_UID: 1000 + USER_GID: 1000 + DB_TYPE: postgres + DB_HOST: db:5432 + APP_NAME: {{ gitea_name }} + RUN_MODE: prod + DOMAIN: {{ gitea_subdomain }}.{{ domain_name }} + SSH_DOMAIN: {{ gitea_subdomain }}.{{ domain_name }} + ROOT_URL: https://{{ gitea_subdomain }}.{{ domain_name }} + DISABLE_REGISTRATION: "true" + DB_NAME: gitea + DB_USER: gitea + DB_PASSWD: "{{ gitea_db_password }}" + networks: + - proxy + - db + volumes: + - app:/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + ports: + - "{{ gitea_ssh_host_port }}:22" + labels: + traefik.http.routers.gitea.entrypoints: websecure + traefik.http.routers.gitea.rule: "Host(`{{ gitea_subdomain }}.{{ domain_name }}`)" + traefik.http.services.gitea.loadbalancer.server.port: 3000 + traefik.enable: true + restart: unless-stopped + + db: + image: postgres:{{ postgres_version }} + container_name: gitea-db + environment: + POSTGRES_USER: gitea + POSTGRES_DB: gitea + POSTGRES_PASSWORD: "{{ gitea_db_password }}" + volumes: + - db:/var/lib/postgresql/data + networks: + - db + restart: unless-stopped diff --git a/roles/gitea/vars/main.yml b/roles/gitea/vars/main.yml new file mode 100644 index 0000000..0d9db20 --- /dev/null +++ b/roles/gitea/vars/main.yml @@ -0,0 +1,6 @@ +gitea_version: "1.14.1" +gitea_folder_name: "{{ docker_files }}/gitea" +postgres_version: "13" +gitea_name: Chostea +gitea_subdomain: git +gitea_ssh_host_port: 22 diff --git a/roles/lychee/templates/docker-compose.yml.j2 b/roles/lychee/templates/docker-compose.yml.j2 index fb084af..f9e7cc2 100644 --- a/roles/lychee/templates/docker-compose.yml.j2 +++ b/roles/lychee/templates/docker-compose.yml.j2 @@ -7,9 +7,9 @@ networks: name: lychee_db volumes: - lychee_db: + db: name: lychee_db - lychee_uploads: + uploads: name: lychee_uploads services: @@ -17,7 +17,7 @@ services: container_name: lychee image: "lycheeorg/lychee:{{ lychee_version }}" volumes: - - lychee_uploads:/uploads + - uploads:/uploads labels: traefik.http.routers.lychee.entrypoints: websecure traefik.http.routers.lychee.rule: "Host(`pic.{{ domain_name }}`)" @@ -46,7 +46,7 @@ services: image: "postgres:{{ postgres_version }}-alpine" container_name: lychee_db volumes: - - lychee_db:/var/lib/postgresql/data + - db:/var/lib/postgresql/data - /etc/localtime:/etc/localtime:ro environment: POSTGRES_USER: lychee