Skip to content

Commit f616ed8

Browse files
Photon deploy, firewall & tests
Co-authored-by: 33Fraise33 <33Fraise33@users.noreply.github.com>
1 parent ea48fd1 commit f616ed8

17 files changed

Lines changed: 242 additions & 0 deletions

File tree

molecule/dawarich/converge.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
dawarich_postgres_image: imresamu/postgis
1414
dawarich_services_network: molecule-services
1515
dawarich_dns_servers: []
16+
dawarich_photon_api_host: molecule-photon
17+
dawarich_photon_api_port: "2322"
18+
dawarich_photon_api_use_https: "false"
1619
roles:
1720
- role: dawarich

molecule/dawarich/verify.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,19 @@
3131
- name: Assert shared Valkey is running
3232
ansible.builtin.assert:
3333
that: valkey_container.container.State.Status == 'running'
34+
35+
- name: Inspect Dawarich containers using Photon
36+
community.docker.docker_container_info:
37+
name: "{{ item }}"
38+
loop:
39+
- dawarich_app
40+
- dawarich_sidekiq
41+
register: dawarich_photon_containers
42+
43+
- name: Assert Dawarich Photon configuration
44+
ansible.builtin.assert:
45+
that:
46+
- item.container.Config.Env is contains('PHOTON_API_HOST=molecule-photon')
47+
- item.container.Config.Env is contains('PHOTON_API_PORT=2322')
48+
- item.container.Config.Env is contains('PHOTON_API_USE_HTTPS=false')
49+
loop: "{{ dawarich_photon_containers.results }}"

molecule/photon/cleanup.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- name: Cleanup Photon test dependencies
3+
hosts: all
4+
gather_facts: false
5+
tasks:
6+
- name: Remove Photon test container
7+
community.docker.docker_container:
8+
name: photon
9+
state: absent
10+
11+
- name: Remove Photon test database directory
12+
ansible.builtin.file:
13+
path: /tmp/molecule-photon-data
14+
state: absent

molecule/photon/converge.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
- name: Converge Photon role
3+
hosts: all
4+
gather_facts: false
5+
vars:
6+
photon_image: python
7+
photon_version: 3.13-alpine
8+
photon_command:
9+
- python
10+
- -m
11+
- http.server
12+
- "2322"
13+
photon_database_path: /tmp/molecule-photon-data
14+
photon_port: 12322
15+
roles:
16+
- role: photon
17+
tasks:
18+
- name: Pause for Photon runtime inspection
19+
ansible.builtin.pause:
20+
seconds: 5

molecule/photon/molecule.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
driver:
3+
name: docker
4+
5+
ansible:
6+
cfg:
7+
defaults:
8+
roles_path: ${MOLECULE_PROJECT_DIRECTORY}/roles
9+
10+
scenario:
11+
test_sequence:
12+
- destroy
13+
- syntax
14+
- create
15+
- prepare
16+
- converge
17+
- idempotence
18+
- verify
19+
- cleanup
20+
- destroy
21+
22+
platforms:
23+
- name: photon-instance
24+
image: geerlingguy/docker-debian12-ansible:latest
25+
pre_build_image: true
26+
privileged: true
27+
volumes:
28+
- /var/run/docker.sock:/var/run/docker.sock
29+
30+
provisioner:
31+
name: ansible
32+
playbooks:
33+
prepare: prepare.yml
34+
inventory:
35+
host_vars:
36+
photon-instance:
37+
ansible_python_interpreter: /usr/bin/python3
38+
39+
verifier:
40+
name: ansible

molecule/photon/prepare.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Prepare Photon dependencies
3+
hosts: all
4+
gather_facts: false
5+
become: true
6+
tasks:
7+
- name: Install Docker SDK dependencies
8+
ansible.builtin.apt:
9+
name:
10+
- python3-docker
11+
- python3-requests
12+
state: present
13+
update_cache: true

molecule/photon/verify.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
- name: Verify Photon deployment
3+
hosts: all
4+
gather_facts: false
5+
vars:
6+
photon_database_path: /tmp/molecule-photon-data
7+
tasks:
8+
- name: Inspect Photon container
9+
community.docker.docker_container_info:
10+
name: photon
11+
register: photon_container
12+
13+
- name: Assert Photon container configuration
14+
ansible.builtin.assert:
15+
that:
16+
- photon_container.container.State.Status == 'running'
17+
- photon_container.container.Config.Image == 'python:3.13-alpine'
18+
- photon_container.container.HostConfig.RestartPolicy.Name == 'always'
19+
- >-
20+
photon_container.container.HostConfig.PortBindings['2322/tcp'][0].HostPort
21+
== '12322'
22+
- >-
23+
photon_container.container.Mounts | selectattr('Destination', 'equalto',
24+
'/photon/photon_data') | list | length == 1
25+
- >-
26+
(photon_container.container.Mounts |
27+
selectattr('Destination', 'equalto', '/photon/photon_data') |
28+
map(attribute='Source') | first) == photon_database_path
29+
- photon_container.container.Config.Env is contains('PHOTON_UPDATE_STRATEGY=CONTINUOUS')
30+
- photon_container.container.Config.Env is contains('PHOTON_UPDATE_INTERVAL=3600')
31+
32+
- name: Check Photon API endpoint from the container
33+
community.docker.docker_container_exec:
34+
container: photon
35+
command: >-
36+
python -c "from urllib.request import urlopen;
37+
assert urlopen('http://127.0.0.1:2322/').status == 200"
38+
register: photon_api_check
39+
changed_when: false
40+
41+
- name: Assert Photon API endpoint succeeded
42+
ansible.builtin.assert:
43+
that: photon_api_check.rc == 0

playbooks/dawarich.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
---
2+
- name: Setup Photon reverse geocoding service
3+
hosts: BEOKPDCOVM02
4+
connection: ssh
5+
become: true
6+
roles:
7+
- role: photon
8+
tags: photon
9+
210
- name: Setup shared Valkey and Dawarich
311
hosts: BEOKPDCOVM01
412
connection: ssh

playbooks/host_vars/beokpdcovm01.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
dawarich_photon_api_host: 10.10.48.35
3+
dawarich_photon_api_port: "2322"
4+
dawarich_photon_api_use_https: "false"
5+
26
cloudflared:
37
docker_network: services
48
service_token: !vault |

playbooks/host_vars/beokpdcovm02.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
---
2+
photon_database_path: /media/photon
3+
24
firewall_filter_input_host:
35
- comment: "Allow portainer_agent"
46
destination:
57
port: 9001
68
protocol: tcp
79
counter: true
10+
- comment: "Allow Photon from VM01"
11+
source:
12+
ip: "@VM01"
13+
destination:
14+
port: 2322
15+
protocol: tcp
16+
counter: true
817

918
firewall:
1019
sets: "{{ firewall_sets_all + firewall_sets_internal }}"

0 commit comments

Comments
 (0)