-
-
Notifications
You must be signed in to change notification settings - Fork 260
Establish an e2e backend instance locally and in CI/CD #2429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahmedxgouda
wants to merge
47
commits into
OWASP:feature/e2e-backend
Choose a base branch
from
ahmedxgouda:feature/e2e-backend
base: feature/e2e-backend
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 36 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
b5c57b4
Add dockerfile and compose and update makefile
ahmedxgouda 1e9254b
Dump db-data
ahmedxgouda 69092ce
Reorder makefile
ahmedxgouda 4002a19
Dump db-data
ahmedxgouda 0a05fdf
Remove e2e dockerfile
ahmedxgouda 58507cc
Add CI/CD
ahmedxgouda 36258b5
Merge branch 'main' into feature/e2e-backend
ahmedxgouda 4119c73
Apply rabbit's suggestions
ahmedxgouda 0688a77
Add postgres instead of pgvector
ahmedxgouda a66029c
Remove needs
ahmedxgouda 9846482
Update envs
ahmedxgouda f8be096
Fix migrations step
ahmedxgouda fbac331
Add envs to docker
ahmedxgouda 837c665
Remove migrations step
ahmedxgouda 143ce39
Remove --without test from dockerfile
ahmedxgouda 1a42d21
Copy tests in dockerfile and add needs to gh workflow
ahmedxgouda f619928
Update dockerfile
ahmedxgouda 93f3180
Merge branch 'main' into feature/e2e-backend
ahmedxgouda 8893db1
Apply suggestion
ahmedxgouda 1e39448
Use the e2e instance in the frontend e2e tests
ahmedxgouda a659f0a
Update CI/CD
ahmedxgouda 009b32c
Update CI/CD
ahmedxgouda 54f09ee
Update CI/CD
ahmedxgouda f1b0af0
Update CI/CD
ahmedxgouda 3376a65
Update CI/CD and dockerfile
ahmedxgouda 3f76de1
Update CI/CD
ahmedxgouda 0300e4e
Update CI/CD
ahmedxgouda 89ad0a6
Update CI/CD
ahmedxgouda ee3055f
Update CI/CD
ahmedxgouda 8c73507
Update CI/CD
ahmedxgouda e2f1162
Update CI/CD
ahmedxgouda bf347ef
Update CI/CD
ahmedxgouda c5909b3
Update CI/CD
ahmedxgouda fae06b4
Update CI/CD
ahmedxgouda 78cd6c8
Update CI/CD
ahmedxgouda d054d25
Update CI/CD
ahmedxgouda dcd91be
Update CI/CD
ahmedxgouda 913ffcb
Update CI/CD
ahmedxgouda ba9671b
Restore needs for the job
ahmedxgouda c080a41
Update Makefiles
ahmedxgouda f43728e
Update docs
ahmedxgouda 14178dd
Merge branch 'feature/upstream-e2e-backend' into feature/e2e-backend
ahmedxgouda 70562bf
Apply suggestions
ahmedxgouda 2e7dd25
Update load-data
ahmedxgouda 61551c3
Skip sonar error
ahmedxgouda eb0af68
update port numbers
ahmedxgouda 55f717f
Update docs
ahmedxgouda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| name: Set up E2E environment | ||
| description: "Sets up the environment for end-to-end testing." | ||
|
|
||
| runs: | ||
| steps: | ||
| - name: Wait for database to be ready | ||
| run: | | ||
| until docker exec ${{ job.services.db.id }} pg_isready -U nest_user_e2e -d nest_db_e2e; do | ||
ahmedxgouda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "Waiting for database..." | ||
| sleep 5 | ||
| done | ||
ahmedxgouda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shell: bash | ||
ahmedxgouda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Install PostgreSQL client | ||
| run: sudo apt-get install -y postgresql-client | ||
| shell: bash | ||
|
|
||
| - name: Load Postgres data | ||
| env: | ||
| PGPASSWORD: nest_user_e2e_password | ||
ahmedxgouda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| run: | | ||
| gunzip -c backend/data/nest-e2e.sql.gz | psql -h localhost -U nest_user_e2e -d nest_db_e2e | ||
| shell: bash | ||
|
|
||
| - name: Build backend e2e image | ||
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 | ||
| with: | ||
| cache-from: | | ||
| type=gha | ||
| cache-to: | | ||
| type=gha,compression=zstd | ||
| context: backend | ||
| file: backend/docker/Dockerfile | ||
| load: true | ||
| platforms: linux/amd64 | ||
| tags: owasp/nest:test-backend-e2e-latest | ||
|
|
||
| - name: Start Backend in the background | ||
| run: | | ||
| docker run --rm --name nest-backend-e2e-runner \ | ||
| --env-file backend/.env.example \ | ||
| --network host \ | ||
| -e DJANGO_SETTINGS_MODULE=settings.test \ | ||
| -e DJANGO_DB_HOST=localhost \ | ||
| -e DJANGO_DB_NAME=nest_db_e2e \ | ||
| -e DJANGO_DB_USER=nest_user_e2e \ | ||
| -e DJANGO_DB_PASSWORD=nest_user_e2e_password \ | ||
| -e DJANGO_DB_PORT=5432 \ | ||
| -p 8000:8000 \ | ||
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| owasp/nest:test-backend-e2e-latest \ | ||
| sh -c ' | ||
| python manage.py runserver 0.0.0.0:8000 | ||
| ' | ||
| shell: bash | ||
|
|
||
| - name: Waiting for the backend to be ready | ||
| run: | | ||
| until curl -s http://localhost:8000/graphql > /dev/null; do | ||
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| echo "Waiting for backend..." | ||
| sleep 3 | ||
| done | ||
| echo "Backend is up!" | ||
| shell: bash | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
ahmedxgouda marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,4 +64,4 @@ RUN rm -rf /home/owasp/.cache && \ | |
|
|
||
| USER owasp | ||
|
|
||
| CMD ["/home/owasp/entrypoint.sh"] | ||
| EXPOSE 8000 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| services: | ||
| backend: | ||
| container_name: nest-backend-e2e | ||
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| command: > | ||
| sh -c ' | ||
| python manage.py migrate && | ||
| python manage.py runserver 0.0.0.0:8000 | ||
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ' | ||
| build: | ||
| context: ../backend | ||
| dockerfile: docker/Dockerfile | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
| env_file: ../backend/.env | ||
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| environment: | ||
| DJANGO_DB_HOST: ${DJANGO_DB_HOST:-db} | ||
| DJANGO_DB_NAME: ${DJANGO_DB_NAME:-nest_db_e2e} | ||
| DJANGO_DB_PASSWORD: ${DJANGO_DB_PASSWORD:-nest_user_e2e_password} | ||
| DJANGO_DB_PORT: ${DJANGO_DB_PORT:-5432} | ||
| DJANGO_DB_USER: ${DJANGO_DB_USER:-nest_user_e2e} | ||
| networks: | ||
| - nest-network | ||
| ports: | ||
| - 8000:8000 | ||
| healthcheck: | ||
| interval: 10s | ||
| retries: 10 | ||
| test: > | ||
| sh -c ' | ||
| wget --spider http://backend:8000/graphql | ||
| ' | ||
| timeout: 10s | ||
| start_period: 10s | ||
| db: | ||
| container_name: nest-db-e2e | ||
| image: pgvector/pgvector:pg16 | ||
| environment: | ||
| POSTGRES_DB: ${DJANGO_DB_NAME:-nest_db_e2e} | ||
| POSTGRES_PASSWORD: ${DJANGO_DB_PASSWORD:-nest_user_e2e_password} | ||
| POSTGRES_USER: ${DJANGO_DB_USER:-nest_user_e2e} | ||
| healthcheck: | ||
| interval: 5s | ||
| retries: 5 | ||
| test: [CMD-SHELL, pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB -h localhost -p 5432] | ||
| timeout: 5s | ||
| networks: | ||
| - nest-network | ||
| volumes: | ||
| - db-e2e-data:/var/lib/postgresql/data | ||
| ports: | ||
| - 5433:5432 | ||
|
|
||
| frontend: | ||
| container_name: nest-frontend-e2e | ||
| build: | ||
| context: ../frontend | ||
| dockerfile: docker/Dockerfile.e2e.test | ||
| command: > | ||
| sh -c ' | ||
| pnpm run test:e2e | ||
ahmedxgouda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ' | ||
| depends_on: | ||
| backend: | ||
| condition: service_healthy | ||
| env_file: ../frontend/.env | ||
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ahmedxgouda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| networks: | ||
| - nest-network | ||
|
|
||
| volumes: | ||
| db-e2e-data: | ||
|
|
||
| networks: | ||
| nest-network: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.