Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ docker := docker
endif

dockerNetwork := pathology-local
pythonPlatform := manylinux2014_$(shell uname -m)

# ==============================================================================

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -108,24 +111,24 @@ 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} ..."
@$(docker) buildx build --load --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t localhost/api-gateway-mock-image infrastructure/images/api-gateway-mock
@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
# TODO: Implement the artefact publishing step

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)
@app.route("/<path:path_params>", 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

Expand Down
5 changes: 4 additions & 1 deletion infrastructure/images/build-container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion infrastructure/images/mocks/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/build
/.aws
1 change: 0 additions & 1 deletion infrastructure/images/pathology-api/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/build
/.aws
Loading