- Developer Quickstart
- Tests
- Project Structure
- VScode Extensions
- Debugging
- Workflows
- Contributing
- License
Welcome to the project! Follow these steps to get the service up and running for development.
Create a .env
file in the project root. This file configures both FastAPI and Docker.
Sample .env
File
# PostgreSQL Configuration
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_SERVER=postgres # localhost if launching without Docker
POSTGRES_PORT=5432
POSTGRES_DB=openlabsx
# Docker Compose Configuration
POSTGRES_DEBUG_PORT=5432 # Expose PostgreSQL on host port for debugging
- Run with Docker (Recommended for most users)
- Run Locally (Without Docker) (For local development setups)
Prerequisites
- Install Docker and
docker compose
.
Steps
-
Build and Run Containers:
docker compose up
Note: If you get a
KeyError: 'ContainerConfig'
error, rundocker container prune -f
to remove stopped containers. -
Congrats! It's working! π
API:
- API Documentation: http://127.0.0.1:8000/docs
- Health Check Endpoint: http://127.0.0.1:8000/api/v1/health/ping
Database:
-
PostgreSQL is available locally on port
5432
(configured viaPOSTGRES_DEBUG_PORT
). -
Connect using:
psql -h localhost -p 5432 -U postgres -d openlabsx
See Python Environment Setup to configure your virtual environment.
Prerequisites
- Install and configure PostgreSQL.
Steps
-
Start the API Server:
fastapi dev src/app/main.py
-
Congrats! It's working! π
- API Documentation: http://127.0.0.1:8000/docs
- Health Check Endpoint: http://127.0.0.1:8000/api/v1/health/ping
Prerequisites
- Install Python 3.12+.
Steps
-
Create Virtual Environment:
python3.12 -m venv venv
-
Activate Virtual Environment:
source venv/bin/activate
-
Install Dependencies:
pip install --upgrade pip pip install -r requirements.txt pip install -r dev-requirements.txt
-
Run Pre-Commit Hook (Verify Setup):
pre-commit run --all-files
pytest
pytest
open htmlcov/index.html
All tests are located in tests/
. The structure of the tests/
directory mirrors the src/app/
directory structure.
src/
βββ app
βββ api
β βββ v1 # API Version 1 routes (/v1)
| | # ------------------------- #
β βββ health.py # /health routes
β βββ templates.py # /templates routes
|
βββ core # Core Application Logic
| | # ---------------------- #
β βββ cdktf/ # CDKTF Libraries
β βββ config.py # Application settings
β βββ db # Database configuration
β β βββ database.py
β βββ logger.py # Shared logger utility
β βββ setup.py # Application setup logic
|
βββ enums # Enums (Constants)
| | # ---------------- #
β βββ providers.py # Defined cloud providers
β βββ specs.py # Preset VM hardware configurations
|
βββ schemas # API Schema (Objects)
| | # ------------------ #
β βββ openlabs.py # OpenLabs network objects
β βββ templates.py # Template objects
|
βββ validators # Data Validation
| | # --------------- #
| βββ network.py # Networking config input validation
|
βββ main.py # Main App Entry Point
This is a list of extensions that this project was configured to work with. It has only been tested on VScode.
Extensions:
You can configure Black to format on save (Ctrl
+S
) with the following configuration in Preferences: Open User Settings (JSON) (Ctrl
+Shift
+P
).
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
To debug with the python debugger extension, use the docker-compose.dev.yaml
file.
docker compose -f docker-compose.dev.yml up
The app will only be started once you run the debugger in VScode.
All changes made to code in your local directory will be applied to the container app and should reload automatically.
This workflow runs an identical set of checks that the .pre-commit-config.yaml
runs. This means that if you were able to commit you should pass this workflow.
This workflow checks if you correctly labeled your PR for the release.yml
workflow to create a proper release. This workflow will recheck when new labels are added to the PR.
Setup: To setup this workflow, you just need a CONTRIBUTING.md
file in the root of your project. At minimum it should have a section called No semver label!
(Link to example). The workflow will automatically link this section when it fails so user's can fix their PRs. Feel free to copy the example.
This workflow automatically creates GitHub tagged releases based on the tag of the PR.
Setup:
-
Install the Auto release tool (Latest release)
-
Navigate to the repository
cd /path/to/repo/API/
-
Initialize Auto
For this step the choose
Git Tag
as the package manager plugin. Fill in the rest of the information relevant to the repo and keep all default values.When prompted for a Github PAT, go to the next step.
auto init
-
Create repository tags
This will allow you to tag your PRs and control the semantic version changes.
auto create-labels
-
Create a GitHub App
Note: OpenLabsX already has the
auto-release-app
installed. Skip to step 7.This allows us to enforce branch protection rules while allowing the Auto release tool to bypass the protections when running automated workflows. (Source: Comment Link)
Link: Making authenticated API requests with a GitHub App in a GitHub Actions workflow
-
Configure the app with the following permissions
- Actions (read/write)
- Administration (read/write)
- Contents (read/write)
-
Update the ruleset bypass list to include the GitHub App
-
Add GitHub app variables and secrets
Secrets:
AUTO_RELEASE_APP_PRIVATE_KEY
AUTO_RELEASE_APP_ID