diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8bc9b8c9..fcc08864 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,8 @@ "build": { "dockerfile": "../infrastructure/images/build-container/Dockerfile", "args": { - "INCLUDE_DEV_CERTS": "true" + "INCLUDE_DEV_CERTS": "true", + "AWS_DIR": "${localEnv:HOME}/.aws" } }, "customizations": { @@ -42,7 +43,8 @@ "postCreateCommand": "doas apk add --no-cache openjdk21-jre && scripts/devcontainer/configure-zsh.sh && bash -c 'source ~/.bashrc && make config && pyenv activate pathology && make dependencies'", "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind,consistency=cached", - "source=${localEnv:HOME}/.proxygen,target=/home/pathology-dev/.proxygen,type=bind,consistency=cached" + "source=${localEnv:HOME}/.proxygen,target=/home/pathology-dev/.proxygen,type=bind,consistency=cached", + "source=${localEnv:HOME}/.aws,target=/home/pathology-dev/.aws,type=bind,consistency=cached" ], "remoteUser": "pathology-dev", "containerUser": "pathology-dev", diff --git a/.vscode/settings.json b/.vscode/settings.json index 6069540f..11099a66 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -78,5 +78,5 @@ }, // Disabling automatic port forwarding as the devcontainer should already have access to any required ports. "remote.autoForwardPorts": false, - "python-envs.defaultEnvManager": "ms-python.python:system" + "python-envs.defaultEnvManager": "ms-python.python:pyenv" } diff --git a/Makefile b/Makefile index 990648ce..28e43abe 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ docker := docker endif dockerNetwork := pathology-local +pythonPlatform := manylinux2014_$(shell uname -m) # ============================================================================== @@ -58,7 +59,8 @@ build-pathology: @echo "Packaging dependencies..." @poetry build --format=wheel VERSION=$$(poetry version -s) - @pip install "dist/pathology_api-$$VERSION-py3-none-any.whl" --target "./target/pathology-api" --platform manylinux2014_x86_64 --only-binary=:all: + @echo Building pathology API: version=$$VERSION, platform=${pythonPlatform} + @pip install "dist/pathology_api-$$VERSION-py3-none-any.whl" --target "./target/pathology-api" --platform ${pythonPlatform} --only-binary=:all: # Copy lambda_handler file separately as it is not included within the package. @cp lambda_handler.py ./target/pathology-api/ @cd ./target/pathology-api @@ -84,7 +86,8 @@ build-mocks: @echo "Packaging dependencies..." @poetry build --format=wheel VERSION=$$(poetry version -s) - @pip install "dist/pathology_api_mocks-$$VERSION-py3-none-any.whl" --target "./target/mocks" --platform manylinux2014_x86_64 --only-binary=:all: + @echo Building mocks: version=$$VERSION, platform=${pythonPlatform} + @pip install "dist/pathology_api_mocks-$$VERSION-py3-none-any.whl" --target "./target/mocks" --platform ${pythonPlatform} --only-binary=:all: # Copy lambda_handler file separately as it is not included within the package. @cp lambda_handler.py ./target/mocks/ @cd ./target/mocks @@ -108,7 +111,7 @@ build-images: build # Build the project artefact @Pipeline @cp -r mocks/target/mocks infrastructure/images/mocks/resources/build @echo "Building Docker image using Docker. Utilising python version: ${PYTHON_VERSION} ..." - @$(docker) buildx build --load --platform=linux/amd64 --provenance=false --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t localhost/pathology-api-image infrastructure/images/pathology-api + @$(docker) buildx build --load --provenance=false --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t localhost/pathology-api-image infrastructure/images/pathology-api @echo "Docker image 'pathology-api-image' built successfully!" @echo "Building api gateway image using Docker. Utilising python version: ${PYTHON_VERSION} ..." @@ -116,7 +119,7 @@ build-images: build # Build the project artefact @Pipeline @echo "Docker image 'api-gateway-mock-image' built successfully!" @echo "Building mocks Docker image using Docker. Utilising python version: ${PYTHON_VERSION} ..." - @$(docker) buildx build --load --platform=linux/amd64 --provenance=false --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t localhost/mocks-image infrastructure/images/mocks + @$(docker) buildx build --load --provenance=false --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t localhost/mocks-image infrastructure/images/mocks @echo "Docker image 'mocks-image' built successfully!" publish: # Publish the project artefact @Pipeline @@ -124,8 +127,8 @@ publish: # Publish the project artefact @Pipeline deploy: clean-docker build-images # Deploy the project artefact to the target environment @Pipeline $(docker) network create $(dockerNetwork) || echo "Docker network '$(dockerNetwork)' already exists." - $(docker) run --platform linux/amd64 --name pathology-api -p 5001:8080 --network $(dockerNetwork) -d localhost/pathology-api-image - $(docker) run --platform linux/amd64 --name mocks -p 5003:8080 --network $(dockerNetwork) -d localhost/mocks-image + $(docker) run --name pathology-api -p 5001:8080 --env-file=".env.docker.api.local" --mount type=bind,src=$(AWS_DIR),dst=/root/.aws --network $(dockerNetwork) -d localhost/pathology-api-image + $(docker) run --name mocks -p 5003:8080 --env-file=".env.docker.mock.local" --mount type=bind,src=$(AWS_DIR),dst=/root/.aws --network $(dockerNetwork) -d localhost/mocks-image $(docker) run --name pathology-api-gateway -p 5002:5000 -e TARGET_CONTAINER='PATHOLOGY_API' -e TARGET_URL='http://pathology-api:8080' --network $(dockerNetwork) -d localhost/api-gateway-mock-image $(docker) run --name mocks-api-gateway -p 5005:5000 -e TARGET_CONTAINER='MOCKS' -e TARGET_URL='http://mocks:8080' --network $(dockerNetwork) -d localhost/api-gateway-mock-image diff --git a/infrastructure/images/api-gateway-mock/resources/server.py b/infrastructure/images/api-gateway-mock/resources/server.py index 230abf26..f6918366 100644 --- a/infrastructure/images/api-gateway-mock/resources/server.py +++ b/infrastructure/images/api-gateway-mock/resources/server.py @@ -42,7 +42,7 @@ ) @app.route("/", methods=["POST", "GET"]) def forward_request(path_params): - x_correlation_id = request.headers.get("X-Correlation-ID") + x_correlation_id = request.headers.get("X-Correlation-ID", "") forwarded_headers = {k.lower(): v for k, v in request.headers.items()} forwarded_headers["nhsd-correlation-id"] = x_correlation_id diff --git a/infrastructure/images/build-container/Dockerfile b/infrastructure/images/build-container/Dockerfile index afbb6ac8..2f61377f 100644 --- a/infrastructure/images/build-container/Dockerfile +++ b/infrastructure/images/build-container/Dockerfile @@ -7,11 +7,12 @@ ENV EDITORCONFIG_DOWNLOAD_URL="https://github.com/editorconfig-checker/editorcon ARG INCLUDE_DEV_CERTS -ARG DEV_CERT_FILENAME +ARG AWS_DIR # Add development certificates to node if provided. ENV NODE_EXTRA_CA_CERTS=${INCLUDE_DEV_CERTS:+/etc/ssl/certs/ca-certificates.crt} ENV DEV_CERTS_INCLUDED=$INCLUDE_DEV_CERTS +ENV AWS_DIR=$AWS_DIR ENV IN_BUILD_CONTAINER=true @@ -55,6 +56,7 @@ fi \ # Required for building lxml Python package libxml2-dev \ libxslt-dev \ + aws-cli \ # Configure doas to allow members of the wheel group to run commands as root. && echo "permit :wheel" >> /etc/doas.conf \ @@ -157,6 +159,7 @@ RUN bash -c "source ~/.bashrc && pyenv virtualenv ${PYTHON_VERSION} pathology" \ # Change default shell to bash for pathology-dev user. && chsh -s /bin/bash pathology-dev + # Update pathology-dev user's bash configuration. COPY /resources/.bashrc /home/pathology-dev/.bashrc diff --git a/infrastructure/images/mocks/resources/.gitignore b/infrastructure/images/mocks/resources/.gitignore index 1e60e223..796b96d1 100644 --- a/infrastructure/images/mocks/resources/.gitignore +++ b/infrastructure/images/mocks/resources/.gitignore @@ -1,2 +1 @@ /build -/.aws diff --git a/infrastructure/images/pathology-api/resources/.gitignore b/infrastructure/images/pathology-api/resources/.gitignore index 1e60e223..796b96d1 100644 --- a/infrastructure/images/pathology-api/resources/.gitignore +++ b/infrastructure/images/pathology-api/resources/.gitignore @@ -1,2 +1 @@ /build -/.aws