diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..9dea50f --- /dev/null +++ b/.drone.yml @@ -0,0 +1,61 @@ +kind: pipeline +type: docker +name: Deploiement + +trigger: + event: + - push + +steps: + - name: code-analysis + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-python37 + settings: + sonar_host: https://codefirst.iut.uca.fr/sonar/ + sonar_token: + from_secret: SECRET_SONAR_TOKEN + + - name: docker-build-and-push + image: plugins/docker + settings: + dockerfile: docker/Dockerfile + context: . + registry: hub.codefirst.iut.uca.fr + mirror: https://proxy.iut.uca.fr:8443 + repo: hub.codefirst.iut.uca.fr/alix.jeudi--lemoine/memorymap_api + username: + from_secret: SECRET_REGISTRY_USERNAME + password: + from_secret: SECRET_REGISTRY_PASSWORD + + - name: deploy-database + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest + environment: + IMAGENAME: mongo:8.0.3-noble + CONTAINERNAME: memorymap_mongodb + COMMAND: create + OVERWRITE: true + CODEFIRST_CLIENTDRONE_ENV_MONGO_INITDB_ROOT_USERNAME: + from_secret: SECRET_MONGODB_USERNAME + CODEFIRST_CLIENTDRONE_ENV_MONGO_INITDB_ROOT_PASSWORD: + from_secret: SECRET_MONGODB_PASSWORD + + - name: deploy-container + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest + environment: + IMAGENAME: hub.codefirst.iut.uca.fr/alix.jeudi--lemoine/memorymap_api:latest + CONTAINERNAME: memorymap_api + COMMAND: create + OVERWRITE: true + CODEFIRST_CLIENTDRONE_ENV_MONGODB_URL: "mongodb://memorymap_mongodb:27017/" + CODEFIRST_CLIENTDRONE_ENV_MONGODB_USERNAME: + from_secret: SECRET_MONGODB_USERNAME + CODEFIRST_CLIENTDRONE_ENV_MONGODB_PASSWORD: + from_secret: SECRET_MONGODB_PASSWORD + CODEFIRST_CLIENTDRONE_ENV_MONGODB_DATABASE: + from_secret: SECRET_MONGODB_DATABASE + CODEFIRST_CLIENTDRONE_ENV_JWT_SECRET_KEY: + from_secret: SECRET_JWT_SECRET_KEY + CODEFIRST_CLIENTDRONE_ENV_JWT_ALGORITHM: + from_secret: SECRET_JWT_ALGORITHM + CODEFIRST_CLIENTDRONE_ENV_JWT_ACCESS_TOKEN_EXPIRE_MINUTES: + from_secret: SECRET_JWT_ACCESS_TOKEN_EXPIRE_MINUTES \ No newline at end of file diff --git a/app/config.py b/app/config.py index 35c3f53..3f1216e 100644 --- a/app/config.py +++ b/app/config.py @@ -1,13 +1,15 @@ +import os + # Constants for PyMongo -MONGODB_URL = "mongodb://localhost:27017/" -MONGODB_USERNAME = "mongoadmin" -MONGODB_PASSWORD = "secret" -MONGODB_DATABASE = "memorymap" +MONGODB_URL = os.getenv("MONGODB_URL", "mongodb://localhost:27017/") +MONGODB_USERNAME = os.getenv("MONGODB_USERNAME", "mongoadmin") +MONGODB_PASSWORD = os.getenv("MONGODB_PASSWORD", "secret") +MONGODB_DATABASE = os.getenv("MONGODB_DATABASE", "memorymap") # Constants for JWT -SECRET_KEY = "_2YfT44$xF.Tg_xI63UH3D7:N+>pZN2';j%>7H@?e0:Xor'pV[" # temporary of course :) -ALGORITHM = "HS256" # TODO: check if broken (don't believe) -ACCESS_TOKEN_EXPIRE_MINUTES = 30 # TODO: check what to add here / maybe need to evaluate criticity of that? +SECRET_KEY = os.getenv("JWT_SECRET_KEY", "_2YfT44$xF.Tg_xI63UH3D7:N+>pZN2';j%>7H@?e0:Xor'pV[") # temporary of course :) +ALGORITHM = os.getenv("JWT_ALGORITHM", "HS256") # TODO: check if broken (don't believe) +ACCESS_TOKEN_EXPIRE_MINUTES = os.getenv("JWT_ACCESS_TOKEN_EXPIRE_MINUTES", 30) # TODO: check what to add here / maybe need to evaluate criticity of that? # Constants for OAuth2 TOKEN_URL = "login" # Path to the auth \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..bbe752a --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,20 @@ +# Official Python image +FROM python:3.12-slim + +# Set workdir +WORKDIR /app + +# Copy the file with the requirements +COPY requirements.txt . + +# Install the package dependencies in the requirements file. +RUN pip install --no-cache-dir --upgrade -r requirements.txt + +# Copy the FastAPI app folder in the container +COPY ./app . + +# Expose API port +EXPOSE 80 + +# Launches the uvicorn server (command from offical FastAPI documentation) +CMD ["fastapi", "run", "app/main.py", "--port", "80"] \ No newline at end of file diff --git a/serializers.py b/serializers.py deleted file mode 100644 index 9176d05..0000000 --- a/serializers.py +++ /dev/null @@ -1,28 +0,0 @@ -def users_serialize(users: list) -> list: - serialized_users: list = [] - for user in users: - serialized_users.append({ - "id": str(user["_id"]), - "username": user["username"] - }) - return serialized_users - -def friends_serialize(friends: list) -> list: - serialized_friends: list = [] - for friend in friends: - serialized_friends.append({ - "id": str(friend["_id"]), - "user_id": friend["user_id"] - }) - return serialized_friends - -def pins_serialize(pins: list) -> list: - serialized_pins: list = [] - for pin in pins: - serialized_pins.append({ - "id": str(pin["_id"]), - "title": pin["title"], - "description": pin["description"] - - }) - return serialized_pins \ No newline at end of file