forked from art049/fastapi-odmantic-realworld-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
204 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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,122 @@ | ||
import random | ||
import sys | ||
import uuid | ||
|
||
import anyio | ||
import dagger | ||
|
||
|
||
async def main(): | ||
config = dagger.Config(log_output=sys.stdout) | ||
|
||
async with dagger.Connection(config) as client: | ||
base_image = "python:3.10.0-slim" | ||
|
||
# set build context | ||
src = client.host().directory(".") | ||
pc_cache = client.cache_volume("pc") | ||
|
||
# run pre-commit hooks | ||
# FIXME: pre-commit is not working because we don't mount .git inside the container | ||
# pre_commit = ( | ||
# await docker_image_dev.with_directory("/code", src) | ||
# .with_workdir("/code") | ||
# .with_mounted_cache("/cache", pc_cache) | ||
# .with_env_variable("PRE_COMMIT_HOME", "/cache") | ||
# .with_entrypoint(["/bin/bash"]) | ||
# .with_exec(["git", "remote", "-v"]) | ||
# .with_exec(["pre-commit", "run", "--all-files"]) | ||
# .stdout() | ||
# ) | ||
# print(pre_commit) | ||
|
||
# build the prod docker image | ||
docker_image_prod = await src.docker_build(target="prod") | ||
|
||
# build the dev docker image | ||
docker_image_dev = await src.docker_build(target="dev") | ||
|
||
# lint | ||
print("Running linting") | ||
lint = ( | ||
await docker_image_dev.with_directory("/code", src) | ||
.with_workdir("/code") | ||
.with_entrypoint(["/bin/sh", "-c"]) | ||
.with_exec(["/bin/bash", "scripts/lint.sh"]) | ||
.stdout() | ||
) | ||
print(lint) | ||
|
||
# format | ||
print("Running format") | ||
format = ( | ||
await docker_image_dev.with_directory("/code", src) | ||
.with_workdir("/code") | ||
.with_entrypoint(["/bin/sh", "-c"]) | ||
.with_exec(["/bin/bash", "scripts/format.sh"]) | ||
.stdout() | ||
) | ||
print(format) | ||
|
||
# unit tests | ||
print("Running unit tests") | ||
unit = ( | ||
await docker_image_dev.with_directory("/code", src) | ||
.with_workdir("/code") | ||
.with_entrypoint(["/bin/sh", "-c"]) | ||
.with_exec(["/bin/bash", "scripts/unit-tests.sh"]) | ||
.stdout() | ||
) | ||
print(unit) | ||
|
||
# coverage | ||
print("Running coverage") | ||
coverage = ( | ||
await docker_image_dev.with_directory("/code", src) | ||
.with_workdir("/code") | ||
.with_entrypoint(["/bin/sh", "-c"]) | ||
.with_exec(["/bin/bash", "scripts/coverage.sh"]) | ||
.stdout() | ||
) | ||
print(coverage) | ||
|
||
# fonctional tests | ||
print("Running fonctional tests") | ||
# FIXME: this should work but it hangs on stopping the mongo process after initial setup | ||
# mongo = ( | ||
# client.container() | ||
# .from_("bitnami/mongodb:4.4-debian-10") | ||
# .with_env_variable("MONGODB_ROOT_PASSWORD", "root") | ||
# .with_env_variable("MONGODB_USERNAME", "app") | ||
# .with_env_variable("MONGODB_PASSWORD", "app") | ||
# .with_env_variable("MONGODB_DATABASE", "test") | ||
# .with_exposed_port(27017) | ||
# .as_service() | ||
# ) | ||
mongo = client.host().service( | ||
[ | ||
dagger.PortForward( | ||
backend=27017, frontend=27017, protocol=dagger.NetworkProtocol.TCP | ||
) | ||
] | ||
) | ||
|
||
api = ( | ||
docker_image_prod | ||
.with_env_variable("MONGO_URI", "mongodb://app:app@mongo:27017/test") | ||
.with_service_binding("mongo", mongo) | ||
.with_exposed_port(8000) | ||
.as_service() | ||
) | ||
|
||
newman = ( | ||
await docker_image_dev | ||
.with_directory("/code", src) | ||
.with_workdir("/code") | ||
.with_service_binding("api", api) | ||
.with_entrypoint(["/bin/bash", "scripts/functional-tests.sh"]) | ||
.stdout() | ||
) | ||
print(newman) | ||
|
||
anyio.run(main) |
This file contains 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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
.venv | ||
.vscode | ||
.helm | ||
_CI.md | ||
.dagger | ||
.dockerignore | ||
.env | ||
.git | ||
.github | ||
.helm | ||
.mypy_cache | ||
.pytest_cache | ||
.env | ||
virtualenv | ||
README.md | ||
_CI.md | ||
.venv | ||
.vscode | ||
Conduit.postman_collection.json | ||
docker-compose*.yaml | ||
docker-compose*.yml | ||
docker/data/** | ||
Conduit.postman_collection.json | ||
README.md | ||
virtualenv |
This file contains 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 |
---|---|---|
|
@@ -4,3 +4,5 @@ ignore = | |
# See https://github.com/PyCQA/pycodestyle/issues/373 | ||
E203, | ||
W503, | ||
exclude = | ||
.dagger/*.py |
This file contains 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,39 @@ | ||
name: CI Workflow (dagger) | ||
|
||
on: | ||
push: | ||
branches: | ||
- ci/dagger | ||
|
||
jobs: | ||
realworld-tests: | ||
timeout-minutes: 10 | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
mongo: | ||
image: bitnami/mongodb:4.4-debian-10 | ||
ports: | ||
- 27017:27017 | ||
env: | ||
MONGODB_ROOT_PASSWORD: root | ||
MONGODB_USERNAME: app | ||
MONGODB_PASSWORD: app | ||
MONGODB_DATABASE: test | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
cache: "pip" | ||
|
||
- name: Dagger install | ||
run: pip install dagger.io==0.9.3 | ||
|
||
- name: Run dagger tests | ||
run: python .dagger/ci.py |
This file contains 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 @@ | ||
dagger 0.6.1 |
This file contains 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 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,5 @@ | ||
Creating virtualenv fastapi-odmantic-example-MATOk_fk-py3.10 in /root/.cache/pypoetry/virtualenvs | ||
INFO: Started server process [8] | ||
INFO: Waiting for application startup. | ||
INFO: Application startup complete. | ||
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) |
This file contains 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 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 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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
#!/bin/bash | ||
|
||
docker run --rm -p 27017:27017 --name fastapi-odmantic-example -d mongo:4 | ||
set -e | ||
|
||
docker run --rm -d --name mongodb \ | ||
-e MONGODB_ROOT_PASSWORD="root" \ | ||
-e MONGODB_USERNAME="app" \ | ||
-e MONGODB_PASSWORD="app" \ | ||
-e MONGODB_DATABASE="test" \ | ||
-p 27017:27017 \ | ||
bitnami/mongodb:4.4-debian-10 |
This file contains 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
#!/bin/bash | ||
docker stop fastapi-odmantic-example | ||
|
||
set -e | ||
|
||
docker stop mongodb |
This file contains 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