Skip to content

Commit 8b7ba62

Browse files
authored
Merge pull request #3912 from tpurschke/fix/develop/new-docker-syntax
develop - fix play for docker start (no ports and no pull)
2 parents 6229897 + 27bf26b commit 8b7ba62

File tree

1 file changed

+105
-109
lines changed

1 file changed

+105
-109
lines changed

roles/api/tasks/hasura-install.yml

Lines changed: 105 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -2,209 +2,205 @@
22

33
- name: Install packages for python pip3 n virtualenv
44
package:
5-
name: "{{ item }}"
6-
state: present
5+
name: "{{ item }}"
6+
state: present
77
loop:
8-
- python3-pip
9-
- python3-virtualenv
10-
- python3-docker
8+
- python3-pip
9+
- python3-virtualenv
10+
- python3-docker
1111
become: true
1212

1313
- name: read dbadmin pwd from secrets file
1414
slurp:
15-
src: "{{ dbadmin_password_file }}"
15+
src: "{{ dbadmin_password_file }}"
1616
register: api_user_password
1717
become: true
1818

1919
- name: decode dbadmin pwd
2020
set_fact:
21-
api_user_password: "{{ api_user_password['content'] | b64decode | trim }}"
21+
api_user_password: "{{ api_user_password['content'] | b64decode | trim }}"
2222

2323
- name: read jwt public key from file as JWT secret
2424
slurp:
25-
src: "{{ jwt_public_key_file }}"
25+
src: "{{ jwt_public_key_file }}"
2626
register: api_hasura_jwt_secret_dict
2727
become: true
2828

2929
- name: decode key
3030
set_fact:
31-
api_hasura_jwt_secret: "{{ api_hasura_jwt_secret_dict['content'] | b64decode }}"
31+
api_hasura_jwt_secret: "{{ api_hasura_jwt_secret_dict['content'] | b64decode }}"
3232

3333
- name: make sure {{ fworch_secrets_dir }} exists
3434
file:
35-
path: "{{ fworch_secrets_dir }}"
36-
state: directory
37-
mode: "0750"
38-
owner: "{{ fworch_user }}"
39-
group: "{{ postgres_group }}"
35+
path: "{{ fworch_secrets_dir }}"
36+
state: directory
37+
mode: "0750"
38+
owner: "{{ fworch_user }}"
39+
group: "{{ postgres_group }}"
4040
become: true
4141

4242
- name: set static hasura admin pwd for test purposes only
4343
set_fact:
44-
api_hasura_admin_secret: "{{ api_hasura_admin_test_password }}"
44+
api_hasura_admin_secret: "{{ api_hasura_admin_test_password }}"
4545
when: testkeys is defined and testkeys|bool
4646

4747
- name: set random hasura admin password
4848
set_fact:
49-
api_hasura_admin_secret: "{{ randomly_generated_pwd }}"
49+
api_hasura_admin_secret: "{{ randomly_generated_pwd }}"
5050
when: testkeys is not defined or not testkeys|bool
5151

5252
- name: write hasura admin password to secrets directory
5353
copy:
54-
content: "{{ api_hasura_admin_secret }}\n"
55-
dest: "{{ fworch_secrets_dir }}/hasura_admin_pwd"
56-
mode: '0600'
57-
owner: "{{ fworch_user }}"
58-
group: "{{ fworch_group }}"
54+
content: "{{ api_hasura_admin_secret }}\n"
55+
dest: "{{ fworch_secrets_dir }}/hasura_admin_pwd"
56+
mode: "0600"
57+
owner: "{{ fworch_user }}"
58+
group: "{{ fworch_group }}"
5959
become: true
6060

6161
- name: check for existing hasura cli file
6262
stat:
63-
path: "{{ api_hasura_cli_bin }}"
63+
path: "{{ api_hasura_cli_bin }}"
6464
register: api_cli_check
6565

6666
# only download new version of api cli, when not restoring from backup:
6767
- name: download {{ api_hasura_version }} hasura cli binary
6868
get_url:
69-
url: "https://github.com/hasura/graphql-engine/releases/download/{{ api_hasura_version }}/cli-hasura-linux-amd64"
70-
dest: "{{ api_hasura_cli_bin }}"
71-
force: true
72-
mode: "0755"
73-
owner: "{{ fworch_user }}"
74-
group: "{{ fworch_group }}"
69+
url: "https://github.com/hasura/graphql-engine/releases/download/{{ api_hasura_version }}/cli-hasura-linux-amd64"
70+
dest: "{{ api_hasura_cli_bin }}"
71+
force: true
72+
mode: "0755"
73+
owner: "{{ fworch_user }}"
74+
group: "{{ fworch_group }}"
7575
environment: "{{ proxy_env }}"
7676
become: true
77-
when: not api_cli_check.stat.exists
77+
when: not api_cli_check.stat.exists
7878

