From 95b73daa36b23565a8566f71f9b202d3459b685f Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 25 Jun 2023 09:52:36 -0400 Subject: Initial Commit --- .../containers/invidious/handlers/main.yml | 29 +++++ roles/services/containers/invidious/tasks/main.yml | 124 +++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 roles/services/containers/invidious/handlers/main.yml create mode 100644 roles/services/containers/invidious/tasks/main.yml (limited to 'roles/services/containers/invidious') diff --git a/roles/services/containers/invidious/handlers/main.yml b/roles/services/containers/invidious/handlers/main.yml new file mode 100644 index 0000000..a3a5d0b --- /dev/null +++ b/roles/services/containers/invidious/handlers/main.yml @@ -0,0 +1,29 @@ +- name: login to docker registry + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_login: + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + registry_url: "{{ docker_registry_url }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + +- name: build invidious image + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_image: + name: "{{ docker_registry_url }}/{{ docker_registry_username }}/invidious:latest" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + build: + path: /srv/docker/invidious/src + dockerfile: docker/Dockerfile + source: build + push: yes + +- name: restart nginx + service: + name: nginx + state: restarted diff --git a/roles/services/containers/invidious/tasks/main.yml b/roles/services/containers/invidious/tasks/main.yml new file mode 100644 index 0000000..6bff0e2 --- /dev/null +++ b/roles/services/containers/invidious/tasks/main.yml @@ -0,0 +1,124 @@ +- name: set image fact + set_fact: + image: gitea.chudnick.com/sam/invidious:latest + +- name: set other facts + vars: + array: "{{ image.split('/', 1) }}" + set_fact: + repo_tag: "{{ array.1 }}" + custom_registry: "{{ docker_registry_url + '/' + docker_registry_username }}" + +- name: create invidious directory + file: + path: "{{ docker_home }}/invidious" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: create postgres data directory + file: + path: "{{ docker_home }}/invidious/data" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: clone invidious repo + become: yes + become_user: "{{ docker_username }}" + notify: + - login to docker registry + - build invidious image + git: + repo: "{{ invidious_repo }}" + dest: "{{ docker_home }}/invidious/src" + version: "master" + +- meta: flush_handlers + +- name: create invidious docker network + become: yes + become_user: "{{ docker_username }}" + docker_network: + name: "{{ invidious_network_name }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + driver: bridge + ipam_config: + - subnet: "{{ invidious_subnet }}" + gateway: "{{ invidious_gateway }}" + +- name: create and deploy invidious db + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "invidious-db" + hostname: "invidious-db" + image: postgres:13 + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ invidious_network_name }}" + ipv4_address: "{{ invidious_db_ipv4 }}" + volumes: + - "{{ docker_home }}/invidious/data:/var/lib/postgresql/data" + - "{{ docker_home }}/invidious/src/config/sql:/config/sql" + - "{{ docker_home }}/invidious/src/docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh" + env: + "POSTGRES_DB": "invidious" + "POSTGRES_USER": "invidious" + "POSTGRES_PASSWORD": "{{ invidious_postgres_password }}" + state: 'started' + recreate: yes + restart_policy: unless-stopped + +- name: create and deploy invidious container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "invidious" + hostname: "invidious" + image: "{{ image }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + env: + "dbname": "invidious" + "user": "invidious" + "password": "{{ invidious_postgres_password }}" + "host": "invidious-db" + "port": "5432" + "check_tables": "true" + "https_only": "true" + "hsts": "true" + "domain": "{{ invidious_server_name }}" + "dark_mode": "dark" + networks: + - name: "{{ invidious_network_name }}" + ipv4_address: "{{ invidious_ipv4 }}" + ports: + - "127.0.0.1:{{ invidious_external_port }}:3000" + state: 'started' + recreate: yes + restart_policy: unless-stopped + +- name: deploy nginx configuration + notify: restart nginx + template: + src: "{{ invidious_nginx_config }}" + dest: /etc/nginx/sites-available/invidious.conf + owner: root + group: root + mode: '0644' + +- name: symlink site + file: + src: /etc/nginx/sites-available/invidious.conf + dest: /etc/nginx/sites-enabled/invidious.conf + owner: root + group: root + state: link -- cgit v1.2.3