Add Ansible role for shopping-list-api deployment
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
- name: Deploy Shopping List API
|
||||||
|
hosts: shopping_list_api
|
||||||
|
become: true
|
||||||
|
roles:
|
||||||
|
- shopping_list_api
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
shopping_list_api_base_path: "{{ base_config_dir }}/shopping-list-api"
|
||||||
|
shopping_list_api_data_path: "{{ shopping_list_api_base_path }}/data"
|
||||||
|
|
||||||
|
shopping_list_api_image: "git.danhenry.dev/thelab/shopping-list-api:{{ shopping_list_api_image_tag }}"
|
||||||
|
shopping_list_api_image_tag: "latest"
|
||||||
|
|
||||||
|
shopping_list_api_proxy_port: 8002
|
||||||
|
shopping_list_api_container_port: 8000
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Restart Shopping List API
|
||||||
|
community.docker.docker_compose_v2:
|
||||||
|
project_src: "{{ shopping_list_api_base_path }}"
|
||||||
|
state: restarted
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
dependencies:
|
||||||
|
- role: docker
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
- name: Create Shopping List API directories
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ docker_uid }}"
|
||||||
|
group: "{{ docker_gid }}"
|
||||||
|
mode: '0755'
|
||||||
|
loop:
|
||||||
|
- "{{ shopping_list_api_base_path }}"
|
||||||
|
- "{{ shopping_list_api_data_path }}"
|
||||||
|
|
||||||
|
- name: Deploy docker-compose.yml
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: docker-compose.yml.j2
|
||||||
|
dest: "{{ shopping_list_api_base_path }}/docker-compose.yml"
|
||||||
|
owner: "{{ docker_uid }}"
|
||||||
|
group: "{{ docker_gid }}"
|
||||||
|
mode: '0600'
|
||||||
|
notify: Restart Shopping List API
|
||||||
|
|
||||||
|
- name: Deploy nginx reverse proxy config
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: nginx.conf.j2
|
||||||
|
dest: "{{ shopping_list_api_base_path }}/nginx.conf"
|
||||||
|
owner: "{{ docker_uid }}"
|
||||||
|
group: "{{ docker_gid }}"
|
||||||
|
mode: '0644'
|
||||||
|
notify: Restart Shopping List API
|
||||||
|
|
||||||
|
- name: Deploy Shopping List API stack
|
||||||
|
community.docker.docker_compose_v2:
|
||||||
|
project_src: "{{ shopping_list_api_base_path }}"
|
||||||
|
state: present
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
services:
|
||||||
|
api:
|
||||||
|
image: {{ shopping_list_api_image }}
|
||||||
|
environment:
|
||||||
|
- DB_PATH=/app/data/shopping.db
|
||||||
|
volumes:
|
||||||
|
- {{ shopping_list_api_data_path }}:/app/data
|
||||||
|
restart: unless-stopped
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "-qO-", "http://localhost:{{ shopping_list_api_container_port }}/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
expose:
|
||||||
|
- "{{ shopping_list_api_container_port }}"
|
||||||
|
|
||||||
|
proxy:
|
||||||
|
image: nginx:alpine
|
||||||
|
ports:
|
||||||
|
- "{{ shopping_list_api_proxy_port }}:80"
|
||||||
|
volumes:
|
||||||
|
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||||
|
depends_on:
|
||||||
|
api:
|
||||||
|
condition: service_healthy
|
||||||
|
restart: unless-stopped
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://api:{{ shopping_list_api_container_port }};
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user