7979
- name: initialize hasura cli directory
8080
command: "{{ api_hasura_cli_bin }} init {{ product_name }} --skip-update-check --endpoint http://{{ api_local_listening_ip_address }}:{{ api_port }} --admin-secret {{ api_hasura_admin_secret }}"
81-
args:
82-
chdir: "{{ api_home }}"
81+
args:
82+
chdir: "{{ api_home }}"
8383
become: true
8484
become_user: "{{ fworch_user }}"
8585
environment: "{{ proxy_env }}"
8686
when: not api_cli_check.stat.exists
8787

8888
- name: set hasura env variable
8989
set_fact:
90-
hasura_env:
91-
HASURA_GRAPHQL_DATABASE_URL: "postgres://{{ api_user }}:{{ api_user_password }}@{{ fworch_db_host }}:{{ fworch_db_port }}/{{ fworch_db_name }}"
92-
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
93-
HASURA_GRAPHQL_ENABLE_TELEMETRY: "false"
94-
HASURA_GRAPHQL_ADMIN_SECRET: "{{ api_hasura_admin_secret }}"
95-
HASURA_GRAPHQL_SERVER_HOST: "127.0.0.1"
96-
HASURA_GRAPHQL_SERVER_PORT: "8080"
97-
HASURA_GRAPHQL_LOG_LEVEL: "{{ api_log_level }}"
98-
HASURA_GRAPHQL_ENABLED_LOG_TYPES: '{{ api_HASURA_GRAPHQL_ENABLED_LOG_TYPES }}'
99-
HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: "/srv/console-assets"
100-
HASURA_GRAPHQL_V1_BOOLEAN_NULL_COLLAPSE: "true"
101-
HASURA_GRAPHQL_CORS_DOMAIN: "*"
102-
HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS: "{{ api_HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS }}"
103-
HASURA_GRAPHQL_JWT_SECRET: '
104-
{
105-
"type": "{{ api_hasura_jwt_alg|quote }}",
106-
"key": "{{ api_hasura_jwt_secret | regex_replace(''\n'', ''\\n'') }}",
107-
"claims_namespace_path": "$"
108-
}
109-
'
110-
HTTP_PROXY: "{{ http_proxy }}"
111-
HTTPS_PROXY: "{{ https_proxy }}"
112-
http_proxy: "{{ http_proxy }}"
113-
https_proxy: "{{ https_proxy }}"
114-
no_proxy: "{{ no_proxy }}"
115-
NO_PROXY: "{{ no_proxy }}"
90+
hasura_env:
91+
HASURA_GRAPHQL_DATABASE_URL: "postgres://{{ api_user }}:{{ api_user_password }}@{{ fworch_db_host }}:{{ fworch_db_port }}/{{ fworch_db_name }}"
92+
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
93+
HASURA_GRAPHQL_ENABLE_TELEMETRY: "false"
94+
HASURA_GRAPHQL_ADMIN_SECRET: "{{ api_hasura_admin_secret }}"
95+
HASURA_GRAPHQL_SERVER_HOST: "127.0.0.1"
96+
HASURA_GRAPHQL_SERVER_PORT: "8080"
97+
HASURA_GRAPHQL_LOG_LEVEL: "{{ api_log_level }}"
98+
HASURA_GRAPHQL_ENABLED_LOG_TYPES: "{{ api_HASURA_GRAPHQL_ENABLED_LOG_TYPES }}"
99+
HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: "/srv/console-assets"
100+
HASURA_GRAPHQL_V1_BOOLEAN_NULL_COLLAPSE: "true"
101+
HASURA_GRAPHQL_CORS_DOMAIN: "*"
102+
HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS: "{{ api_HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS }}"
103+
HASURA_GRAPHQL_JWT_SECRET: '
104+
{
105+
"type": "{{ api_hasura_jwt_alg|quote }}",
106+
"key": "{{ api_hasura_jwt_secret | regex_replace(''\n'', ''\\n'') }}",
107+
"claims_namespace_path": "$"
108+
}
109+
'
110+
HTTP_PROXY: "{{ http_proxy }}"
111+
HTTPS_PROXY: "{{ https_proxy }}"
112+
http_proxy: "{{ http_proxy }}"
113+
https_proxy: "{{ https_proxy }}"
114+
no_proxy: "{{ no_proxy }}"
115+
NO_PROXY: "{{ no_proxy }}"
116116

117117
- name: show hasura env for debugging
118118
debug:
119-
var:
120-
hasura_env
119+
var: hasura_env
121120
when: debug_level > '1'
122121

