Oipie API repository implements the API that will be consumed by the mobile apps.
Prerequisites:
Now:
git clone git@github.com:Oipie/oipie-api-core.git
cd oipie-api-core
poetry install
docker-compose up [-d] --build postgres # starts DDBB
flask db init # creates database if not exists
flask db upgrade # runs all database migrations
flask --app "src/app.py" run # starts the server in development mode
You are now good ready to go!! 👯
We are using virtual environments to manage our dependencies separated from other Python projects. Dependencies are managed using poetry.
poetry add [--group dev] <package==version> # adds a new dependency
If no version is specified, the latest version will be installed with caret, but the caret should be removed. If that is the case, just regenerate lockfile.
poetry lock # regenerates lockfile
Dependency injection have been implemented using dependency-injection
python library. Following the documentation and the tutorial.
To use dependecy injection have to take into account that providers have to be defined on the Container.py
defined into src/confg/
. Actual configuration of the dependency injection resolver is only set up to resolve dependencies inside the src/api/
.
We use Docker as a utility tool, mainly for running a Postgres, which is the Database that we have deployed with RDS. In the docker-compose.yml
you have two services:
postgres
: A postgres database that we use for starting the API in development mode and running the integration tests locally.web
: Our API running in production mode with Gunicorn.
For starting the full application you can run the following command
docker-compose up [-d] --build
Since we are using Heroku containers (SENKIU Heroku) as our deploying platform, we need to have two different Dockerfiles regarding Heroku container images:
Dockerfile.web
--> Starts gunicorn at specified port by HerokuDockerfile.release
--> Executes pre-deploy scripts. In this case we just launch migrations
As soon as we stop using Heroku these files will be removed PERMANENTLY from the project
If you're using a M1 chipset based computer, you may encounter some problems when interacting to web
container. The main reason is because some pip
dependencies regarding SQLAlchemy
. This can be solved by exporting DOCKER_DEFAULT_PLATFORM
variable to linux/amd64
:
export DOCKER_DEFAULT_PLATFORM=linux/amd64
or adding it to your .bashrc
/.zshrc
or the tool you are using. Another alternative is to simply use Rosetta. Please be adviced that any of these workarounds may make your Docker performance a little bit lower.
We use Heroku to publish this API so it can be consumed. Heroku settings are set in repositorie's CI/CD workflows, so you do not need anything to worry about to this matter.
For now we just have a main environment that you can access through this URL
- Python
- Flask
In order to be aligned with the Oipie DevOps Team, this repository is organized with the following folder structure:
- src - contains all source code of the application.
- api: code all controllers and DTO
- config: configuration files
- core: all modules on the application.
- tests: E2E tests and fixtures
- .github - Github actions integration for CI/CD
The architecture follows the principles from Hexagonal Architecture.
All the main code of the application lives under src
- We are using Pytest
- Unitary Tests are paired with the element that tests. For example
test_recipe.py
is next torecipe.py
. - Acceptance tests lives under the
tests
directory.
Continous deployment is executed only on master brach after all previous actions have succed.
821f0cad68385585254999a06e6ed07a24d86eb2
The project was mainly developed by Jaume Moreno and Diego Machín for Acid Tango