Skip to content

Commit

Permalink
feat: Use SQS trigger from scaleway
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Feb 1, 2024
1 parent 44779f9 commit c596d20
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
DATABASE_URL=mongodb+srv://username:[email protected]/?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=
Expand All @@ -15,4 +10,9 @@ SQS_REGION="fr-par"
SQS_ENDPOINT="https://sqs.mnq.fr-par.scaleway.com"
SQS_ID=
SQS_SECRET=
SQS_QUEUE_URL=
SQS_QUEUE_URL=

## Only for deployement on Scaleway
SCW_PROJECT=
SCW_TOKEN=
SCW_REGISTRY="registry.fr-par.scw.cloud"
12 changes: 9 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ COPY requirements.txt .
RUN pip install -qr requirements.txt
COPY ./src .

CMD ["python3", "./sqs.py"]
CMD ["python3", "./server.py"]
15 changes: 12 additions & 3 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}

9 changes: 9 additions & 0 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<file_id>", methods=["POST"])
def root(file_id):
result = process_file(content['file_id'])
Expand Down

0 comments on commit c596d20

Please sign in to comment.