99env :
1010 COMPOSE_BAKE : true
1111 COMPOSE_BAKE_ARGS : " --build-arg PIP_NO_CACHE_DIR=1"
12+ DOCKER_COMPOSE_VERSION : " v2.23.0"
1213
1314jobs :
14- lint :
15- name : Code Linting
15+ # Shared setup job to avoid duplication
16+ setup :
17+ name : Setup Dependencies
1618 runs-on : ubuntu-latest
19+ outputs :
20+ compose-cache-key : ${{ steps.compose-cache.outputs.cache-hit }}
1721 steps :
18- - uses : actions/checkout@v3
22+ - name : Cache Docker Compose binary
23+ id : compose-cache
24+ uses : actions/cache@v4
25+ with :
26+ path : /usr/local/bin/docker-compose
27+ key : docker-compose-${{ env.DOCKER_COMPOSE_VERSION }}
1928
2029 - name : Install Docker Compose
30+ if : steps.compose-cache.outputs.cache-hit != 'true'
2131 run : |
22- sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0 /docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
32+ sudo curl -L "https://github.com/docker/compose/releases/download/${{ env.DOCKER_COMPOSE_VERSION }} /docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2333 sudo chmod +x /usr/local/bin/docker-compose
24- docker-compose --version
34+
35+ - name : Verify Docker Compose
36+ run : docker-compose --version
37+
38+ lint :
39+ name : Code Linting
40+ runs-on : ubuntu-latest
41+ needs : setup
42+ steps :
43+ - uses : actions/checkout@v4
44+
45+ - name : Restore Docker Compose
46+ uses : actions/cache@v4
47+ with :
48+ path : /usr/local/bin/docker-compose
49+ key : docker-compose-${{ env.DOCKER_COMPOSE_VERSION }}
2550
2651 - name : Run code quality checks in Docker
2752 run : |
@@ -41,17 +66,18 @@ jobs:
4166 migration-check :
4267 name : Django Migration Check
4368 runs-on : ubuntu-latest
44- needs : lint
69+ needs : [setup, lint]
4570 if : github.event_name == 'pull_request'
4671 steps :
47- - uses : actions/checkout@v3
72+ - uses : actions/checkout@v4
4873 with :
4974 fetch-depth : 0
5075
51- - name : Install Docker Compose
52- run : |
53- sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
54- sudo chmod +x /usr/local/bin/docker-compose
76+ - name : Restore Docker Compose
77+ uses : actions/cache@v4
78+ with :
79+ path : /usr/local/bin/docker-compose
80+ key : docker-compose-${{ env.DOCKER_COMPOSE_VERSION }}
5581
5682 - name : Django Migration Checker
5783 run : |
6086 build :
6187 name : Docker Build
6288 runs-on : ubuntu-latest
63- needs : lint
89+ needs : [setup, lint]
6490 steps :
65- - uses : actions/checkout@v3
91+ - uses : actions/checkout@v4
6692
6793 - name : System configuration
6894 run : |
@@ -73,85 +99,101 @@ jobs:
7399 ulimit -u 16384 # Increase process/thread limit
74100 ulimit -n 4096 # Increase open file limit
75101
76- - name : Install Docker Compose
77- run : |
78- sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
79- sudo chmod +x /usr/local/bin/docker-compose
80- docker-compose --version
102+ - name : Restore Docker Compose
103+ uses : actions/cache@v4
104+ with :
105+ path : /usr/local/bin/docker-compose
106+ key : docker-compose-${{ env.DOCKER_COMPOSE_VERSION }}
107+
108+ - name : Cache Docker layers
109+ uses : actions/cache@v4
110+ with :
111+ path : /tmp/.buildx-cache
112+ key : ${{ runner.os }}-buildx-${{ github.sha }}
113+ restore-keys : |
114+ ${{ runner.os }}-buildx-
81115
82116 - name : Docker login
83117 if : github.event_name == 'push'
84- uses : docker/login-action@v2
118+ uses : docker/login-action@v3
85119 with :
86120 username : ${{ secrets.DOCKER_USERNAME }}
87121 password : ${{ secrets.DOCKER_PASSWORD }}
88122
89123 - name : Build Docker image
90124 run : docker-compose --profile worker --profile statsd build ${{ env.COMPOSE_BAKE_ARGS }}
91-
92- - name : Cache Docker images
93- uses : actions/cache@v3
94- with :
95- path : /var/lib/docker
96- key : ${{ runner.os }}-docker-${{ github.sha }}
97- restore-keys : |
98- ${{ runner.os }}-docker-
99125
100126 frontend-test :
101127 name : Frontend Tests
102128 runs-on : ubuntu-latest
103129 needs : build
104130 steps :
105- - uses : actions/checkout@v3
131+ - uses : actions/checkout@v4
106132
107- - name : Install Docker Compose
108- run : |
109- sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
110- sudo chmod +x /usr/local/bin/docker-compose
111- docker-compose --version
112-
113- - name : Setup Chrome
114- run : |
115- export CHROME_BIN=chromium-browser
133+ - name : Restore Docker Compose
134+ uses : actions/cache@v4
135+ with :
136+ path : /usr/local/bin/docker-compose
137+ key : docker-compose-${{ env.DOCKER_COMPOSE_VERSION }}
116138
117139 - name : Setup display for browser tests
118140 run : |
119- export DISPLAY=:99
141+ sudo apt-get update
120142 sudo apt-get install -y xvfb
143+ export DISPLAY=:99
121144 Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
145+ export CHROME_BIN=chromium-browser
122146
123147 - name : Run frontend tests
148+ env :
149+ DISPLAY : :99
150+ CHROME_BIN : chromium-browser
124151 run : docker-compose run nodejs bash -c "gulp dev && karma start --single-run && gulp staging"
125152
126-
127153 backend-test :
128154 name : Backend Tests
129155 runs-on : ubuntu-latest
130156 needs : build
157+ services :
158+ postgres :
159+ image : postgres:14
160+ env :
161+ POSTGRES_USER : postgres
162+ POSTGRES_PASSWORD : postgres
163+ POSTGRES_DB : evalai_test
164+ options : >-
165+ --health-cmd pg_isready
166+ --health-interval 10s
167+ --health-timeout 5s
168+ --health-retries 5
169+ ports :
170+ - 5432:5432
131171 steps :
132- - uses : actions/checkout@v3
172+ - uses : actions/checkout@v4
133173
134- - name : Install Docker Compose
135- run : |
136- sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
137- sudo chmod +x /usr/local/bin/docker-compose
138- docker-compose --version
174+ - name : Restore Docker Compose
175+ uses : actions/cache@v4
176+ with :
177+ path : /usr/local/bin/docker-compose
178+ key : docker-compose-${{ env.DOCKER_COMPOSE_VERSION }}
139179
140180 - name : Set up Python 3.9
141- uses : actions/setup-python@v4
181+ uses : actions/setup-python@v5
142182 with :
143183 python-version : 3.9.21
144184
145185 - name : Install dependencies
146186 run : pip install awscli==1.18.66 coveralls
147187
148188 - name : Run backend tests
189+ env :
190+ DATABASE_URL : postgres://postgres:postgres@localhost:5432/evalai_test
149191 run : |
150- docker-compose run -e DJANGO_SETTINGS_MODULE=settings.test django python manage.py flush --noinput
151- docker-compose run -e DJANGO_SETTINGS_MODULE=settings.test django pytest --cov . --cov-config .coveragerc
192+ docker-compose run --no-deps - e DJANGO_SETTINGS_MODULE=settings.test -e DATABASE_URL=$DATABASE_URL django python manage.py flush --noinput
193+ docker-compose run --no-deps - e DJANGO_SETTINGS_MODULE=settings.test -e DATABASE_URL=$DATABASE_URL django pytest --cov . --cov-config .coveragerc
152194
153195 - name : Upload coverage to Codecov
154- uses : codecov/codecov-action@v3
196+ uses : codecov/codecov-action@v4
155197
156198 - name : Coveralls
157199 continue-on-error : true
@@ -160,17 +202,55 @@ jobs:
160202 run : |
161203 echo "Attempting to submit coverage to Coveralls..."
162204 coveralls --rcfile=.coveragerc || echo "Coveralls submission failed, but continuing workflow"
205+
206+ pr-deploy :
207+ name : Deploy PR Preview
208+ runs-on : ubuntu-latest
209+ if : github.event_name == 'pull_request'
210+ needs : [frontend-test]
211+ steps :
212+ - uses : actions/checkout@v4
213+
214+ - name : Setup Node.js
215+ uses : actions/setup-node@v4
216+ with :
217+ node-version : ' 18'
218+ cache : ' npm'
219+
220+ - name : Build frontend
221+ run : |
222+ npm install
223+ npm run build
224+
225+ - name : Deploy PR Preview
226+ env :
227+ SURGE_TOKEN : ${{ secrets.SURGE_TOKEN }}
228+ GITHUB_PR_NUMBER : ${{ github.event.number }}
229+ run : |
230+ chmod +x ./scripts/pr_deploy.sh
231+ ./scripts/pr_deploy.sh
232+
233+ - name : Comment PR with preview link
234+ uses : actions/github-script@v7
235+ with :
236+ script : |
237+ github.rest.issues.createComment({
238+ issue_number: context.issue.number,
239+ owner: context.repo.owner,
240+ repo: context.repo.repo,
241+ body: '🚀 Preview deployed to: https://pr-${{ github.event.number }}-evalai.surge.sh'
242+ })
163243
164244 deploy :
165245 name : Package & Deploy
166246 runs-on : ubuntu-latest
167247 needs : [frontend-test, backend-test]
168248 if : github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
169249 steps :
170- - uses : actions/checkout@v3
250+ - uses : actions/checkout@v4
171251
172252 - name : Set up Python 3.9
173- uses : actions/setup-python@v4
253+ uses : actions/setup-python@v5
174254 with :
175255 python-version : 3.9.21
176256
@@ -186,6 +266,16 @@ jobs:
186266 ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
187267
188268 - name : Run deployment scripts
269+ env :
270+ AWS_ACCOUNT_ID : ${{ secrets.AWS_ACCOUNT_ID }}
271+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
272+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
273+ GITHUB_REF_NAME : ${{ github.ref_name }}
274+ JUMPBOX_INSTANCE : ${{ secrets.JUMPBOX_INSTANCE }}
275+ PRODUCTION_INSTANCE : ${{ secrets.PRODUCTION_INSTANCE }}
276+ STAGING_INSTANCE : ${{ secrets.STAGING_INSTANCE }}
277+ PRODUCTION_MONITORING_INSTANCE : ${{ secrets.PRODUCTION_MONITORING_INSTANCE }}
278+ STAGING_MONITORING_INSTANCE : ${{ secrets.STAGING_MONITORING_INSTANCE }}
189279 run : |
190280 export SSH_AUTH_SOCK=/tmp/ssh_agent.sock
191281 ssh-agent -a $SSH_AUTH_SOCK > /dev/null
0 commit comments