|
39 | 39 | group: "{{ postgres_group }}" |
40 | 40 | become: true |
41 | 41 |
|
| 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 | + |
42 | 66 | - name: set static hasura admin pwd for test purposes only |
43 | 67 | set_fact: |
44 | 68 | 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 |
46 | 73 |
|
47 | 74 | - name: set random hasura admin password |
48 | 75 | set_fact: |
49 | 76 | 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 |
51 | 79 |
|
52 | 80 | - name: write hasura admin password to secrets directory |
53 | 81 | copy: |
|
57 | 85 | owner: "{{ fworch_user }}" |
58 | 86 | group: "{{ fworch_group }}" |
59 | 87 | 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 |
60 | 90 |
|
61 | 91 | - name: check for existing hasura cli file |
62 | 92 | stat: |
|
81 | 111 | retries: 3 |
82 | 112 | delay: 5 |
83 | 113 | 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 |
85 | 117 |
|
86 | 118 | - name: Extract Hasura CLI asset id for {{ linux_architecture }} |
87 | 119 | set_fact: |
|
95 | 127 | }} |
96 | 128 | when: |
97 | 129 | - not api_cli_check.stat.exists |
| 130 | + - not api_use_existing_hasura_on_upgrade | default(false) | bool |
98 | 131 | - hasura_release.status | default(-1) == 200 |
99 | 132 |
|
100 | 133 | - name: download {{ api_hasura_version }} hasura cli binary via authenticated GitHub access |
|
114 | 147 | become: true |
115 | 148 | when: |
116 | 149 | - not api_cli_check.stat.exists |
| 150 | + - not api_use_existing_hasura_on_upgrade | default(false) | bool |
117 | 151 | - hasura_cli_asset_id is defined |
118 | 152 |
|
119 | 153 | - name: download {{ api_hasura_version }} hasura cli binary via direct GitHub download |
|
132 | 166 | become: true |
133 | 167 | when: |
134 | 168 | - not api_cli_check.stat.exists |
| 169 | + - not api_use_existing_hasura_on_upgrade | default(false) | bool |
135 | 170 | - hasura_cli_asset_id is not defined |
136 | 171 |
|
137 | 172 | - name: initialize hasura cli directory |
|
141 | 176 | become: true |
142 | 177 | become_user: "{{ fworch_user }}" |
143 | 178 | 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 |
145 | 182 |
|
146 | 183 | - name: set hasura env variable |
147 | 184 | set_fact: |
|
177 | 214 | var: hasura_env |
178 | 215 | when: debug_level > '1' |
179 | 216 |
|
| 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 | +
|
180 | 233 | - name: request Docker Hub token for hasura/graphql-engine |
181 | 234 | uri: |
182 | 235 | url: "https://auth.docker.io/token?service=registry.docker.io&scope=repository:hasura/graphql-engine:pull" |
|
185 | 238 | register: dockerhub_token |
186 | 239 | environment: "{{ proxy_env }}" |
187 | 240 | failed_when: dockerhub_token.status | default(-1) != 200 |
| 241 | + when: not api_reuse_existing_hasura_container | bool |
188 | 242 |
|
189 | 243 | - name: check Docker Hub manifest access for hasura/graphql-engine:{{ api_hasura_version }} |
190 | 244 | uri: |
|
198 | 252 | register: dockerhub_manifest_check |
199 | 253 | environment: "{{ proxy_env }}" |
200 | 254 | failed_when: false |
| 255 | + when: not api_reuse_existing_hasura_container | bool |
201 | 256 |
|
202 | 257 | - name: fail if Docker Hub manifest access is blocked |
203 | 258 | fail: |
|
206 | 261 | (HTTP {{ dockerhub_manifest_check.status | default('unknown') }}). This typically indicates |
207 | 262 | blocked registry access or proxy restrictions. Ensure the host can reach registry-1.docker.io |
208 | 263 | 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 |
210 | 278 |
|
211 | 279 | - name: start hasura container |
212 | 280 | docker_container: |
|
230 | 298 | become: true |
231 | 299 | become_user: "{{ fworch_user }}" |
232 | 300 | environment: "{{ proxy_env }}" |
| 301 | + when: not api_reuse_existing_hasura_container | bool |
233 | 302 |
|
234 | 303 | - name: show docker result |
235 | 304 | debug: |
|
0 commit comments