Skip to content

Commit bb94a8e

Browse files
committed
Staging -> hotfix/fix_239175
2 parents bf86fd5 + 6c2595b commit bb94a8e

56 files changed

Lines changed: 1142 additions & 5477 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
max-line-length = 120
33
max-complexity = 12
44
max-nesting-depth = 12
5+
cache = true
6+
cache-dir = .flake8-cache
7+
8+
exclude =
9+
.git,
10+
__pycache__,
11+
.venv,
12+
venv,
13+
migrations,
14+
node_modules,
15+
build,
16+
dist
517

618
ignore =
719
# black formatting related
@@ -20,6 +32,6 @@ ignore =
2032
# TODO
2133
# F401,
2234
F403,
23-
35+
2436
per-file-ignores =
2537
tests/extras/testutils/factories/__init__.py: F401

.github/workflows/ci.yml

Lines changed: 175 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -13,193 +13,179 @@ on:
1313
- master
1414

1515
jobs:
16-
build_and_push_dev:
17-
runs-on: ubuntu-latest
18-
steps:
19-
- name: Set up Docker Buildx
20-
uses: docker/setup-buildx-action@v1
21-
- name: Checkout code
22-
uses: actions/checkout@v2
23-
- name: DockerHub login
24-
uses: docker/login-action@v1
25-
with:
26-
username: ${{ secrets.DOCKERHUB_USERNAME }}
27-
password: ${{ secrets.DOCKERHUB_TOKEN }}
28-
29-
- name: Push dev
30-
run: |
31-
docker buildx create --use
32-
docker buildx build \
33-
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-dev \
34-
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-dev \
35-
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-dev \
36-
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-dev \
37-
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev \
38-
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-latest-dev \
39-
-f ./docker/Dockerfile \
40-
--target dev \
41-
--push \
42-
./
43-
44-
black:
45-
runs-on: ubuntu-latest
46-
needs: [build_and_push_dev]
47-
steps:
48-
- name: Checkout code
49-
uses: actions/checkout@v2
50-
- name: DockerHub login
51-
uses: docker/login-action@v1
52-
with:
53-
username: ${{ secrets.DOCKERHUB_USERNAME }}
54-
password: ${{ secrets.DOCKERHUB_TOKEN }}
55-
56-
- name: Check
57-
run: |
58-
docker run --rm -i \
59-
${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev \
60-
black . --check
61-
62-
flake8:
63-
runs-on: ubuntu-latest
64-
needs: [build_and_push_dev]
65-
steps:
66-
- name: Checkout code
67-
uses: actions/checkout@v2
68-
- name: DockerHub login
69-
uses: docker/login-action@v1
70-
with:
71-
username: ${{ secrets.DOCKERHUB_USERNAME }}
72-
password: ${{ secrets.DOCKERHUB_TOKEN }}
73-
74-
- name: Check
75-
run: |
76-
docker run --rm -i \
77-
${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev \
78-
flake8 .
79-
80-
unit_tests:
81-
runs-on: ubuntu-latest
82-
needs: [build_and_push_dev]
83-
steps:
84-
- name: Checkout code
85-
uses: actions/checkout@v2
86-
- name: DockerHub login
87-
uses: docker/login-action@v1
88-
with:
89-
username: ${{ secrets.DOCKERHUB_USERNAME }}
90-
password: ${{ secrets.DOCKERHUB_TOKEN }}
91-
92-
- name: Unit tests
93-
run: |
94-
backend_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev docker compose \
95-
-f ./ops/compose.ci-test.yml \
96-
up --exit-code-from backend
97-
98-
build_and_push_prd:
99-
needs: [build_and_push_dev]
100-
runs-on: ubuntu-latest
101-
steps:
102-
- name: Set up Docker Buildx
103-
uses: docker/setup-buildx-action@v1
104-
- name: Checkout code
105-
uses: actions/checkout@v2
106-
- name: DockerHub login
107-
uses: docker/login-action@v1
108-
with:
109-
username: ${{ secrets.DOCKERHUB_USERNAME }}
110-
password: ${{ secrets.DOCKERHUB_TOKEN }}
111-
112-
- name: Push prd
113-
run: |
114-
docker buildx create --use
115-
116-
# Base part of the command
117-
build_command="docker buildx build \
118-
--progress=plain \
119-
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-dev \
120-
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-dev \
121-
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-prd \
122-
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-prd \
123-
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-prd \
124-
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-prd \
125-
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-prd \
126-
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }} \
127-
-f ./docker/Dockerfile \
128-
--target prd \
129-
--push ./"
130-
131-
if [ "${{ github.ref }}" = "refs/heads/master" ]; then
132-
version=$(python3 -c "import sys; version=None; [version:=line.split('=')[1].strip().strip('\"') for line in open('pyproject.toml', 'r') if line.strip().startswith('version =')]; print(version if version else sys.exit(1))")
133-
tagged_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope:country-report-$version
134-
build_command="$build_command -t $tagged_image"
135-
fi
136-
137-
eval $build_command
138-
139-
trivy:
140-
runs-on: ubuntu-latest
141-
needs: [build_and_push_prd]
142-
steps:
143-
- name: Checkout code
144-
uses: actions/checkout@v2
145-
- name: DockerHub login
146-
uses: docker/login-action@v1
147-
with:
148-
username: ${{ secrets.DOCKERHUB_USERNAME }}
149-
password: ${{ secrets.DOCKERHUB_TOKEN }}
150-
- name: Run Trivy vulnerability scanner
151-
continue-on-error: true # due to getting TOOMANYREQUESTS
152-
uses: aquasecurity/trivy-action@master
153-
with:
154-
image-ref: '${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}'
155-
format: 'table'
156-
exit-code: '0'
157-
ignore-unfixed: true
158-
vuln-type: 'os,library'
159-
severity: 'CRITICAL,HIGH'
160-
161-
deploy:
162-
runs-on: ubuntu-latest
163-
needs: [unit_tests, black, flake8, build_and_push_prd]
164-
if: |
165-
github.event_name == 'push' &&
166-
(
167-
github.ref == 'refs/heads/develop' ||
168-
github.ref == 'refs/heads/staging' ||
169-
github.ref == 'refs/heads/master'
170-
)
171-
steps:
172-
- name: Trigger deploy
173-
run: |
174-
if [ ${{ github.ref }} == 'refs/heads/develop' ]; then
175-
pipelineId=1149
176-
elif [ ${{ github.ref }} == 'refs/heads/staging' ]; then
177-
pipelineId=1286
178-
elif [ ${{ github.ref }} == 'refs/heads/master' ]; then
179-
pipelineId=1483,1233
180-
else
181-
echo "No pipeline to trigger for ref ${{ github.ref }}"
182-
exit 0
183-
fi
16+
build_and_push_dev:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
- name: DockerHub login
24+
uses: docker/login-action@v3
25+
with:
26+
username: ${{ secrets.DOCKERHUB_USERNAME }}
27+
password: ${{ secrets.DOCKERHUB_TOKEN }}
28+
29+
- name: Push dev
30+
run: |
31+
docker buildx create --use
32+
docker buildx build \
33+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-dev \
34+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-dev \
35+
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-dev \
36+
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-dev \
37+
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev \
38+
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-latest-dev \
39+
-f ./docker/Dockerfile \
40+
--target dev \
41+
--push \
42+
./
43+
44+
ruff:
45+
runs-on: ubuntu-latest
46+
needs: [build_and_push_dev]
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v4
50+
- name: DockerHub login
51+
uses: docker/login-action@v3
52+
with:
53+
username: ${{ secrets.DOCKERHUB_USERNAME }}
54+
password: ${{ secrets.DOCKERHUB_TOKEN }}
55+
- name: Ruff Check
56+
run: |
57+
docker run --rm -i \
58+
${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev \
59+
ruff check . --output-format=github
60+
- name: Ruff Format Check
61+
run: |
62+
docker run --rm -i \
63+
${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev \
64+
ruff format . --check
65+
66+
unit_tests:
67+
runs-on: ubuntu-latest
68+
needs: [build_and_push_dev]
69+
steps:
70+
- name: Checkout code
71+
uses: actions/checkout@v4
72+
- name: DockerHub login
73+
uses: docker/login-action@v3
74+
with:
75+
username: ${{ secrets.DOCKERHUB_USERNAME }}
76+
password: ${{ secrets.DOCKERHUB_TOKEN }}
77+
78+
- name: Unit tests
79+
run: |
80+
backend_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-dev docker compose \
81+
-f ./ops/compose.ci-test.yml \
82+
up --exit-code-from backend
83+
84+
build_and_push_prd:
85+
needs: [build_and_push_dev]
86+
runs-on: ubuntu-latest
87+
steps:
88+
- name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@v3
90+
- name: Checkout code
91+
uses: actions/checkout@v4
92+
- name: DockerHub login
93+
uses: docker/login-action@v3
94+
with:
95+
username: ${{ secrets.DOCKERHUB_USERNAME }}
96+
password: ${{ secrets.DOCKERHUB_TOKEN }}
97+
98+
- name: Push prd
99+
run: |
100+
docker buildx create --use
184101
185-
IFS=',' read -ra pipelines <<< "$pipelineId"
186-
for pipeline in "${pipelines[@]}"; do
187-
jsonBody='{"variables": {"sha": {"isSecret": false, "value": "${{ github.sha }}"}, "tag": {"isSecret": false, "value": "country-report-${{ github.sha }}"}}}'
188-
contentLength=$(echo -n $jsonBody | wc -c)
189-
project=ICTD-HCT-MIS
190-
organization=unicef
191-
192-
echo Triggering deploy for pipeline $pipeline
193-
echo JSON body: $jsonBody
194-
195-
curl -f -v -L \
196-
-u ":${{ secrets.AZURE_PAT }}" \
197-
-H "Content-Type: application/json" \
198-
-H "Content-Length: $contentLength" \
199-
-d "$jsonBody" \
200-
https://dev.azure.com/$organization/$project/_apis/pipelines/$pipeline/runs?api-version=7.1-preview.1
201-
if [ $? -ne 0 ]; then
202-
echo "Failed to trigger deploy for pipeline $pipeline"
203-
exit 1
204-
fi
205-
done
102+
# Base part of the command
103+
build_command="docker buildx build \
104+
--progress=plain \
105+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-dev \
106+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-dev \
107+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-prd \
108+
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-prd \
109+
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-${{ github.sha }}-prd \
110+
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-country-report-latest-prd \
111+
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}-prd \
112+
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }} \
113+
-f ./docker/Dockerfile \
114+
--target prd \
115+
--push ./"
116+
117+
if [ "${{ github.ref }}" = "refs/heads/master" ]; then
118+
version=$(python3 -c "import sys; version=None; [version:=line.split('=')[1].strip().strip('\"') for line in open('pyproject.toml', 'r') if line.strip().startswith('version =')]; print(version if version else sys.exit(1))")
119+
tagged_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope:country-report-$version
120+
build_command="$build_command -t $tagged_image"
121+
fi
122+
123+
eval $build_command
124+
125+
trivy:
126+
runs-on: ubuntu-latest
127+
needs: [build_and_push_prd]
128+
steps:
129+
- name: Checkout code
130+
uses: actions/checkout@v2
131+
- name: DockerHub login
132+
uses: docker/login-action@v3
133+
with:
134+
username: ${{ secrets.DOCKERHUB_USERNAME }}
135+
password: ${{ secrets.DOCKERHUB_TOKEN }}
136+
- name: Run Trivy vulnerability scanner
137+
continue-on-error: true # due to getting TOOMANYREQUESTS
138+
uses: aquasecurity/trivy-action@master
139+
with:
140+
image-ref: '${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:country-report-${{ github.sha }}'
141+
format: 'table'
142+
exit-code: '0'
143+
ignore-unfixed: true
144+
vuln-type: 'os,library'
145+
severity: 'CRITICAL,HIGH'
146+
147+
deploy:
148+
runs-on: ubuntu-latest
149+
needs: [unit_tests, ruff, build_and_push_prd]
150+
if: |
151+
github.event_name == 'push' &&
152+
(
153+
github.ref == 'refs/heads/develop' ||
154+
github.ref == 'refs/heads/staging' ||
155+
github.ref == 'refs/heads/master'
156+
)
157+
steps:
158+
- name: Trigger deploy
159+
run: |
160+
if [ ${{ github.ref }} == 'refs/heads/develop' ]; then
161+
pipelineId=1149
162+
elif [ ${{ github.ref }} == 'refs/heads/staging' ]; then
163+
pipelineId=1286
164+
elif [ ${{ github.ref }} == 'refs/heads/master' ]; then
165+
pipelineId=1483,1233
166+
else
167+
echo "No pipeline to trigger for ref ${{ github.ref }}"
168+
exit 0
169+
fi
170+
171+
IFS=',' read -ra pipelines <<< "$pipelineId"
172+
for pipeline in "${pipelines[@]}"; do
173+
jsonBody='{"variables": {"sha": {"isSecret": false, "value": "${{ github.sha }}"}, "tag": {"isSecret": false, "value": "country-report-${{ github.sha }}"}}}'
174+
contentLength=$(echo -n $jsonBody | wc -c)
175+
project=ICTD-HCT-MIS
176+
organization=unicef
177+
178+
echo Triggering deploy for pipeline $pipeline
179+
echo JSON body: $jsonBody
180+
181+
curl -f -v -L \
182+
-u ":${{ secrets.AZURE_PAT }}" \
183+
-H "Content-Type: application/json" \
184+
-H "Content-Length: $contentLength" \
185+
-d "$jsonBody" \
186+
https://dev.azure.com/$organization/$project/_apis/pipelines/$pipeline/runs?api-version=7.1-preview.1
187+
if [ $? -ne 0 ]; then
188+
echo "Failed to trigger deploy for pipeline $pipeline"
189+
exit 1
190+
fi
191+
done

0 commit comments

Comments
 (0)