Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Data7-based opendata service #116

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 @@ -76,18 +80,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 "$@"
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
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 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
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