Skip to content

Commit

Permalink
Merge branch 'master' into upgrade-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
javadzarezadeh authored Sep 22, 2024
2 parents d884057 + b262c20 commit de70316
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
- run: docker compose down -v --remove-orphans
- run: docker compose up -d
- name: Lint
run: docker compose exec -T backend bash /app/scripts/lint.sh
run: docker compose exec -T backend bash scripts/lint.sh
- name: Run tests
run: docker compose exec -T backend bash /app/tests-start.sh "Coverage for ${{ github.sha }}"
run: docker compose exec -T backend bash scripts/tests-start.sh "Coverage for ${{ github.sha }}"
- run: docker compose down -v --remove-orphans
- name: Store coverage files
uses: actions/upload-artifact@v4
Expand Down
8 changes: 2 additions & 6 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:latest
FROM python:3.10

WORKDIR /app/

Expand All @@ -17,14 +17,10 @@ RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; els

ENV PYTHONPATH=/app

COPY ./scripts/ /app/
COPY ./scripts /app/scripts

COPY ./alembic.ini /app/

COPY ./prestart.sh /app/

COPY ./tests-start.sh /app/

COPY ./app /app/app

CMD ["fastapi", "run", "--workers", "4", "app/main.py"]
8 changes: 4 additions & 4 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ If you use GitHub Actions the tests will run automatically.
If your stack is already up and you just want to run the tests, you can use:

```bash
docker compose exec backend bash /app/tests-start.sh
docker compose exec backend bash scripts/tests-start.sh
```

That `/app/tests-start.sh` script just calls `pytest` after making sure that the rest of the stack is running. If you need to pass extra arguments to `pytest`, you can pass them to that command and they will be forwarded.
That `/app/scripts/tests-start.sh` script just calls `pytest` after making sure that the rest of the stack is running. If you need to pass extra arguments to `pytest`, you can pass them to that command and they will be forwarded.

For example, to stop on first error:

```bash
docker compose exec backend bash /app/tests-start.sh -x
docker compose exec backend bash scripts/tests-start.sh -x
```

### Test Coverage
Expand Down Expand Up @@ -155,7 +155,7 @@ If you don't want to use migrations at all, uncomment the lines in the file at `
SQLModel.metadata.create_all(engine)
```

and comment the line in the file `prestart.sh` that contains:
and comment the line in the file `scripts/prestart.sh` that contains:

```console
$ alembic upgrade head
Expand Down
7 changes: 5 additions & 2 deletions backend/prestart.sh → backend/scripts/prestart.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#! /usr/bin/env bash

set -e
set -x

# Let the DB start
python /app/app/backend_pre_start.py
python app/backend_pre_start.py

# Run migrations
alembic upgrade head

# Create initial data in DB
python /app/app/initial_data.py
python app/initial_data.py
7 changes: 7 additions & 0 deletions backend/scripts/tests-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /usr/bin/env bash
set -e
set -x

python app/tests_pre_start.py

bash scripts/test.sh "$@"
7 changes: 0 additions & 7 deletions backend/tests-start.sh

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ services:
db:
condition: service_healthy
restart: true
command: bash prestart.sh
command: bash scripts/prestart.sh
env_file:
- .env
environment:
Expand Down
2 changes: 2 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Refactors

* 🔧 Use plain base official Python Docker image. PR [#1351](https://github.com/fastapi/full-stack-fastapi-template/pull/1351) by [@tiangolo](https://github.com/tiangolo).
* 🚚 Move location of scripts to simplify file structure. PR [#1352](https://github.com/fastapi/full-stack-fastapi-template/pull/1352) by [@tiangolo](https://github.com/tiangolo).
* ♻️ Refactor prestart (migrations), move that to its own container. PR [#1350](https://github.com/fastapi/full-stack-fastapi-template/pull/1350) by [@tiangolo](https://github.com/tiangolo).
* ♻️ Include `FRONTEND_HOST` in CORS origins by default. PR [#1348](https://github.com/fastapi/full-stack-fastapi-template/pull/1348) by [@tiangolo](https://github.com/tiangolo).
* ♻️ Simplify domains with `api.example.com` for API and `dashboard.example.com` for frontend, improve local development with `localhost`. PR [#1344](https://github.com/fastapi/full-stack-fastapi-template/pull/1344) by [@tiangolo](https://github.com/tiangolo).
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ fi

docker-compose build
docker-compose up -d
docker-compose exec -T backend bash /app/tests-start.sh "$@"
docker-compose exec -T backend bash scripts/tests-start.sh "$@"
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set -x
docker compose build
docker compose down -v --remove-orphans # Remove possibly previous broken stacks left hanging after an error
docker compose up -d
docker compose exec -T backend bash /app/tests-start.sh "$@"
docker compose exec -T backend bash scripts/tests-start.sh "$@"
docker compose down -v --remove-orphans

0 comments on commit de70316

Please sign in to comment.