-
Notifications
You must be signed in to change notification settings - Fork 1
65 lines (50 loc) · 1.99 KB
/
image-tests.yml
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
name: Run backend and frontend tests inside docker image
on:
push:
branches:
- master
- dev
pull_request:
branches:
- master
- dev
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Buildx cache
uses: actions/cache@v3
with:
path: buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('buildx-cache/**') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Run the backend and frontend tests in containers
run: |
export MAIN_IMAGE=teamware-main
export STATIC_IMAGE=teamware-static
export DJANGO_SETTINGS_MODULE=teamware.settings.docker-test
./generate-docker-env.sh
# Remove container registry address
sed -i 's/ghcr.io\/gatenlp\///g' .env
# Display the environment variable file for the logs
cat .env
# Build the test image with npm and pytest installed
docker buildx build --cache-from type=local,src=buildx-cache --cache-to type=local,dest=buildx-cache-out,mode=max --load -t teamware-main:latest --target test .
# Clear up the cache
rm -rf buildx-cache && mv buildx-cache-out buildx-cache
# Export the environment variables
source .env
# Launch the database container
docker-compose up -d db
# Hacky method of waiting for postgres to be up and running
sleep 10
# Allow Django to create databases for the testing
docker-compose exec -T db psql -v ON_ERROR_STOP=1 --username postgres -c 'ALTER USER '"$DB_USERNAME"' CREATEDB;'
# Run the backend tests
docker-compose run --rm --entrypoint npm backend run test:pytest
# Run the frontend tests
docker-compose run --rm --entrypoint npm backend run test:frontend