This repository is for experimentation only, for the study of the infrastructure and development cycle of the portfolio project for DuocUC.
- Notes
- Published API
- How to publish the API to DetaSpace
- How to set up the local environment
- How to Manage the Environment
- Project Structure
- References:
- Bug: If I've updated the repository secrets, I need to update the environment variables in Deta Space because they are not updated automatically.
- ACCESS_TOKEN:
deta access token
- PROJECT_ID:
deta project id
- MONGO_USERNAME:
mongo username
- MONGO_PASSWORD:
mongo password
- MONGO_CLUSTER:
mongo cluster
- Make a pull request to the
main
branch:- The GitHub Action will run the tests for being able to merge the pull request.
- When merged, the GitHub Action will publish the API to Deta Space.
-
Linux:
-
Windows:
- Docker Desktop
- Manage docker in wsl2 distro terminal (Optional but recommended because it's faster and enable hot reload):
- After installing Docker Desktop, install a Linux distro with WSL2: Tutorial
- Enable Docker support in your WSL 2 distro: Tutorial
- (optional) configure the WSL2 for comfortable development:
- Notes:
- Clone the repository in the wsl2 distro filesystem, not in Windows filesystem.
- You can manage the containers in Windows by referring to the WSL2 distro's filesystem..
- If you don´t want to edit the files in the WSL2 distro, you can edit them in Windows(access Linux from Windows) and the changes will be reflected in the WSL2 distro filesystem.
- Execute
docker compose up -d
at the root of the project (if you encounter an error about the compose command, try withdocker-compose up -d
, as this may occur with older versions of Docker). - When finished, navegate to
localhost:8000/docs
to view the api documentation
- Node v20.11.1
- Ionic 7.1.1:
npm install -g @ionic/cli@7.1.1
- Angular 17.1.1:
npm install -g @angular/cli@17.1.1
- Android Studio
- Ensure that the FastAPI and MongoDB containers are running.
- Open your terminal and navigate to the ./mobile/coleccti-mate/ folder.
- Execute the command:
ionic serve
- Optional: To test the app with the production configuration (which accesses the DetaSpace API instead of the local API), use:
ionic serve --prod
- When finished, navegate to
localhost:8100/
to view the Ionic app.
- Execute
docker compose start
at the root of the project to start the containers. - Execute
docker compose stop
at the root of the project to stop the containers. - Note:
- The API container have hot reload enabled, so you don't need to restart the containers when you make changes to the code.
- When the containers are running, execute
docker exec -it coleccionista-api-test bash
to enter the container. - Once inside the container:
- Execute
pytest
to run all the tests. - Execute
pytest -k <filename>.py
to run a specific test. - To see the verbose output of the tests, add the
-v
or-vv
flags to the previous commands.
- Execute
.github/
- GitHub Actions workflows (CI/CD)api/
- API configuration files and source codemobile/
- Ionic app configuration files and source code.dockerignore
- Files to ignore when building the Docker images.gitignore
- Files to ignore when pushing to the repository.spaceignore
- Files to ignore when deploying to Deta SpaceREADME.md
- Documentation of the projectSpacefile
- Deta Space configuration file (for deployment)compose.yaml
- Docker Compose configuration file for local development
app/
- API source code (FastAPI)Dockerfile
- Docker configuration file for the FastAPI apprequirements.txt
- Python dependencies for the FastAPI app
dependencies/
- Avaliable dependencies for the API (db, auth, etc.)models/
- Pydantic models for be used in the endpointsrouters/
- API source code for each set of endpoints ( for separation of concerns)tests/
- API tests (pytest)README.md
- Specific documentation for the API (not as a replacement for the Swagger docs)main.py
- API main file ( app creation, routers addition, definition of the lifespan events, etc. )settings.py
- Enums; environment variables, secrets, etc.
./coleccti-mate/
- APP source code (Ionic)Dockerfile
- Docker configuration file for the Ionic app
- API - Project Documentation
- FastAPI - web
- FastAPI - How to mantain global pool connections
- FastAPI - Lifespan Events
- FastAPI - Simple OAuth2 with Password and Bearer
- FastAPI - OAuth2 with Password (and hashing), Bearer with JWT tokens
- FastAPI - Testing
- FastAPI - Advanced testing, lifespan
- DetaSpace - Run a Python App on DetaSpace
- DetaSpace - GitHub Action for DetaSpace
- DetaSpace - Setting Environment Variables within a Spacefile