Skip to content

Commit 1f6e92e

Browse files
Merge branch 'CactuseSecurity:develop' into develop
2 parents dddba93 + 751a509 commit 1f6e92e

6 files changed

Lines changed: 184 additions & 95 deletions

File tree

.githooks/pre-commit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ set -euo pipefail
33

44
if [ -d ".venv/Scripts" ]; then
55
VENV_BIN=".venv/Scripts/"
6+
echo "Using virtual environment from .venv (Windows)"
7+
activate_script=".venv/Scripts/activate"
68
elif [ -d ".venv/bin" ]; then
9+
echo "Using virtual environment from .venv (Unix)"
710
VENV_BIN=".venv/bin/"
11+
activate_script=".venv/bin/activate"
812
else
13+
echo "Warning: No virtual environment found. Assuming ruff and pyright are globally available."
914
VENV_BIN=""
15+
activate_script=""
16+
fi
17+
18+
if [ -f "$activate_script" ]; then
19+
source "$activate_script"
1020
fi
1121

1222
RUFF_PATH=$VENV_BIN"ruff"

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ include = [
33
"roles/importer/files/importer",
44
"scripts"
55
]
6+
extraPaths = ["roles/importer/files/importer"]
7+
venv = ".venv"
8+
69
exclude = [
710
"**/.*",
811
"**/node_modules",
@@ -17,7 +20,6 @@ exclude = [
1720
"scripts/release_lock.py"
1821
]
1922

20-
2123
typeCheckingMode = "strict"
2224
reportMissingImports = false
2325
reportMissingTypeStubs = true

roles/api/tasks/hasura-install.yml

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,43 @@
3939
group: "{{ postgres_group }}"
4040
become: true
4141

42+
- name: check for existing hasura admin secret file
43+
stat:
44+
path: "{{ fworch_secrets_dir }}/hasura_admin_pwd"
45+
register: hasura_admin_secret_file
46+
become: true
47+
48+
- name: read existing hasura admin secret during upgrade
49+
slurp:
50+
src: "{{ fworch_secrets_dir }}/hasura_admin_pwd"
51+
register: existing_hasura_admin_secret
52+
become: true
53+
when:
54+
- installation_mode == "upgrade"
55+
- hasura_admin_secret_file.stat.exists
56+
- api_use_existing_hasura_on_upgrade | default(false) | bool
57+
58+
- name: set hasura admin secret from existing file
59+
set_fact:
60+
api_hasura_admin_secret: "{{ existing_hasura_admin_secret['content'] | b64decode | trim }}"
61+
when:
62+
- installation_mode == "upgrade"
63+
- hasura_admin_secret_file.stat.exists
64+
- api_use_existing_hasura_on_upgrade | default(false) | bool
65+
4266
- name: set static hasura admin pwd for test purposes only
4367
set_fact:
4468
api_hasura_admin_secret: "{{ api_hasura_admin_test_password }}"
45-
when: testkeys is defined and testkeys|bool
69+
when:
70+
- api_hasura_admin_secret is not defined
71+
- testkeys is defined
72+
- testkeys | bool
4673

4774
- name: set random hasura admin password
4875
set_fact:
4976
api_hasura_admin_secret: "{{ randomly_generated_pwd }}"
50-
when: testkeys is not defined or not testkeys|bool
77+
when:
78+
- api_hasura_admin_secret is not defined
5179

5280
- name: write hasura admin password to secrets directory
5381
copy:
@@ -57,6 +85,8 @@
5785
owner: "{{ fworch_user }}"
5886
group: "{{ fworch_group }}"
5987
become: true
88+
when:
89+
- installation_mode != "upgrade" or not (api_use_existing_hasura_on_upgrade | default(false) | bool) or not hasura_admin_secret_file.stat.exists
6090

6191
- name: check for existing hasura cli file
6292
stat:
@@ -81,7 +111,9 @@
81111
retries: 3
82112
delay: 5
83113
until: hasura_release.status | default(-1) == 200
84-
when: not api_cli_check.stat.exists
114+
when:
115+
- not api_cli_check.stat.exists
116+
- not api_use_existing_hasura_on_upgrade | default(false) | bool
85117

86118
- name: Extract Hasura CLI asset id for {{ linux_architecture }}
87119
set_fact:
@@ -95,6 +127,7 @@
95127
}}
96128
when:
97129
- not api_cli_check.stat.exists
130+
- not api_use_existing_hasura_on_upgrade | default(false) | bool
98131
- hasura_release.status | default(-1) == 200
99132

100133
- name: download {{ api_hasura_version }} hasura cli binary via authenticated GitHub access
@@ -114,6 +147,7 @@
114147
become: true
115148
when:
116149
- not api_cli_check.stat.exists
150+
- not api_use_existing_hasura_on_upgrade | default(false) | bool
117151
- hasura_cli_asset_id is defined
118152

119153
- name: download {{ api_hasura_version }} hasura cli binary via direct GitHub download
@@ -132,6 +166,7 @@
132166
become: true
133167
when:
134168
- not api_cli_check.stat.exists
169+
- not api_use_existing_hasura_on_upgrade | default(false) | bool
135170
- hasura_cli_asset_id is not defined
136171

137172
- name: initialize hasura cli directory
@@ -141,7 +176,9 @@
141176
become: true
142177
become_user: "{{ fworch_user }}"
143178
environment: "{{ proxy_env }}"
144-
when: not api_cli_check.stat.exists
179+
when:
180+
- not api_cli_check.stat.exists
181+
- not api_use_existing_hasura_on_upgrade | default(false) | bool
145182

