From ff1d236b72169c51c4dc22f7da9e6f3d267a4f63 Mon Sep 17 00:00:00 2001 From: Giacomo Licari Date: Tue, 28 Nov 2023 14:30:08 +0100 Subject: [PATCH] API: add gunicorn --- .github/workflows/publish-api.yaml | 2 +- .github/workflows/publish-ui.yaml | 2 +- api/Dockerfile | 5 +++-- api/api/api.py | 3 ++- api/requirements.txt | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-api.yaml b/.github/workflows/publish-api.yaml index 72dd0ac..93a7fe1 100644 --- a/.github/workflows/publish-api.yaml +++ b/.github/workflows/publish-api.yaml @@ -43,7 +43,7 @@ jobs: # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. - name: Build and push Docker image - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 with: context: api push: true diff --git a/.github/workflows/publish-ui.yaml b/.github/workflows/publish-ui.yaml index 8304121..fc2ffe0 100644 --- a/.github/workflows/publish-ui.yaml +++ b/.github/workflows/publish-ui.yaml @@ -43,7 +43,7 @@ jobs: # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. - name: Build and push Docker image - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 with: context: app push: true diff --git a/api/Dockerfile b/api/Dockerfile index dedcc66..a1866cb 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -7,5 +7,6 @@ RUN pip3 install -r requirements.txt COPY . . -EXPOSE 5000 -CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port", "5000"] \ No newline at end of file +EXPOSE 8000 + +CMD ["gunicorn", "-b", "0.0.0.0", 'api:create_app()'] \ No newline at end of file diff --git a/api/api/api.py b/api/api/api.py index b4a41bb..81c7f1c 100644 --- a/api/api/api.py +++ b/api/api/api.py @@ -31,7 +31,8 @@ def create_app(): app = Flask(__name__) app.config.from_object('api.settings') apiv1 = Blueprint("version1", "version1") - cors = CORS(app, resources={r"/api/v1/*": {"origins": app.config['CORS_ALLOWED_ORIGINS']}}) + # Apply CORS + CORS(app, resources={r"/api/v1/*": {"origins": app.config['CORS_ALLOWED_ORIGINS']}}) w3 = Web3(Web3.HTTPProvider(app.config['FAUCET_RPC_URL'])) w3.middleware_onion.add(construct_sign_and_send_raw_middleware(app.config['FAUCET_PRIVATE_KEY'])) diff --git a/api/requirements.txt b/api/requirements.txt index a4bf7fd..727070a 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -4,4 +4,5 @@ cachetools==5.3.2 python-dotenv==1.0.0 web3==6.11.3 pytest==7.4.3 -pytest-mock==3.12.0 \ No newline at end of file +pytest-mock==3.12.0 +gunicorn==21.2.0 \ No newline at end of file