Skip to content

Commit

Permalink
Added test build to Dockerfile and test service in docker-compose.dev…
Browse files Browse the repository at this point in the history
….yml
  • Loading branch information
katporks committed Nov 17, 2023
1 parent 6607bdf commit 084d80e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
extra_build_args: |
APP_VERSION=${{ github.ref_name }}
COMMIT_REF=${{ github.sha }}
compose_service: base
compose_service: test
compose_command: pytest
compose_file: "docker-compose.dev.yml"
13 changes: 10 additions & 3 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ WORKDIR /app
# Create user "wagtail"
RUN useradd -m wagtail

# Use user "wagtail" to run the build commands below and the server itself.
USER wagtail

FROM base as test

# Copy the source code of the project into the container.
COPY --chown=wagtail:wagtail . .

ENTRYPOINT [ "pytest" ]

# Define the server stage
FROM base as server

Expand All @@ -45,8 +55,5 @@ COPY --chown=wagtail:wagtail entrypoint.dev.sh /app/entrypoint.dev.sh
# Make the entrypoint script executable
RUN chmod +x /app/entrypoint.dev.sh

# Use user "wagtail" to run the build commands below and the server itself.
USER wagtail

# Use the entrypoint script as the Docker entrypoint
ENTRYPOINT ["/app/entrypoint.dev.sh"]
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ build-dev:

build-prod:
@docker compose -f docker-compose.prod.yml build
@docker compose -f docker-compose.prod.yml up -d

test:
@pytest
@docker build --target test -t myproject:test -f Dockerfile.dev .
@docker run --rm myproject:test
@docker rmi myproject:test

up-dev:
@docker compose -f docker-compose.dev.yml up -d
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
build:
context: .
dockerfile: Dockerfile.dev
target: server
command: >
bash -c "./wait-for-it.sh db:5432 -- sleep 10 && python manage.py runserver 0.0.0.0:8000"
ports:
Expand All @@ -14,6 +15,16 @@ services:
depends_on:
db:
condition: service_healthy
test:
build:
context: .
dockerfile: Dockerfile.dev
target: test
env_file:
- .env
depends_on:
db:
condition: service_healthy
db:
image: postgres
env_file:
Expand Down

0 comments on commit 084d80e

Please sign in to comment.