Skip to content

Commit 1fd25df

Browse files
authored
πŸ”– Migrate FastQL to Poetry & Improve DockerFile (#16)
chore(dev): Migrate to Poetry
2 parents 88420ab + 61b6942 commit 1fd25df

36 files changed

+2573
-221
lines changed

β€Ž.env.exampleβ€Ž

Lines changed: 0 additions & 4 deletions
This file was deleted.

β€Ž.github/workflows/build.ymlβ€Ž

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Docker Image
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 10
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Build
18+
run: docker build --tag fastql --file docker/Dockerfile .
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Docker
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
schedule:
10+
- cron: '29 4 * * *'
11+
push:
12+
branches: [ master ]
13+
# Publish semver tags as releases.
14+
tags: [ 'v*.*.*' ]
15+
pull_request:
16+
branches: [ master ]
17+
18+
env:
19+
# Use docker.io for Docker Hub if empty
20+
REGISTRY: ghcr.io
21+
# github.repository as <account>/<repo>
22+
IMAGE_NAME: ${{ github.repository }}
23+
24+
25+
jobs:
26+
build:
27+
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
packages: write
32+
# This is used to complete the identity challenge
33+
# with sigstore/fulcio when running outside of PRs.
34+
id-token: write
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v2
39+
40+
# Install the cosign tool except on PR
41+
# https://github.com/sigstore/cosign-installer
42+
- name: Install cosign
43+
if: github.event_name != 'pull_request'
44+
uses: sigstore/cosign-installer@1e95c1de343b5b0c23352d6417ee3e48d5bcd422
45+
with:
46+
cosign-release: 'v1.4.0'
47+
48+
49+
# Workaround: https://github.com/docker/build-push-action/issues/461
50+
- name: Setup Docker buildx
51+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
52+
53+
# Login against a Docker registry except on PR
54+
# https://github.com/docker/login-action
55+
- name: Log into registry ${{ env.REGISTRY }}
56+
if: github.event_name != 'pull_request'
57+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
58+
with:
59+
registry: ${{ env.REGISTRY }}
60+
username: ${{ github.actor }}
61+
password: ${{ secrets.GITHUB_TOKEN }}
62+
63+
# Extract metadata (tags, labels) for Docker
64+
# https://github.com/docker/metadata-action
65+
- name: Extract Docker metadata
66+
id: meta
67+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
68+
with:
69+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
70+
71+
# Build and push Docker image with Buildx (don't push on PR)
72+
# https://github.com/docker/build-push-action
73+
- name: Build and push Docker image
74+
id: build-and-push
75+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
76+
with:
77+
context: .
78+
push: ${{ github.event_name != 'pull_request' }}
79+
tags: ${{ steps.meta.outputs.tags }}
80+
labels: ${{ steps.meta.outputs.labels }}
81+
82+
# Sign the resulting Docker image digest except on PRs.
83+
# This will only write to the public Rekor transparency log when the Docker
84+
# repository is public to avoid leaking data. If you would like to publish
85+
# transparency data even for private images, pass --force to cosign below.
86+
# https://github.com/sigstore/cosign
87+
- name: Sign the published Docker image
88+
if: ${{ github.event_name != 'pull_request' }}
89+
env:
90+
COSIGN_EXPERIMENTAL: "true"
91+
# This step uses the identity token to provision an ephemeral certificate
92+
# against the sigstore community Fulcio instance.
93+
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}

β€ŽDockerfileβ€Ž

Lines changed: 0 additions & 19 deletions
This file was deleted.

β€ŽMakefileβ€Ž

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ down:
1818
build:
1919
docker-compose build
2020

21-
bash:
22-
docker-compose run --rm backend bash
23-
24-
lint:
25-
docker-compose run --rm backend pre-commit run --all-files
21+
test:
22+
docker-compose up -d && docker-compose run --rm fastql bash -c "pytest"
2623

2724
clean:
2825
find . -name '*.pyc' -exec rm -f {} +

β€ŽREADME.mdβ€Ž

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
![fastql](.github/header.svg)
1+
# FastQL - FastAPI GraphQL Playground πŸ”§
22

3-
# FastQL - FastAPI GraphQL Playground
3+
![fastql](.github/header.svg)
44

5-
Generate a FullStack playground using FastAPI and GraphQL and Ariadne :rocket:.
5+
<p align="center">
6+
<em>Generate a FullStack playground using FastAPI and GraphQL and Ariadne ⚑</em>
7+
</p>
68

