Skip to content

Commit 8f65415

Browse files
authored
Update ci-cd.yml
1 parent bae5ad8 commit 8f65415

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

.github/workflows/ci-cd.yml

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ env:
1313
DISPLAY: :99.0
1414
PYTHON_VERSION: '3.9'
1515
AWSCLI_VERSION: '1.18.66'
16+
REGISTRY: ${{ secrets.DOCKER_USERNAME }}
17+
IMAGE_TAG: ${{ github.sha }}
1618

1719
jobs:
1820
quality-check:
@@ -24,7 +26,7 @@ jobs:
2426
fetch-depth: 0
2527

2628
- name: Setup Python and dependencies
27-
uses: actions/setup-python@v4
29+
uses: actions/setup-python@v5
2830
with:
2931
python-version: ${{ env.PYTHON_VERSION }}
3032
cache: 'pip'
@@ -64,9 +66,11 @@ jobs:
6466
run: |
6567
docker compose run -e DJANGO_SETTINGS_MODULE=settings.dev django python manage.py makemigrations --check --dry-run
6668
67-
build-docker:
68-
name: Build Docker Images
69+
build-and-push:
70+
name: Build & Push Docker Images
6971
runs-on: ubuntu-latest
72+
outputs:
73+
image-digest: ${{ steps.build.outputs.digest }}
7074
steps:
7175
- uses: actions/checkout@v4
7276

@@ -75,49 +79,58 @@ jobs:
7579
with:
7680
version: latest
7781

78-
- name: Setup Docker environment
79-
run: |
80-
docker buildx create --use
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
8184

8285
- name: Cache Docker layers
83-
uses: actions/cache@v3
86+
uses: actions/cache@v4
8487
with:
8588
path: /tmp/.buildx-cache
8689
key: ${{ runner.os }}-buildx-${{ github.sha }}
8790
restore-keys: |
8891
${{ runner.os }}-buildx-
8992
9093
- name: Docker login
91-
if: github.event_name == 'push'
9294
uses: docker/login-action@v3
9395
with:
9496
username: ${{ secrets.DOCKER_USERNAME }}
9597
password: ${{ secrets.DOCKER_PASSWORD }}
9698

97-
- name: Build Docker images
99+
- name: Build and push Docker images
100+
id: build
98101
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
112+
export COMPOSE_DOCKER_CLI_BUILD=1
113+
export DOCKER_BUILDKIT=1
114+
99115
docker compose --profile worker_py3_7 --profile worker_py3_8 --profile worker_py3_9 --profile statsd build ${{ env.COMPOSE_BAKE_ARGS }}
100-
101-
- name: Save Docker images
102-
run: |
103-
docker save $(docker images --format "table {{.Repository}}:{{.Tag}}" | grep -v REPOSITORY | tr '\n' ' ') -o /tmp/docker-images.tar
104-
105-
- name: Upload Docker images
106-
uses: actions/upload-artifact@v4
107-
with:
108-
name: docker-images
109-
path: /tmp/docker-images.tar
110-
retention-days: 1
116+
docker compose --profile worker_py3_7 --profile worker_py3_8 --profile worker_py3_9 --profile statsd push
117+
118+
# Clean up cache
119+
rm -rf /tmp/.buildx-cache
120+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
111121
112122
test:
113123
name: Run Tests
114124
runs-on: ubuntu-latest
115-
needs: build-docker
125+
strategy:
126+
matrix:
127+
test-type: [frontend, backend]
128+
fail-fast: false
116129
steps:
117130
- uses: actions/checkout@v4
118131

119132
- name: Setup Python and dependencies
120-
uses: actions/setup-python@v4
133+
uses: actions/setup-python@v5
121134
with:
122135
python-version: ${{ env.PYTHON_VERSION }}
123136
cache: 'pip'
@@ -127,40 +140,47 @@ jobs:
127140
with:
128141
version: latest
129142

143+
- name: Docker login
144+
uses: docker/login-action@v3
145+
with:
146+
username: ${{ secrets.DOCKER_USERNAME }}
147+
password: ${{ secrets.DOCKER_PASSWORD }}
148+
130149
- name: Install test dependencies
131150
run: pip install awscli==${{ env.AWSCLI_VERSION }} coveralls
132151

133-
- name: Download Docker images
134-
uses: actions/download-artifact@v3
135-
with:
136-
name: docker-images
137-
path: /tmp
138-
139-
- name: Load Docker images
152+
- name: Pull Docker images
140153
run: |
141-
docker load -i /tmp/docker-images.tar
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
142157
143158
- name: Setup display for frontend tests
159+
if: matrix.test-type == 'frontend'
144160
run: |
145161
sudo apt-get update
146162
sudo apt-get install -y xvfb chromium-browser
147163
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
148164
149165
- name: Run frontend tests
166+
if: matrix.test-type == 'frontend'
150167
run: |
151168
docker compose run nodejs bash -c "gulp dev && karma start --single-run && gulp staging"
152169
153170
- name: Run backend tests
171+
if: matrix.test-type == 'backend'
154172
run: |
155173
docker compose run -e DJANGO_SETTINGS_MODULE=settings.test django python manage.py flush --noinput
156174
docker compose run -e DJANGO_SETTINGS_MODULE=settings.test django pytest --cov . --cov-config .coveragerc
157175
158176
- name: Upload coverage to Codecov
177+
if: matrix.test-type == 'backend'
159178
uses: codecov/codecov-action@v3
160179
with:
161180
fail_ci_if_error: false
162181

163182
- name: Upload coverage to Coveralls
183+
if: matrix.test-type == 'backend'
164184
continue-on-error: true
165185
env:
166186
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
@@ -170,14 +190,14 @@ jobs:
170190
deploy:
171191
name: Deploy & Notify
172192
runs-on: ubuntu-latest
173-
needs: [test, quality-check]
193+
needs: [build-and-push, test, quality-check]
174194
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
175195
environment: production
176196
steps:
177197
- uses: actions/checkout@v4
178198

179199
- name: Setup Python and dependencies
180-
uses: actions/setup-python@v4
200+
uses: actions/setup-python@v5
181201
with:
182202
python-version: ${{ env.PYTHON_VERSION }}
183203
cache: 'pip'

0 commit comments

Comments
 (0)