diff --git a/roles/forgejo/files/redis.conf b/roles/forgejo/files/redis.conf deleted file mode 100644 index 43daf82..0000000 --- a/roles/forgejo/files/redis.conf +++ /dev/null @@ -1,5 +0,0 @@ -save "" -appendonly no - -maxmemory 32mb -maxmemory-policy allkeys-lru diff --git a/roles/forgejo/tasks/forgejo.yml b/roles/forgejo/tasks/forgejo.yml deleted file mode 100644 index 1e19cb1..0000000 --- a/roles/forgejo/tasks/forgejo.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -- name: Create forgejo volume - become: true - community.docker.docker_volume: - name: forgejo -- name: Copy app.ini - become: true - ansible.builtin.template: - src: app.ini.j2 - dest: /var/lib/docker/volumes/forgejo/_data/custom/conf/app.ini - owner: 1000 - group: 1000 - mode: '0660' - register: appini -- name: Create forgejo container - become: true - community.docker.docker_container: - name: forgejo - image: codeberg.org/forgejo/forgejo:8.0.3 - env: - USER_UID: "1000" - USER_GID: "1000" - FORGEJO_WORK_DIR: "/data" - FORGEJO_CUSTOM: "/data/custom" - networks: - - name: postgresql - - name: redis-forgejo - - name: minio - - name: haproxy - volumes: - - forgejo:/data - - /etc/timezone:/etc/timezone:ro - - /etc/localtime:/etc/localtime:ro - ports: - - "127.0.0.1:3004:3000" - - "8022:8022" - restart_policy: unless-stopped - recreate: "{{ appini.changed }}" diff --git a/roles/forgejo/tasks/main.yml b/roles/forgejo/tasks/main.yml index e40c31c..69296ce 100644 --- a/roles/forgejo/tasks/main.yml +++ b/roles/forgejo/tasks/main.yml @@ -1,3 +1,49 @@ --- -- import_tasks: redis.yml -- import_tasks: forgejo.yml +- name: Create forgejo network + become: true + community.docker.docker_network: + name: forgejo +- name: Create redis container + include_role: + name: redis + vars: + preset: cache + container_name: redis-forgejo + docker_networks: + - name: forgejo +- name: Create forgejo volume + become: true + community.docker.docker_volume: + name: forgejo +- name: Copy app.ini + become: true + ansible.builtin.template: + src: app.ini.j2 + dest: /var/lib/docker/volumes/forgejo/_data/custom/conf/app.ini + owner: 1000 + group: 1000 + mode: '0660' + register: appini +- name: Create forgejo container + become: true + community.docker.docker_container: + name: forgejo + image: codeberg.org/forgejo/forgejo:8.0.3 + env: + USER_UID: "1000" + USER_GID: "1000" + FORGEJO_WORK_DIR: "/data" + FORGEJO_CUSTOM: "/data/custom" + networks: + - name: postgresql + - name: forgejo + - name: minio + - name: haproxy + volumes: + - forgejo:/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + ports: + - "8022:8022" + restart_policy: unless-stopped + recreate: "{{ appini.changed }}" diff --git a/roles/forgejo/tasks/redis.yml b/roles/forgejo/tasks/redis.yml deleted file mode 100644 index a20ca4f..0000000 --- a/roles/forgejo/tasks/redis.yml +++ /dev/null @@ -1,34 +0,0 @@ ---- -- name: Create redis-forgejo network - become: true - community.docker.docker_network: - name: redis-forgejo -- name: Create redis-forgejo config dir - become: true - ansible.builtin.file: - path: /etc/redis/forgejo - state: directory - mode: '1755' - owner: root - group: root -- name: Copy redis config - become: true - ansible.builtin.copy: - src: redis.conf - dest: /etc/redis/forgejo/redis.conf - mode: '0664' - owner: root - group: root - register: redisconf -- name: Create redis container - become: true - community.docker.docker_container: - name: redis-forgejo - image: redis:7.4-bookworm - command: ["redis-server", "/etc/redis/redis.conf"] - volumes: - - /etc/redis/forgejo:/etc/redis:ro - networks: - - name: redis-forgejo - restart_policy: unless-stopped - recreate: "{{ redisconf.changed }}" diff --git a/roles/redis/meta/argument_specs.yml b/roles/redis/meta/argument_specs.yml new file mode 100644 index 0000000..f82f66c --- /dev/null +++ b/roles/redis/meta/argument_specs.yml @@ -0,0 +1,20 @@ +--- +argument_specs: + main: + options: + preset: + description: "Select 'persistent' preset if you want to save data." + type: "str" + choices: + - persistent + - cache + required: true + container_name: + type: "str" + required: true + docker_networks: + type: "list" + required: true + docker_volume: + type: "str" + description: "Required for 'persistent' preset" diff --git a/roles/redis/tasks/cache.yml b/roles/redis/tasks/cache.yml new file mode 100644 index 0000000..1a37313 --- /dev/null +++ b/roles/redis/tasks/cache.yml @@ -0,0 +1,9 @@ +--- +- name: Run redis container + become: true + community.docker.docker_container: + name: "{{ container_name }}" + image: "{{ image }}" + command: "{{ shared_cmd + ['--save', '', '--maxmemory', '128mb', '--maxmemory-policy', 'allkeys-lru'] }}" + networks: "{{ docker_networks }}" + restart_policy: unless-stopped diff --git a/roles/redis/tasks/main.yml b/roles/redis/tasks/main.yml new file mode 100644 index 0000000..98260ac --- /dev/null +++ b/roles/redis/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- import_tasks: persistent.yml + when: preset == "persistent" +- import_tasks: cache.yml + when: preset == "cache" diff --git a/roles/redis/tasks/persistent.yml b/roles/redis/tasks/persistent.yml new file mode 100644 index 0000000..7cfd161 --- /dev/null +++ b/roles/redis/tasks/persistent.yml @@ -0,0 +1,15 @@ +--- +- name: Create docker volume + become: true + community.docker.docker_volume: + name: "{{ docker_volume }}" +- name: Run redis container + become: true + community.docker.docker_container: + name: "{{ container_name }}" + image: "{{ image }}" + command: "{{ shared_cmd }}" + networks: "{{ docker_networks }}" + volumes: + - "{{ docker_volume }}:/data" + restart_policy: unless-stopped diff --git a/roles/redis/vars/main.yml b/roles/redis/vars/main.yml new file mode 100644 index 0000000..b7fe767 --- /dev/null +++ b/roles/redis/vars/main.yml @@ -0,0 +1,2 @@ +image: redis:7.4-bookworm +shared_cmd: ["redis-server", "--loglevel", "warning"]