From c596d202981abd475600a89b0dd95f9e1d63187e Mon Sep 17 00:00:00 2001 From: cballevre Date: Thu, 1 Feb 2024 18:38:43 +0100 Subject: [PATCH] feat: Use SQS trigger from scaleway --- .env.example | 12 ++++++------ .github/workflows/cd.yml | 12 +++++++++--- Dockerfile | 2 +- serverless.yml | 15 ++++++++++++--- src/server.py | 9 +++++++++ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index babf45e..d7d00cc 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,6 @@ DATABASE_URL=mongodb+srv://username:password@example.mongodb.net/?retryWrites=true&w=majority DATABASE_NAME=Astrolabe -SCW_REGION="fr-par" -SCW_ACCESS_KEY_ID= -SCW_SECRET_ACCESS_KEY= -SCW_REGISTRY="registry.fr-par.scw.cloud" - S3_ENDPOINT="https://s3.fr-par.scw.cloud" S3_BUCKET='astrolabe-expeditions-data' S3_ID= @@ -15,4 +10,9 @@ SQS_REGION="fr-par" SQS_ENDPOINT="https://sqs.mnq.fr-par.scaleway.com" SQS_ID= SQS_SECRET= -SQS_QUEUE_URL= \ No newline at end of file +SQS_QUEUE_URL= + +## Only for deployement on Scaleway +SCW_PROJECT= +SCW_TOKEN= +SCW_REGISTRY="registry.fr-par.scw.cloud" \ No newline at end of file diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 8c351c6..eb42f65 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -14,7 +14,7 @@ jobs: uses: docker/login-action@v3 with: username: nologin - password: ${{ secrets.SCW_SECRET_ACCESS_KEY }} + password: ${{ secrets.SCW_TOKEN }} registry: ${{ secrets.SCW_REGISTRY }} - name: Build the Docker image run: docker build . -t ${{ secrets.SCW_REGISTRY }}/ae-data-processing:latest @@ -31,6 +31,12 @@ jobs: args: -c "serverless plugin install --name serverless-scaleway-functions && serverless deploy" entrypoint: /bin/sh env: - SCW_ACCESS_KEY_ID: ${{ secrets.SCW_ACCESS_KEY_ID }} - SCW_SECRET_ACCESS_KEY: ${{ secrets.SCW_SECRET_ACCESS_KEY }} + SCW_PROJECT: ${{ secrets.SCW_PROJECT }} + SCW_TOKEN: ${{ secrets.SCW_TOKEN }} SCW_REGISTRY: ${{ secrets.SCW_REGISTRY }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + DATABASE_NAME: ${{ secrets.DATABASE_NAME }} + S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }} + S3_BUCKET: ${{ secrets.S3_BUCKET }} + S3_ID: ${{ secrets.S3_ID }} + S3_SECRET: ${{ secrets.S3_SECRET }} diff --git a/Dockerfile b/Dockerfile index bbb74c4..f074822 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,4 @@ COPY requirements.txt . RUN pip install -qr requirements.txt COPY ./src . -CMD ["python3", "./sqs.py"] \ No newline at end of file +CMD ["python3", "./server.py"] \ No newline at end of file diff --git a/serverless.yml b/serverless.yml index f0a7473..dd3f5a1 100644 --- a/serverless.yml +++ b/serverless.yml @@ -11,8 +11,8 @@ provider: scwRegion: fr-par # Scaleway organization ID - scwProject: ${env:SCW_ACCESS_KEY_ID} - scwToken: ${env:SCW_SECRET_ACCESS_KEY} + scwProject: ${env:SCW_PROJECT} + scwToken: ${env:SCW_TOKEN} plugins: - serverless-scaleway-functions @@ -31,5 +31,14 @@ custom: minScale: 0 maxScale: 1 memoryLimit: 256 + cpuLimit: 140 port: 8080 - timeout: 100s + timeout: 10s + secret: + DATABASE_URL: ${env:DATABASE_URL} + DATABASE_NAME: ${env:DATABASE_NAME} + S3_ENDPOINT: ${env:S3_ENDPOINT} + S3_BUCKET: ${env:S3_BUCKET} + S3_ID: ${env:S3_ID} + S3_SECRET: ${env:S3_SECRET} + diff --git a/src/server.py b/src/server.py index 980f949..a121da1 100644 --- a/src/server.py +++ b/src/server.py @@ -21,6 +21,15 @@ def resource_not_found(e): return jsonify(error=str(e)), 404 +HTTP_METHODS = ["GET", "POST"] + +@app.route("/", methods=HTTP_METHODS) +def root(): + print(request.get_data(), flush=True) + response = make_response("Hello from container") + return response + + @app.route("/process/", methods=["POST"]) def root(file_id): result = process_file(content['file_id'])