Skip to content

Commit c6092c1

Browse files
committed
Restructure workflow to minimise build time
1 parent 32dcfdf commit c6092c1

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed

.github/workflows/ci-cd.yml

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
COMPOSE_BAKE_ARGS: "--build-arg PIP_NO_CACHE_DIR=1"
1212
CHROME_BIN: chromium-browser
1313
DISPLAY: :99.0
14-
PYTHON_VERSION: '3.9'
14+
PYTHON_VERSION: '3.9.21'
1515
AWSCLI_VERSION: '1.18.66'
1616
REGISTRY: ${{ secrets.DOCKER_USERNAME }}
1717
IMAGE_TAG: ${{ github.sha }}
@@ -38,6 +38,7 @@ jobs:
3838

3939
- name: Install dependencies and configure system
4040
run: |
41+
pip install --upgrade pip
4142
pip install awscli==${{ env.AWSCLI_VERSION }}
4243
sudo rm -f /etc/boto.cfg
4344
mkdir -p $HOME/.config/pip
@@ -48,17 +49,17 @@ jobs:
4849
4950
- name: Run code quality checks
5051
run: |
51-
docker compose run -e DJANGO_SETTINGS_MODULE=settings.test -e VERBOSE=1 django bash -c "
52-
echo 'Installing linting tools...' &&
52+
docker compose run -e DJANGO_SETTINGS_MODULE=settings.dev -e VERBOSE=1 django bash -c "
53+
echo 'Installing black, flake8, pylint and isort...' &&
5354
pip install black==24.8.0 flake8==3.8.2 pylint==3.3.6 isort==5.12.0 &&
5455
echo 'Running black check...' &&
55-
black --check --diff ./ &&
56+
black --check --diff ./ || { echo 'Black check failed!'; exit 1; } &&
5657
echo 'Running isort check...' &&
57-
isort --check-only --diff --profile=black ./ &&
58+
isort --check-only --diff --profile=black ./ || { echo 'isort check failed!'; exit 1; } &&
5859
echo 'Running flake8 check...' &&
59-
flake8 --config=.flake8 ./ &&
60+
flake8 --config=.flake8 ./ || { echo 'Flake8 check failed!'; exit 1; } &&
6061
echo 'Running pylint check...' &&
61-
pylint --rcfile=.pylintrc --output-format=colorized --score=y --fail-under=7.5 ./ &&
62+
pylint --rcfile=.pylintrc --output-format=colorized --score=y --fail-under=7.5 ./ || { echo 'Pylint check failed!'; exit 1; } &&
6263
echo 'All code quality checks passed!'"
6364
6465
- name: Django Migration Check
@@ -69,6 +70,7 @@ jobs:
6970
build-and-push:
7071
name: Build & Push Docker Images
7172
runs-on: ubuntu-latest
73+
# REMOVED: No dependencies - runs in parallel
7274
outputs:
7375
image-digest: ${{ steps.build.outputs.digest }}
7476
steps:
@@ -91,6 +93,7 @@ jobs:
9193
${{ runner.os }}-buildx-
9294
9395
- name: Docker login
96+
if: github.event_name == 'push'
9497
uses: docker/login-action@v3
9598
with:
9699
username: ${{ secrets.DOCKER_USERNAME }}
@@ -99,29 +102,19 @@ jobs:
99102
- name: Build and push Docker images
100103
id: build
101104
run: |
102-
# Build and push images with unique tags
103-
docker buildx build \
104-
--cache-from type=local,src=/tmp/.buildx-cache \
105-
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
106-
--push \
107-
--tag ${{ env.REGISTRY }}/evalai:${{ env.IMAGE_TAG }} \
108-
--tag ${{ env.REGISTRY }}/evalai:latest \
109-
.
110-
111-
# Build compose services and push
112105
export COMPOSE_DOCKER_CLI_BUILD=1
113106
export DOCKER_BUILDKIT=1
114107
115108
docker compose --profile worker_py3_7 --profile worker_py3_8 --profile worker_py3_9 --profile statsd build ${{ env.COMPOSE_BAKE_ARGS }}
116-
docker compose --profile worker_py3_7 --profile worker_py3_8 --profile worker_py3_9 --profile statsd push
117109
118-
# Clean up cache
119-
rm -rf /tmp/.buildx-cache
120-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
110+
if [ "${{ github.event_name }}" = "push" ]; then
111+
docker compose --profile worker_py3_7 --profile worker_py3_8 --profile worker_py3_9 --profile statsd push
112+
fi
121113
122114
test:
123115
name: Run Tests
124116
runs-on: ubuntu-latest
117+
# REMOVED: No dependencies - runs in parallel with build
125118
strategy:
126119
matrix:
127120
test-type: [frontend, backend]
@@ -140,20 +133,14 @@ jobs:
140133
with:
141134
version: latest
142135