123122
- name: start hasura container
124123
docker_container:
125-
name: "{{ api_container_name }}"
126-
image: hasura/graphql-engine:{{ api_hasura_version }}
127-
state: started
128-
network_mode: host
129-
networks_cli_compatible: true
130-
log_driver: syslog
131-
log_options:
132-
syslog-address: "{{ syslog_proto }}://{{ syslog_host }}:{{ syslog_port }}"
133-
syslog-facility: daemon
134-
tag: "{{ api_container_name }}"
135-
recreate: true
136-
exposed_ports:
137-
- "{{ api_port }}:{{ api_port }}"
138-
env:
139-
"{{ hasura_env }}"
140-
container_default_behavior: no_defaults
141-
user: "1001:1001" # hasura user and group id
124+
name: "{{ api_container_name }}"
125+
image: hasura/graphql-engine:{{ api_hasura_version }}
126+
state: started
127+
network_mode: host
128+
networks_cli_compatible: true
129+
log_driver: syslog
130+
log_options:
131+
syslog-address: "{{ syslog_proto }}://{{ syslog_host }}:{{ syslog_port }}"
132+
syslog-facility: daemon
133+
tag: "{{ api_container_name }}"
134+
recreate: true
135+
env: "{{ hasura_env }}"
136+
container_default_behavior: no_defaults
137+
user: "1001:1001" # hasura user and group id
138+
pull: no
142139
register: docker_return
143140
become: true
144141
become_user: "{{ fworch_user }}"
145142
environment: "{{ proxy_env }}"
146143

147144
- name: show docker result
148145
debug:
149-
var:
150-
docker_return
146+
var: docker_return
151147
when: debug_level > '1'
152148

153149
- name: Get info on container
154150
docker_container_info:
155-
name: "{{ api_container_name }}"
151+
name: "{{ api_container_name }}"
156152
register: result
157153
become: true
158154
become_user: "{{ fworch_user }}"
159155

160156
- name: Print the status of the container in case of problems only
161-
fail:
162-
msg: "The container status is: {{ result }}"
157+
fail:
158+
msg: "The container status is: {{ result }}"
163159
when: result.exists and result.container['State']['Status'] == 'exited'
164160

165161
- name: copy hasura systemd service script
166162
template:
167-
src: "{{ api_service_name }}.service.j2"
168-
dest: "/lib/systemd/system/{{ api_service_name }}.service"
169-
backup: true
170-
mode: "0644"
171-
owner: "root"
163+
src: "{{ api_service_name }}.service.j2"
164+
dest: "/lib/systemd/system/{{ api_service_name }}.service"
165+
backup: true
166+
mode: "0644"
167+
owner: "root"
172168
become: true
173169

174170
- name: make hasura docker container run at host startup
175171
systemd:
176-
name: "{{ api_service_name }}"
177-
daemon_reload: true
178-
enabled: true
172+
name: "{{ api_service_name }}"
173+
daemon_reload: true
174+
enabled: true
179175
become: true
180176

181-
- name: wait for hasura port to become available
177+
- name: wait for hasura port to become available
182178
wait_for:
183-
port: "{{ api_port }}"
184-
host: "{{ api_local_listening_ip_address }}"
185-
connect_timeout: 1
186-
delay: 10
187-
timeout: 25
179+
port: "{{ api_port }}"
180+
host: "{{ api_local_listening_ip_address }}"
181+
connect_timeout: 1
182+
delay: 10
183+
timeout: 25
188184

189185
- name: check for existing api dir from restore
190186
stat:
191-
path: "{{ api_home }}/{{ product_name }}"
187+
path: "{{ api_home }}/{{ product_name }}"
192188
register: api_metadata_check
193189

194190
- name: import API metadata via metadata API directly from local file
195-
uri:
196-
url: "http://{{ api_local_listening_ip_address }}:{{ api_port }}/v1/metadata"
197-
method: POST
198-
return_content: true
199-
body_format: json
200-
headers:
201-
Content-Type: application/json
202-
x-hasura-admin-secret: "{{ api_hasura_admin_secret }}"
203-
x-hasura-role: "admin"
204-
body: "{{ lookup('file','replace_metadata.json') | from_json }}"
191+
uri:
192+
url: "http://{{ api_local_listening_ip_address }}:{{ api_port }}/v1/metadata"
193+
method: POST
194+
return_content: true
195+
body_format: json
196+
headers:
197+
Content-Type: application/json
198+
x-hasura-admin-secret: "{{ api_hasura_admin_secret }}"
199+
x-hasura-role: "admin"
200+
body: "{{ lookup('file','replace_metadata.json') | from_json }}"
205201
when: not api_rollback_is_running | bool
206202
# do not install latest metadata in case of rollback
207203
environment:
208-
http_proxy: ""
209-
https_proxy: ""
210-
# do not use http proxy for metadata import
204+
http_proxy: ""
205+
https_proxy: ""
206+
# do not use http proxy for metadata import

0 commit comments

Comments
 (0)