Skip to content

Commit

Permalink
Merge branch 'main' into add-api-db-provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
loco-philippe authored Jul 16, 2024
2 parents 44c136b + 1be823b commit 7c701cb
Show file tree
Hide file tree
Showing 17 changed files with 1,358 additions and 285 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ build-notebook: ## build custom jupyter notebook image
@$(COMPOSE) build notebook
.PHONY: build-notebook

build-opendata: ## build opendata image
@$(COMPOSE) build opendata
.PHONY: build-opendata

down: ## stop and remove all containers
@$(COMPOSE) down
.PHONY: down
Expand All @@ -80,18 +84,26 @@ logs-notebook: ## display notebook logs (follow mode)
@$(COMPOSE) logs -f notebook
.PHONY: logs-notebook

logs-opendata: ## display opendata logs (follow mode)
@$(COMPOSE) logs -f opendata
.PHONY: logs-opendata

run: ## run the api server (and dependencies)
$(COMPOSE) up -d api
.PHONY: run

run-all: ## run the whole stack
$(COMPOSE) up -d api keycloak metabase notebook
$(COMPOSE) up -d api keycloak metabase notebook opendata
.PHONY: run-all

run-notebook: ## run the notebook service
$(COMPOSE) up -d notebook
.PHONY: run-notebook

run-opendata: ## run the opendata service
$(COMPOSE) up -d opendata
.PHONY: run-opendata

status: ## an alias for "docker compose ps"
@$(COMPOSE) ps
.PHONY: status
Expand Down
13 changes: 13 additions & 0 deletions bin/data7
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eo pipefail

declare DOCKER_USER
DOCKER_UID="$(id -u)"
DOCKER_GID="$(id -g)"
DOCKER_USER="${DOCKER_UID}:${DOCKER_GID}"

DOCKER_USER=${DOCKER_USER} \
DOCKER_UID=${DOCKER_UID} \
DOCKER_GID=${DOCKER_GID} \
docker compose run --rm opendata pipenv run data7 "$@"
4 changes: 3 additions & 1 deletion bin/pipenv
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

set -eo pipefail

docker compose run --rm --no-deps -u "pipenv:pipenv" api pipenv "$@"
declare service="${SERVICE:-api}"

docker compose run --rm --no-deps -u "pipenv:pipenv" "${service}" pipenv "$@"
21 changes: 19 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ services:
- ./bin/kc-init:/usr/local/bin/kc-init

metabase:
image: metabase/metabase:v0.50.8
image: metabase/metabase:v0.50.13
ports:
- 3000:3000
env_file:
Expand Down Expand Up @@ -87,6 +87,23 @@ services:
depends_on:
- postgresql

opendata:
build:
context: ./src/opendata
args:
DOCKER_UID: ${DOCKER_UID:-1000}
DOCKER_GID: ${DOCKER_GID:-1000}
user: ${DOCKER_USER:-1000}
image: "qualicharge:opendata"
ports:
- "8020:8000"
env_file:
- env.d/opendata
volumes:
- ./src/opendata:/app
depends_on:
- postgresql

# -- tools
curl:
image: curlimages/curl:8.8.0
Expand All @@ -107,7 +124,7 @@ services:
- env.d/metabase

