Skip to content

Commit 2bf1936

Browse files
korlaxxalrokvishakha1812
authored andcommitted
Finalize production config for google_health deployment (#165)
* Switch to midas export dir * Properly rename Jenkins pipeline stage scripts * Handle google_health's testing needs - Add: Ansible playbook for securely handling placing the `params.json` template we need for testing. This will happen during the Jenkins build stage when we are setting up the venv in the workspace on the Jenkins server. - Add: Test `params.json` template. - Add: Jenkins user variable. - Fix: Was incorrectly trying to use a file instead of a template in `ansible-deploy.yaml`. - Add: Call the small Ansible playbook from the Jenkins build wrapper. * Change to the Ansible root dir before trying to do Ansible things * Delegate to localhost * Tell Ansible we want to connect locally for this playbook * Remove set -x from Bash scripts * used set instead of list to compare dict.keys() (#186) Co-authored-by: Vishakha Srivastava <[email protected]>
1 parent bd57752 commit 2bf1936

11 files changed

+63
-29
lines changed

ansible/ansible-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
when: file.stat.exists
3737

3838
- name: Set production params template.
39-
copy:
39+
template:
4040
src: templates/{{ indicator }}-params-prod.json.j2
4141
dest: "{{ indicators_runtime_dir }}/{{ indicator }}/params.json"
4242
owner: "{{ runtime_user }}"

ansible/google_health-build.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- hosts: localhost
3+
connection: local
4+
vars_files:
5+
- vars.yaml
6+
- vault.yaml
7+
tasks:
8+
- name: Set test params template.
9+
template:
10+
src: templates/{{ indicator }}-params-test.json.j2
11+
dest: "{{ workspace }}/{{ indicator }}/tests/params.json"
12+
owner: "{{ jenkins_user }}"
13+
group: "{{ jenkins_user }}"
14+
mode: "0644"
15+
delegate_to: localhost

ansible/templates/google_health-params-prod.json.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"static_file_dir": "./static",
3-
"export_dir": "./receiving",
3+
"export_dir": "/common/covidcast/receiving/ght",
44
"cache_dir": "./cache",
55
"start_date": "2020-02-01",
66
"end_date": "",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"static_file_dir": "../static",
3+
"export_dir": "./receiving",
4+
"cache_dir": "../cache",
5+
"start_date": "2020-02-11",
6+
"end_date": "2020-04-30",
7+
"ght_key": "{{ google_health_api_key }}"
8+
}

ansible/vars.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
runtime_user: "indicators"
3+
jenkins_user: "jenkins"
34
jenkins_artifact_dir: "/var/lib/jenkins/artifacts"
45
indicators_runtime_dir: "/home/{{ runtime_user }}/runtime"
5-
package: "{{ indicator }}.tar.gz" # This is passed in the Ansible invocation.
6+
package: "{{ indicator }}.tar.gz" # {{ indicator }} is passed in from the Jenkins shell script wrapper.
67
python_version: "3.8.2"
78
pyenv_python_path: "/home/{{ runtime_user }}/.pyenv/versions/{{ python_version }}/bin/python"
89

google_health/tests/test_pull_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_class_state(self):
3636
]
3737

3838
assert len(res["lines"][0]["points"]) == 2
39-
assert [x for x in res["lines"][0]["points"][0].keys()] == ["date", "value"]
39+
assert set([x for x in res["lines"][0]["points"][0].keys()]) == ["date", "value"]
4040
assert res["lines"][0]["points"][0]["date"] == "May 05 2020"
4141
assert res["lines"][0]["points"][1]["date"] == "May 06 2020"
4242

@@ -55,7 +55,7 @@ def test_class_dma(self):
5555
]
5656

5757
assert len(res["lines"][0]["points"]) == 2
58-
assert [x for x in res["lines"][0]["points"][0].keys()] == ["date", "value"]
58+
assert set([x for x in res["lines"][0]["points"][0].keys()]) == ["date", "value"]
5959
assert res["lines"][0]["points"][0]["date"] == "May 05 2020"
6060
assert res["lines"][0]["points"][1]["date"] == "May 06 2020"
6161

jenkins/google_health-jenkins-build copy.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
#
3+
# JHU: Jenkins build
4+
#
5+
6+
set -eo pipefail
7+
source ~/.bash_profile
8+
9+
#
10+
# Build
11+
#
12+
13+
local_indicator="google_health"
14+
15+
cd "${WORKSPACE}/${local_indicator}" || exit
16+
17+
# Set up venv
18+
python -m venv env
19+
source env/bin/activate
20+
pip install ../_delphi_utils_python/.
21+
pip install .
22+
23+
# Ansible!
24+
# We need to call some extra Ansible here to handle placing a special params.json
25+
# template so that our tests can complete. The below calls a small playbook that
26+
# runs locally on the build (Jenkins) server to place the file.
27+
28+
cd "${WORKSPACE}/ansible" || exit
29+
30+
ansible-playbook google_health-build.yaml \
31+
--extra-vars "indicator=${local_indicator} workspace=${WORKSPACE}" -i localhost,

jenkins/google_health-jenkins-deploy copy.sh renamed to jenkins/google_health-jenkins-deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Jenkins deploy
44
#
55

6-
set -exo pipefail
6+
set -eo pipefail
77
source ~/.bash_profile
88

99
#

jenkins/google_health-jenkins-package copy.sh renamed to jenkins/google_health-jenkins-package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Jenkins package
44
#
55

6-
set -exo pipefail
6+
set -eo pipefail
77
source ~/.bash_profile
88

99
#

jenkins/google_health-jenkins-test copy.sh renamed to jenkins/google_health-jenkins-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# JHU: Jenkins test
44
#
55

6-
set -exo pipefail
6+
set -eo pipefail
77
source ~/.bash_profile
88

99
#

0 commit comments

Comments
 (0)