Skip to content

Commit f6c696c

Browse files
committed
Add Ansible Playbook to Validate Compose Config
1 parent dd32b77 commit f6c696c

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

.github/workflows/build-validation.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@ jobs:
2222
- name: Checkout code
2323
uses: actions/checkout@v4
2424

25-
- name: Login to GitHub Container Registry
25+
- name: Install Ansible
26+
run: sudo apt-get update && sudo apt-get install -y ansible
27+
28+
- name: Validate Docker Compose config with Ansible
29+
env:
30+
IMAGE_TAG: dummy
31+
OPEN_WEBUI_API_KEY_CHAT: dummy_key
32+
OPEN_WEBUI_API_KEY_GEN: dummy_key
33+
LANGSMITH_API_KEY: dummy_key
34+
run: ansible-playbook ansible/validate-compose.yml
35+
36+
- name: Login to GitHub Container Registry # TODO: why? - remove?
2637
uses: docker/login-action@v3
2738
with:
2839
registry: ghcr.io

.github/workflows/deploy_vm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
OPEN_WEBUI_API_KEY_CHAT: ${{ secrets.OPEN_WEBUI_API_KEY_CHAT }}
9292
OPEN_WEBUI_API_KEY_GEN: ${{ secrets.OPEN_WEBUI_API_KEY_GEN }}
9393
LANGSMITH_API_KEY: ${{ secrets.LANGSMITH_API_KEY }}
94-
run: ansible-playbook -i inventory.ini deploy/ansible/deploy.yml
94+
run: ansible-playbook -i inventory.ini ansible/deploy.yml
9595

9696
deploy-k8s:
9797
needs: build-and-push
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55

66
vars:
77
project_dir: /home/ubuntu/app
8-
image_tag: "{{ lookup('env','IMAGE_TAG') }}"
9-
open_webui_api_key_chat: "{{ lookup('env','OPEN_WEBUI_API_KEY_CHAT') }}"
10-
open_webui_api_key_gen: "{{ lookup('env','OPEN_WEBUI_API_KEY_GEN') }}"
11-
langsmith_api_key: "{{ lookup('env','LANGSMITH_API_KEY') }}"
128

139
tasks:
10+
- include_tasks: tasks/env_vars.yml # load env variables
11+
1412
- name: Ensure project directory exists
1513
file:
1614
path: "{{ project_dir }}"
1715
state: directory
1816

1917
- name: Template compose with image tags
2018
template:
21-
src: ../../docker-compose.yml.j2
19+
src: ../docker-compose.yml.j2
2220
dest: "{{ project_dir }}/docker-compose.yml"
2321

2422
- name: Copy Traefik configuration files
2523
copy:
26-
src: ../../traefik/
24+
src: ../traefik/
2725
dest: "{{ project_dir }}/traefik/"
2826

2927
- name: Create acme.json file for Let's Encrypt certificates
@@ -36,7 +34,7 @@
3634

3735
- name: Copy Prometheus configuration files
3836
copy:
39-
src: ../../monitoring/prometheus/
37+
src: ../monitoring/prometheus/
4038
dest: "{{ project_dir }}/monitoring/prometheus/"
4139

4240

ansible/tasks/env_vars.yml

Whitespace-only changes.

ansible/validate-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# validate_docker_compose.yaml
2+
- name: Validate Docker Compose Jinja template
3+
hosts: localhost
4+
gather_facts: false
5+
6+
tasks:
7+
- include_tasks: tasks/env_vars.yml # load env variables
8+
9+
- name: Template compose file
10+
template:
11+
src: ../docker-compose.yml.j2
12+
dest: /tmp/compose-validation.yaml
13+
mode: '0644'
14+
15+
- name: Validate Docker Compose config
16+
command: docker compose -f /tmp/compose-validation.yaml config
17+
register: result
18+
failed_when: result.rc != 0
19+
20+
- name: Delete temp file
21+
file:
22+
path: /tmp/compose-validation.yaml
23+
state: absent

0 commit comments

Comments
 (0)