79
This Repository is based on this Article [Getting started with GraphQL in Python with FastAPI and Ariadne](https://www.obytes.com/blog/getting-started-with-graphql-in-python-with-fastapi-and-ariadne), Read Article to know how to use it.
810

9-
## Overview
11+
## Overview πŸ“Œ
1012

1113
- FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
1214
- GraphQL used to create a schema to describe all the possible data that clients can query through that service. A GraphQL schema is made up of object types, which define which kind of object you can request and what fields it has.
1315
- Ariadne is a Python library for implementing GraphQL servers using schema-first approach.
1416

1517
## Features
1618

17-
- Full **Docker** integration (Docker based).
19+
- Full Docker integration (Docker based).
20+
- Docker Compose integration and optimization for local development.
21+
- Production ready Python web server using Uvicorn and Gunicorn.
1822
- **GraphQL** playground based on Graphene and Ariadne.
1923
- **Docker Compose** integration and optimization for local development.
2024
- **Production ready** Python web server using Uvicorn.
@@ -27,11 +31,6 @@ This Repository is based on this Article [Getting started with GraphQL in Python
2731

2832
## Getting Started
2933

30-
### Prerequisites
31-
32-
- Python 3.8.6 or higher.
33-
- Docker.
34-
3534
### Project setup
3635

3736
```sh
@@ -42,21 +41,6 @@ $ git clone https://github.com/obytes/fastql.git
4241
$ cd fastql
4342
```
4443

45-
### Creating virtual environment
46-
47-
- Create a virtual environment using virtualenv.
48-
49-
```shell
50-
# creating virtual environment
51-
$ virtualenv venv
52-
53-
# activate virtual environment
54-
$ source venv/bin/activate
55-
56-
# install all dependencies
57-
$ pip install -r requirements.txt
58-
```
59-
6044
## Running the Docker Container
6145

6246
- We have the Dockerfile created in above section. Now, we will use the Dockerfile to create the image of the FastAPI app and then start the FastAPI app container.
@@ -77,36 +61,6 @@ $ make start
7761

7862
While i use `HTTPX` an HTTP client for Python 3, to test the API, most of the tests are using a live log thats why need before to run a server using `uvicorn` and migrate the database, then you will have the ability to run the tests. To have a clean environment, recommended to use Docker for that, when you start the containers try to open the application container and then run `pytest` to test the API.
7963

80-
### Environment variables
81-
82-
```sh
83-
SECRET_KEY #Secret Key
84-
QUEUE # RabbitMQ Link
85-
DATABASE_URL # Database URL
86-
ACCESS_TOKEN_EXPIRE_SECONDS # Access Token Expire Seconds
87-
```
88-
89-
> change all the environment variables in the `.env.example` and don't forget to rename it to `.env`.
90-
91-
## Preconfigured Packages
92-
93-
Includes preconfigured packages to kick start FastQL by just setting appropriate configuration.
94-
95-
| Package | Usage |
96-
| ------------------------------------------------------------ | ---------------------------------------------------------------- |
97-
| [FastAPI](https://fastapi.tiangolo.com/) | FastAPI is a modern, fast (high-performance), web framework for developing APIs with Python 3.6+ based on standard Python type hints. |
98-
| [GraphQL](https://graphql.org/) | GraphQL used to create a schema to describe all the possible data that clients can query through that service. A GraphQL schema is made up of object types, which define which kind of object you can request and what fields it has. |
99-
| [Ariadne](https://ariadnegraphql.org/) | Ariadne is a Python library for implementing GraphQL servers using schema-first approach. |
100-
101-
## Contributing
102-
103-
- If you have any questions or suggestions, please open an issue or create a pull request.
104-
- If you are a contributor, please check out:
105-
- Is your pull request or issue relate with FastAPI?
106-
- Is your pull request or issue relate with GraphQL?
107-
- And make sure you take a look at the schema of the GraphQL playground. [schema.graphql](graphql/schema.graphql)
108-
- Also for People who gonna add a new features or fix somethings please make sure that its build on Docker.
109-
11064
## License
11165

112-
This project is licensed under the terms of the MIT license.
66+
This project is licensed under the terms of the MIT license.

β€Žalembic.iniβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ version_path_separator = os # default: use os.pathsep
5050
# are written from script.py.mako
5151
# output_encoding = utf-8
5252

53-
sqlalchemy.url = postgresql://postgres:password@localhost/fastql
53+
sqlalchemy.url = postgresql://postgres:postgres@localhost/FastQL
5454

5555

5656
[post_write_hooks]
File renamed without changes.

β€Žapi/mutations.pyβ€Ž renamed to β€Žapp/api/mutations.pyβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from ariadne import MutationType, convert_kwargs_to_snake_case
44

5-
from core import crud, rabbit
6-
from database import config, data
7-
from schemas import security
8-
from schemas.error import MyGraphQLError
5+
from app.core import crud, rabbit
6+
from app.database import config, data
7+
from app.schemas import security
8+
from app.schemas.error import MyGraphQLError
99

1010

1111
@convert_kwargs_to_snake_case

0 commit comments

Comments
Β (0)