-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
Changes from 37 commits
b5c57b4
1e9254b
69092ce
4002a19
0a05fdf
58507cc
36258b5
4119c73
0688a77
a66029c
9846482
f8be096
fbac331
837c665
143ce39
1a42d21
f619928
93f3180
8893db1
1e39448
a659f0a
009b32c
54f09ee
f1b0af0
3376a65
3f76de1
0300e4e
89ad0a6
ee3055f
8c73507
e2f1162
bf347ef
c5909b3
fae06b4
78cd6c8
d054d25
dcd91be
913ffcb
ba9671b
c080a41
f43728e
14178dd
70562bf
2e7dd25
61551c3
eb0af68
55f717f
da0bb58
6de7222
ff08b13
d3e48dd
fc9f270
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| name: Set up E2E environment | ||
| description: "Sets up the environment for end-to-end testing." | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| 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 | ||
|
Comment on lines
+20
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical security risk: Hardcoded database password in source code. Line 22 embeds the database password Define the action input and replace the hardcoded value: +inputs:
+ db-password:
+ description: 'PostgreSQL password for e2e environment (use GitHub secret)'
+ required: true
+
runs:
using: composite
steps:
- name: Load Postgres data
env:
- PGPASSWORD: nest_user_e2e_password
+ PGPASSWORD: ${{ inputs.db-password }}
run: |
gunzip -c backend/data/nest-e2e.sql.gz | psql -h localhost -U nest_user_e2e -d nest_db_e2eThen update the caller in - name: Setup E2E environment
uses: ./.github/workflows/setup-e2e-environment
with:
db-password: ${{ secrets.NEST_E2E_DB_PASSWORD }}Ensure 🤖 Prompt for AI Agents |
||
|
|
||
| - 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 | ||
ahmedxgouda marked this conversation as resolved.
Show resolved
Hide resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How was this dump created and what data is already there?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add a command to dump the local backend instance |
| 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 | ||
| 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: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| services: | ||
| production-nest-backend: | ||
| container_name: production-nest-backend | ||
| entrypoint: /home/owasp/entrypoint.sh | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify the entrypoint script exists and is properly configured. The production service now explicitly calls
Run the following script to verify the entrypoint is present in the backend image: 🏁 Script executed: #!/bin/bash
# Verify entrypoint script exists in the backend production image
docker run --rm --entrypoint ls owasp/nest:backend-production -la /home/owasp/entrypoint.sh 2>&1 || echo "Entrypoint script not found or image not available locally"Length of output: 103 🏁 Script executed: #!/bin/bash
# Search for entrypoint.sh in the repository
fd -t f entrypoint.shLength of output: 28 🏁 Script executed: #!/bin/bash
# Find Dockerfile for the backend service
fd -t f -e Dockerfile | grep -i "backend\|nest" || fd -t f -e DockerfileLength of output: 0 🏁 Script executed: #!/bin/bash
# Search for references to the entrypoint path in docker-compose and Dockerfiles
rg -n "entrypoint.sh|/home/owasp" --type yaml --type dockerfileLength of output: 34 🏁 Script executed: #!/bin/bash
# Examine the entrypoint script content
cat backend/docker/entrypoint.shLength of output: 160 🏁 Script executed: #!/bin/bash
# Find all Dockerfiles (remove type filter to avoid errors)
fd -t f "Dockerfile" -o "Dockerfile.*"Length of output: 143 🏁 Script executed: #!/bin/bash
# Look for Docker-related files in backend/docker directory
ls -la backend/docker/ 2>/dev/null || echo "Directory not found"Length of output: 365 🏁 Script executed: #!/bin/bash
# Search for COPY and ADD commands that reference entrypoint in any files
rg -n "COPY|ADD" -A 1 -B 1 | grep -A 2 -B 2 "entrypoint\|/home/owasp"Length of output: 1355 🏁 Script executed: #!/bin/bash
# View full backend/docker/Dockerfile to understand working directory and path resolution
cat backend/docker/DockerfileLength of output: 1731 🏁 Script executed: #!/bin/bash
# Check if entrypoint.sh is marked executable in git
git ls-files -s backend/docker/entrypoint.shLength of output: 78 Add signal handlers to entrypoint script for graceful shutdown in production. The script exists at Location: Fix: Add signal forwarding before gunicorn: #!/bin/sh
set -e
python manage.py migrate
python manage.py collectstatic --noinput
python manage.py clear_cache
exec gunicorn wsgi:application --bind 0.0.0.0:8000The 🤖 Prompt for AI Agents |
||
| image: owasp/nest:backend-production | ||
| env_file: .env.backend | ||
| depends_on: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.