-
Notifications
You must be signed in to change notification settings - Fork 68
135 lines (127 loc) · 5.49 KB
/
ci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: CI
on:
push
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: mkdir -p repos/undefx
- name: Checkout undefx/py3tester
uses: actions/checkout@v2
with:
repository: undefx/py3tester
path: repos/undefx/py3tester
- name: Checkout undefx/undef-analysis
uses: actions/checkout@v2
with:
repository: undefx/undef-analysis
path: repos/undefx/undef-analysis
- run: mkdir -p repos/delphi
- name: Checkoutcmu-delphi/operations
uses: actions/checkout@v2
with:
repository: cmu-delphi/operations
path: repos/delphi/operations
- name: Checkout cmu-delphi/utils
uses: actions/checkout@v2
with:
repository: cmu-delphi/utils
path: repos/delphi/utils
- name: Checkout cmu-delphi/github-deploy-repo
uses: actions/checkout@v2
with:
repository: cmu-delphi/github-deploy-repo
path: repos/delphi/github-deploy-repo
- name: Checkout THIS REPO
uses: actions/checkout@v2
with:
path: repos/delphi/delphi-epidata
- name: Checkout cmu-delphi/flu-contest
uses: actions/checkout@v2
with:
repository: cmu-delphi/flu-contest
path: repos/delphi/flu-contest
- name: Checkout cmu-delphi/nowcast
uses: actions/checkout@v2
with:
repository: cmu-delphi/nowcast
path: repos/delphi/nowcast
- name: Build docker images
run: |
docker build -t delphi_database -f repos/delphi/operations/dev/docker/database/Dockerfile .
docker build -t delphi_python -f repos/delphi/operations/dev/docker/python/Dockerfile .
docker build -t delphi_database_epidata -f ./repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile .
docker build -t delphi_web_python -f repos/delphi/delphi-epidata/dev/docker/python/Dockerfile .
cd ./repos/delphi/delphi-epidata
docker build -t delphi_web_epidata -f ./devops/Dockerfile .
cd ../../../
- name: Start services
run: |
docker network create --driver bridge delphi-net
docker run --rm -d -p 13306:3306 --network delphi-net --name delphi_database_epidata delphi_database_epidata
docker run --rm -d -p 10080:80 --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb:https://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --network delphi-net --name delphi_web_epidata delphi_web_epidata
docker ps
- run: |
wget https://raw.githubusercontent.com/eficode/wait-for/master/wait-for
chmod +x wait-for
./wait-for localhost:13306 -- echo 'ready'
sleep 10s
- name: Run Unit Tests
run: |
docker run --rm --network delphi-net --env "SQLALCHEMY_DATABASE_URI=mysql+mysqldb:https://user:pass@delphi_database_epidata:3306/epidata" --env "FLASK_SECRET=abc" delphi_web_python python -m pytest --import-mode importlib repos/delphi/delphi-epidata/tests
- name: Run Integration Tests
run: |
docker run --rm --network delphi-net delphi_web_python python -m pytest --import-mode importlib repos/delphi/delphi-epidata/integrations
- name: Clean Up
run: |
docker stop delphi_database_epidata delphi_web_epidata
docker network remove delphi-net
image:
needs: build
# only on main and dev branch
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: cmu-delphi-deploy-machine
password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
- name: Build Image
env:
DEVOPS_DOCKER_FILE: ./devops/Dockerfile
run: |
docker build -t repo --file ${DEVOPS_DOCKER_FILE} .
- name: Resolve Tag
id: tagname
run: |
baseRef="${GITHUB_REF#*/}"
imageTag="${baseRef#*/}"
if [ "$imageTag" = "main" ] ; then
imageTag="latest"
fi
echo "::set-output name=tag::$imageTag"
echo "::set-output name=repo::ghcr.io/${{ github.repository }}"
- name: Push Dev Tag
run: |
docker tag repo ${{ steps.tagname.outputs.repo }}:${{ steps.tagname.outputs.tag }}
docker push ${{ steps.tagname.outputs.repo }}:${{ steps.tagname.outputs.tag }}
# - name: Extract version
# if: startsWith(github.ref, 'refs/heads/main')
# id: extract_version
# run: node -pe "'::set-output name=version::' + require('./package.json').version"
- name: Trigger Webhook
run: |
# trigger a webhook update
curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \
-X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "repository=${{ steps.tagname.outputs.repo }}&tag=${{ steps.tagname.outputs.tag }}"
# - name: Push Version Tag Tag
# if: startsWith(github.ref, 'refs/heads/main')
# run: |
# docker tag repo ${{ steps.tagname.outputs.repo }}:v${{ steps.extract_version.outputs.version }}
# docker push ${{ steps.tagname.outputs.repo }}:v${{ steps.extract_version.outputs.version }}