diff --git a/.dockerignore b/.dockerignore index 48f026fa..28718547 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ model_data/local_data/* backend/tests/* +backend/node_modules/* recommendations/tests/* model_data/tests/* infrastructure/* diff --git a/README.md b/README.md index 63cd9ac8..df36cfe7 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ part of a larger application # Folders +### backend/ + +This folder contains the code for the fastapi backend service, which provides an interface to +much of the functionality in this repository, for the frontend + ### model_data/ This folder contains related to the reading and preparation of diff --git a/backend/README.md b/backend/README.md index 2817fd8f..70739265 100644 --- a/backend/README.md +++ b/backend/README.md @@ -59,6 +59,26 @@ FastAPI automatically generates interactive API documentation for your applicati server and visit /docs in your browser. Alternatively, you can go to /redoc to view the documentation in the ReDoc format. +## Building the backend docker image locally + +To build the backend docker image locally, run the following command from the root of the project directory: + +```commandline +docker build -t fastapi-lambda-image:latest -f backend/docker/lambda.Dockerfile . +``` + +To check the size of the resulting image, run the following command: + +```bash +docker images | grep fastapi-lambda-image +``` + +To run a shell inside the Docker container to inspect its contents, run: + +```commandline +docker run -it fastapi-lambda-image:latest /bin/bash +``` + ## Testing To run tests, run the following command from the root of the project directory: diff --git a/backend/docker/lambda.Dockerfile b/backend/docker/lambda.Dockerfile index 2c338015..9e16c21a 100644 --- a/backend/docker/lambda.Dockerfile +++ b/backend/docker/lambda.Dockerfile @@ -14,7 +14,8 @@ RUN apt-get update && apt-get install -y netcat-openbsd # Install python dependencies COPY ./backend/requirements/base.txt ./backend/requirements/base.txt RUN pip install --upgrade pip -RUN pip install -r backend/requirements/base.txt +# Install and clean up temp caches +RUN pip install -r backend/requirements/base.txt && rm -rf /root/.cache # Copy project files COPY ./backend/ ./backend diff --git a/serverless.yml b/serverless.yml index c6cecba5..28896ad3 100644 --- a/serverless.yml +++ b/serverless.yml @@ -2,7 +2,6 @@ service: fastapi-lambda provider: name: aws - runtime: python3.10 region: eu-west-2 architecture: x86_64 environment: @@ -32,46 +31,11 @@ provider: - arn:aws:s3:::${env:PLAN_TRIGGER_BUCKET}/* -package: - individually: true - patterns: - - 'backend/**' - - '!backend/tests/**' - - 'recommendations/**' - - '!recommendations/tests/**' - # Exclude all of model_data but then re-include the files we need - - '!model_data/**' - - 'model_data/BaseUtility.py' - - 'model_data/config.py' - - 'model_data/optimiser/**' - - 'model_data/__init__.py' - - 'model_data/EpcClean.py' - - 'model_data/utils.py' - - 'model_data/epc_attributes/**' - - 'datatypes/**' - - '!infrastructure/**' - - '!data_collection/**' - - '!node_modules/**' - - '!conservation_areas/**' - - '!open_uprn/**' - - '!land_registry/**' - - '!pytest.ini' - - '**/README.md' - - plugins: - serverless-python-requirements - serverless-domain-manager custom: - pythonRequirements: - dockerizePip: true - dockerFile: backend/docker/lambda.Dockerfile - useDocker: true - dockerSsh: true - fileName: backend/requirements/base.txt - dockerBuildCmdExtraArgs: - - '--progress=plain' customDomain: domainName: api.${self:provider.environment.DOMAIN_NAME} createRoute53Record: true @@ -79,7 +43,8 @@ custom: functions: app: - handler: backend.app.main.handler + image: + uri: ${env:ECR_URI}:latest events: - http: path: /{proxy+}