terraform:
image: hashicorp/terraform:1.9.0
image: hashicorp/terraform:1.9.2
env_file:
- env.d/terraform
user: ${DOCKER_USER:-1000}
Expand Down
4 changes: 4 additions & 0 deletions env.d/opendata
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ENV_FOR_DYNACONF=development
DATA7_DATABASE_URL=postgresql+asyncpg://qualicharge:pass@postgresql:5432/qualicharge-api
DATA7_HOST=0.0.0.0
DATA7_PORT=8000
2 changes: 1 addition & 1 deletion provisioning/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
metabase = {
source = "bnjns/metabase"
version = "0.9.0"
version = "0.9.1"
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ geoalchemy2 = {extras = ["shapely"], version = "==0.15.1"}
httpx = "==0.27.0"
passlib = {extras = ["bcrypt"], version = "==1.7.4"}
psycopg2-binary = "==2.9.9"
pydantic-extra-types = {extras = ["all"], version = "==2.8.2"}
pydantic-extra-types = {extras = ["all"], version = "==2.9.0"}
pydantic-settings = "==2.3.4"
pyjwt = "==2.8.0"
questionary = "==2.0.1"
sentry-sdk = {extras = ["fastapi"], version = "==2.7.1"}
setuptools = "==70.1.1"
sentry-sdk = {extras = ["fastapi"], version = "==2.8.0"}
setuptools = "==70.2.0"
sqlalchemy-timescaledb = "==0.4.1"
sqlmodel = "==0.0.19"
typer = "==0.12.3"
Expand All @@ -28,11 +28,11 @@ black = "==24.4.2"
csvkit = "==2.0.0"
honcho = "==1.1.0"
mypy = "==1.10.1"
polyfactory = "==2.16.0"
polyfactory = "==2.16.1"
pytest = "==8.2.2"
pytest-cov = "==5.0.0"
pytest-httpx = "==0.30.0"
ruff = "==0.5.0"
ruff = "==0.5.1"
types-passlib = "==1.7.7.20240327"
types-python-jose = "==3.3.4.20240106"

Expand Down
371 changes: 200 additions & 171 deletions src/api/Pipfile.lock

Large diffs are not rendered by default.

232 changes: 128 additions & 104 deletions src/client/poetry.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/opendata/.secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Data7 secrets.
#

# Will be set via environment variables

# ---- DEFAULT ---------------------------------
default:
DATABASE_URL: ""
15 changes: 15 additions & 0 deletions src/opendata/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Configured Data7 0.5.0

[unreleased]: https://github.com/MTES-MCT/qualicharge/
47 changes: 47 additions & 0 deletions src/opendata/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -- Base image --
FROM python:3.12-slim

ARG DOCKER_UID 1000
ARG DOCKER_GID 1000

# Upgrade system packages to install security updates
RUN apt-get update && \
apt-get -y upgrade && \
rm -rf /var/lib/apt/lists/*

# Upgrade pip to its latest release to speed up dependencies
# installation
RUN pip install --upgrade pip && \
pip install pipenv==2024.0.1

# Pipenv configuration
ENV PIPENV_USER_UID ${DOCKER_UID}
ENV PIPENV_USER_GID ${DOCKER_GID}
ENV PIPENV_USER_NAME pipenv
ENV PIPENV_GROUP_NAME pipenv
ENV PIPENV_USER_HOME /opt/pipenv/
ENV PIPENV_CUSTOM_VENV_NAME qualicharge

# Create a pipenv user and group
RUN groupadd \
-g ${PIPENV_USER_GID} \
${PIPENV_GROUP_NAME} && \
useradd -rm \
-d ${PIPENV_USER_HOME} \
-s /bin/bash \
-u ${PIPENV_USER_UID} \
-g ${PIPENV_USER_GID} \
${PIPENV_USER_NAME}

# /app will be our working directory
RUN mkdir /app && \
chown ${PIPENV_USER_NAME}:${PIPENV_GROUP_NAME} /app

# -- build (⚠️ development only) --
COPY --chown="${PIPENV_USER_NAME}:${PIPENV_GROUP_NAME}" . /app
WORKDIR /app
USER ${PIPENV_USER_NAME}:${PIPENV_GROUP_NAME}
RUN pipenv install -de .

# -- Run --
CMD pipenv run honcho start
15 changes: 15 additions & 0 deletions src/opendata/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
data7 = "==0.5.0"
databases = {extras = ["asyncpg"], version = "==0.9.0"}

[dev-packages]
honcho = "==1.1.0"
setuptools = "==70.1.1"

[requires]
python_version = "3.12"
Loading

0 comments on commit 7c701cb

Please sign in to comment.