Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support routes from the api in environment variables #2940

Merged
merged 10 commits into from
Nov 29, 2021
495 changes: 3 additions & 492 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh

Large diffs are not rendered by default.

360 changes: 360 additions & 0 deletions images/kubectl-build-deploy-dind/scripts/exec-routes-generation.sh

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions tests/tasks/api/add-environment-variable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
- name: "{{ testname }} - POST api add envVariable with target project {{ project }} to {{ graphql_url }}"
block:
- include: admin-token.yaml
- name: "{{ testname }} - POST api get project by name with target project {{ project }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ admin_token }}"
body_format: json
body: '{ "query": "query($project: String!) {projectByName(name:$project){id,name}}", "variables": {"project":"{{ project }}"}}'
register: apiresponse

- name: "{{ testname }} - POST api get project by name with target project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"

- name: "{{ testname }} - save project id as fact"
set_fact:
project_id: "{{ apiresponse.json.data.projectByName.id }}"
envType: ENVIRONMENT

- name: "{{ testname }} - POST api get environment by name with target project {{ project }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ admin_token }}"
body_format: json
body: '{ "query": "query($branch: String!, $project: Int!) {environmentByName(name:$branch, project:$project){id,name}}", "variables": {"branch":"{{ branch }}", "project":{{ project_id }}}}'
register: apiresponse

- name: "{{ testname }} - POST api get environment by name with target project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"

- name: "{{ testname }} - save project id as fact"
set_fact:
project_id: "{{ apiresponse.json.data.environmentByName.id }}"
envType: ENVIRONMENT

- name: "{{ testname }} - POST api add envVariable with target environment {{ branch }} on project {{ project }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ admin_token }}"
body_format: json
body:
query: '{{ lookup("template", "./add-variable.gql") }}'
register: apiresponse

- name: "{{ testname }} - POST api add envVariable with target project {{ project }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"
64 changes: 64 additions & 0 deletions tests/tasks/api/delete-environment-variable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
- name: "{{ testname }} - POST api delete envVariable with target project {{ project }} to {{ graphql_url }}"
block:
- include: refresh-token.yaml
- name: "{{ testname }} - POST api get project by name with target project {{ project }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ token }}"
body_format: json
body: '{ "query": "query($project: String!) {projectByName(name:$project){id,name}}", "variables": {"project":"{{ project }}"}}'
register: apiresponse

- name: "{{ testname }} - POST api get project by name with target project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"

- name: "{{ testname }} - save project id as fact"
set_fact:
project_id: "{{ apiresponse.json.data.projectByName.id }}"
envType: ENVIRONMENT

- name: "{{ testname }} - POST api get project by name with target environment {{ branch }} project {{ project }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ token }}"
body_format: json
body: '{ "query": "query($branch: String!, $project: Int!) {environmentByName(name:$branch, project:$project){id,name,envVariables{id,name}}}", "variables": {"branch":"{{ branch }}", "project":{{ project_id }}}}'
register: apiresponse

- name: "{{ testname }} - POST api get project by name with target environment {{ branch }} project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"

- name: "{{ testname }} - POST api get project by name with target environment {{ branch }} project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json | community.general.json_query(query) }}"
vars:
query: 'data.environmentByName.envVariables[?name==`{{ envName }}`].id | [0]'

- name: "{{ testname }} - set envvar id to fact"
set_fact:
env_var_id: "{{ apiresponse.json | community.general.json_query(query) }}"
vars:
query: 'data.environmentByName.envVariables[?name==`{{ envName }}`].id | [0]'

- name: "{{ testname }} - POST api delete envVariable with target project {{ project }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ token }}"
body_format: json
body:
query: '{{ lookup("template", "./delete-variable.gql") }}'
register: apiresponse
when: env_var_id != ""

- name: "{{ testname }} - POST api delete envVariable with target project {{ project }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"
when: env_var_id != ""
10 changes: 10 additions & 0 deletions tests/tests/nginx/check-first.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
- name: "{{ testname }} - check if custom domain 'test1.example.com' is not added from the environment variables"
hosts: localhost
serial: 1
vars:
url: "https://nginx-basic-auth.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix_https }}"
host: "test1.example.com"
expected_returncode: "{{ del_status_code }}"
tasks:
- include: ../../checks/check-url-returncode-host.yaml

- name: "{{ testname }} - check if {{ project }} is deployed with searching for 'Hello World!'"
hosts: localhost
serial: 1
Expand Down
9 changes: 9 additions & 0 deletions tests/tests/nginx/check-third.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: "{{ testname }} - THIRD TEST: check if custom domain 'test1.example.com' is added from the environment variables"
hosts: localhost
serial: 1
vars:
url: "https://nginx-basic-auth.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix_https }}"
host: "test1.example.com"
expected_returncode: 200
tasks:
- include: ../../checks/check-url-returncode-host.yaml
37 changes: 37 additions & 0 deletions tests/tests/nginx/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
- include: ../../tasks/git-init.yaml
- include: ../../tasks/git-add-commit-push.yaml

# delete the LAGOON_ROUTES_JSON envvar if it exists already
- name: "{{ testname }} - api delete envVariable on {{ project }}"
hosts: localhost
serial: 1
vars:
envName: "LAGOON_ROUTES_JSON"
project: "{{ project }}"
tasks:
- include: ../../tasks/api/delete-environment-variable.yaml

- name: "{{ testname }} - api deployEnvironmentBranch on {{ project }}, which should deploy the first commit"
hosts: localhost
serial: 1
Expand Down Expand Up @@ -46,6 +56,33 @@
expected_branch: "{{ branch }}"
project: "{{ project }}"

- name: "{{ testname }} - api add envVariable on {{ project }} environment {{ branch }}"
hosts: localhost
serial: 1
vars:
project: "{{ project }}"
branch: "{{ branch }}"
envName: "LAGOON_ROUTES_JSON"
envValue: "eyJyb3V0ZXMiOlt7ImRvbWFpbiI6InRlc3QxLmV4YW1wbGUuY29tIiwic2VydmljZSI6Im5naW54IiwidGxzLWFjbWUiOmZhbHNlLCJtb25pdG9yaW5nLXBhdGgiOiIvYnlwYXNzLWNhY2hlIn1dfQo="
envScope: "BUILD"
tasks:
- include: ../../tasks/api/add-environment-variable.yaml

- name: "{{ testname }} - api deployEnvironmentBranch on {{ project }}, which should deploy the second commit again but with the LAGOON_ROUTES_JSON override"
hosts: localhost
serial: 1
vars:
branch: "{{ branch }}"
project: "{{ project }}"
tasks:
- include: ../../tasks/api/deploy-no-sha.yaml

- include: check-third.yaml
vars:
expected_head: "{{ current_head }}"
expected_branch: "{{ branch }}"
project: "{{ project }}"

- name: "{{ testname }} - api deleteEnvironment on {{ project }}, which should remove all resources"
hosts: localhost
serial: 1
Expand Down