143-
- name: Docker login
144-
uses: docker/login-action@v3
145-
with:
146-
username: ${{ secrets.DOCKER_USERNAME }}
147-
password: ${{ secrets.DOCKER_PASSWORD }}
148-
149136
- name: Install test dependencies
150-
run: pip install awscli==${{ env.AWSCLI_VERSION }} coveralls
137+
run: |
138+
pip install --upgrade pip
139+
pip install awscli==${{ env.AWSCLI_VERSION }} coveralls
151140
152-
- name: Pull Docker images
141+
- name: Build images for testing (if not available)
153142
run: |
154-
# Pull the latest images (they might be building in parallel)
155-
timeout 300 bash -c 'until docker pull ${{ env.REGISTRY }}/evalai:${{ env.IMAGE_TAG }} 2>/dev/null; do echo "Waiting for image..."; sleep 10; done'
156-
docker compose pull
143+
docker compose --profile worker_py3_7 --profile worker_py3_8 --profile worker_py3_9 --profile statsd build ${{ env.COMPOSE_BAKE_ARGS }}
157144
158145
- name: Setup display for frontend tests
159146
if: matrix.test-type == 'frontend'
@@ -175,22 +162,21 @@ jobs:
175162
176163
- name: Upload coverage to Codecov
177164
if: matrix.test-type == 'backend'
178-
uses: codecov/codecov-action@v3
179-
with:
180-
fail_ci_if_error: false
165+
run: |
166+
bash <(curl -s https://codecov.io/bash)
181167
182168
- name: Upload coverage to Coveralls
183169
if: matrix.test-type == 'backend'
184170
continue-on-error: true
185171
env:
186172
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
187173
run: |
188-
coveralls --rcfile=.coveragerc || echo "Coveralls submission failed, continuing..."
174+
coveralls --rcfile=.coveragerc
189175
190176
deploy:
191-
name: Deploy & Notify
177+
name: Package & Deploy Services
192178
runs-on: ubuntu-latest
193-
needs: [build-and-push, test, quality-check]
179+
needs: [build-and-push, test, quality-check] # Waits for ALL jobs to complete
194180
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
195181
environment: production
196182
steps:
@@ -203,10 +189,13 @@ jobs:
203189
cache: 'pip'
204190

205191
- name: Install deployment dependencies
206-
run: pip install awscli==${{ env.AWSCLI_VERSION }}
192+
run: |
193+
pip install --upgrade pip
194+
pip install awscli==${{ env.AWSCLI_VERSION }}
207195
208-
- name: Configure SSH
196+
- name: Configure SSH and decrypt keys
209197
run: |
198+
eval "$(ssh-agent -s)"
210199
mkdir -p ~/.ssh
211200
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
212201
chmod 600 ~/.ssh/deploy_key
@@ -215,11 +204,14 @@ jobs:
215204
216205
- name: Deploy services
217206
run: |
218-
eval "$(ssh-agent -s)"
219207
ssh-add ~/.ssh/deploy_key
220208
./scripts/deployment/push.sh
221209
./scripts/deployment/deploy.sh auto_deploy
222210
211+
- name: Clean up pip cache
212+
run: |
213+
rm -f $HOME/.cache/pip/log/debug.log
214+
223215
- name: Notify on failure
224216
if: failure()
225217
uses: 8398a7/action-slack@v3

0 commit comments

Comments
 (0)