146183
- name: set hasura env variable
147184
set_fact:
@@ -177,6 +214,22 @@
177214
var: hasura_env
178215
when: debug_level > '1'
179216

217+
- name: get existing hasura container info
218+
docker_container_info:
219+
name: "{{ api_container_name }}"
220+
register: existing_hasura_container_info
221+
become: true
222+
become_user: "{{ fworch_user }}"
223+
224+
- name: set hasura container reuse mode
225+
set_fact:
226+
api_reuse_existing_hasura_container: >-
227+
{{
228+
installation_mode == "upgrade"
229+
and (api_use_existing_hasura_on_upgrade | default(false) | bool)
230+
and (existing_hasura_container_info.exists | default(false) | bool)
231+
}}
232+
180233
- name: request Docker Hub token for hasura/graphql-engine
181234
uri:
182235
url: "https://auth.docker.io/token?service=registry.docker.io&scope=repository:hasura/graphql-engine:pull"
@@ -185,6 +238,7 @@
185238
register: dockerhub_token
186239
environment: "{{ proxy_env }}"
187240
failed_when: dockerhub_token.status | default(-1) != 200
241+
when: not api_reuse_existing_hasura_container | bool
188242

189243
- name: check Docker Hub manifest access for hasura/graphql-engine:{{ api_hasura_version }}
190244
uri:
@@ -198,6 +252,7 @@
198252
register: dockerhub_manifest_check
199253
environment: "{{ proxy_env }}"
200254
failed_when: false
255+
when: not api_reuse_existing_hasura_container | bool
201256

202257
- name: fail if Docker Hub manifest access is blocked
203258
fail:
@@ -206,7 +261,20 @@
206261
(HTTP {{ dockerhub_manifest_check.status | default('unknown') }}). This typically indicates
207262
blocked registry access or proxy restrictions. Ensure the host can reach registry-1.docker.io
208263
or configure a registry mirror.
209-
when: dockerhub_manifest_check.status | default(0) != 200
264+
when:
265+
- not api_reuse_existing_hasura_container | bool
266+
- dockerhub_manifest_check.status | default(0) != 200
267+
268+
- name: start existing hasura container during upgrade
269+
docker_container:
270+
name: "{{ api_container_name }}"
271+
state: started
272+
container_default_behavior: no_defaults
273+
register: docker_return
274+
become: true
275+
become_user: "{{ fworch_user }}"
276+
environment: "{{ proxy_env }}"
277+
when: api_reuse_existing_hasura_container | bool
210278

211279
- name: start hasura container
212280
docker_container:
@@ -230,6 +298,7 @@
230298
become: true
231299
become_user: "{{ fworch_user }}"
232300
environment: "{{ proxy_env }}"
301+
when: not api_reuse_existing_hasura_container | bool
233302

234303
- name: show docker result
235304
debug:

roles/api/tasks/main.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,42 @@
88
- api handler
99
when: installation_mode == "upgrade"
1010

11+
- name: set default hasura upgrade mode for upgrades
12+
set_fact:
13+
api_use_existing_hasura_on_upgrade: "{{ api_keep_existing_hasura_on_upgrade | default(false) | bool }}"
14+
when: installation_mode == "upgrade"
15+
16+
- name: probe GitHub release access for hasura upgrade
17+
uri:
18+
url: "https://api.github.com/repos/hasura/graphql-engine/releases/tags/{{ api_hasura_version }}"
19+
method: GET
20+
return_content: false
21+
register: api_hasura_release_access
22+
environment: "{{ proxy_env }}"
23+
failed_when: false
24+
when:
25+
- installation_mode == "upgrade"
26+
- not api_use_existing_hasura_on_upgrade | bool
27+
28+
- name: fallback to existing hasura when GitHub is not reachable during upgrade
29+
set_fact:
30+
api_use_existing_hasura_on_upgrade: true
31+
when:
32+
- installation_mode == "upgrade"
33+
- not api_use_existing_hasura_on_upgrade | bool
34+
- api_hasura_release_access.status | default(0) != 200
35+
36+
- name: show hasura upgrade fallback decision
37+
debug:
38+
msg: >-
39+
GitHub release lookup failed (HTTP {{ api_hasura_release_access.status | default('unknown') }}),
40+
reusing existing Hasura container and upgrading metadata only.
41+
when:
42+
- installation_mode == "upgrade"
43+
- api_use_existing_hasura_on_upgrade | bool
44+
- api_hasura_release_access is defined
45+
- api_hasura_release_access.status | default(0) != 200
46+
1147
- name: stop MW for upgrading
1248
ansible.builtin.systemd:
1349
name: "{{ product_name }}-middleware"
@@ -20,7 +56,7 @@
2056
name: "{{ api_service_name }}"
2157
state: stopped
2258
become: true
23-
when: installation_mode == "upgrade"
59+
when: installation_mode == "upgrade" and not (api_use_existing_hasura_on_upgrade | default(false) | bool)
2460
failed_when: false
2561

2662
- name: stop API container for upgrading
@@ -30,7 +66,7 @@
3066
container_default_behavior: no_defaults
3167
become: true
3268
become_user: "{{ fworch_user }}"
33-
when: installation_mode == "upgrade"
69+
when: installation_mode == "upgrade" and not (api_use_existing_hasura_on_upgrade | default(false) | bool)
3470
failed_when: false
3571

3672
- name: stop UI for upgrading
@@ -58,6 +94,7 @@
5894
path: "{{ api_home }}"
5995
state: absent
6096
become: true
97+
when: installation_mode != "upgrade" or not (api_use_existing_hasura_on_upgrade | default(false) | bool)
6198

6299
- name: create api home
63100
file:

0 commit comments

Comments
 (0)