Skip to content

Commit d82a923

Browse files
committed
Revert "Remove ParallelCluster API docker logic"
This reverts commit 0d5be94. The commit must be reverted because the Docker was useful to execute local testing.
1 parent 5269dbb commit d82a923

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ jobs:
190190
- name: Verify External SlurmDBD Template
191191
run:
192192
git diff --exit-code --quiet cloudformation/external-slurmdbd/external-slurmdbd.json cloudformation/external-slurmdbd/cdk.out/ExternalSlurmdbdStack.template.json
193+
api-docker-test:
194+
name: API Docker Tests
195+
runs-on: ubuntu-latest
196+
steps:
197+
- uses: actions/checkout@v2
198+
- uses: mikefarah/yq@v4.32.2
199+
- run: api/docker/awslambda/docker-build.sh
193200
shellcheck:
194201
name: Shellcheck
195202
runs-on: ubuntu-latest

api/docker/awslambda/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
### Stage 1: creates the wheel package from the pcluster source
2+
FROM public.ecr.aws/lambda/python:3.9 AS build_pcluster
3+
4+
RUN python -m pip install --upgrade setuptools wheel pip
5+
COPY src ./cli/src
6+
COPY setup.py MANIFEST.in README ./cli/
7+
RUN cd cli && python setup.py bdist_wheel
8+
9+
### Stage 2: prepares the AWS Lambda environment
10+
FROM public.ecr.aws/lambda/python:3.9 AS pcluster_lambda
11+
12+
# Copy the node runtime
13+
COPY --from=public.ecr.aws/lambda/nodejs:16 /var/lang/bin/node /var/lang/bin
14+
# Copy the aws-parallelcluster wheel package
15+
COPY --from=build_pcluster /var/task/cli/dist/* ./dist/
16+
# Install aws-parallelcluster
17+
RUN python -m pip install --upgrade pip
18+
RUN export PKG=(./dist/*.whl); python -m pip install "${PKG}[awslambda]" && rm -rf ./dist
19+
20+
# When the PROFILE is set to dev the Flask application is started in debug mode and with SwaggerUI support
21+
ARG PROFILE=prod
22+
ENV PROFILE=${PROFILE}
23+
# Install additional dependencies to start the SwaggerUI in dev mode
24+
RUN if [ "${PROFILE}" = "dev" ]; then python -m pip install connexion[swagger-ui]; fi
25+
26+
CMD ["pcluster.api.awslambda.entrypoint.lambda_handler"]

api/docker/awslambda/buildspec.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: 0.2
2+
3+
env:
4+
variables:
5+
# REQUIRED VARIABLES
6+
ECR_ENDPOINT: "" # ecr endpoint where the image is pushed (e.g. 12345667.dkr.ecr.eu-west-1.amazonaws.com)
7+
GIT_REF: "develop" # branch name or commit id to build
8+
IMAGE_REPO_NAME: "" # name of the ECR repo where the image is pushed
9+
IMAGE_TAG: "develop" # tag for the Docker images
10+
phases:
11+
pre_build:
12+
commands:
13+
- echo Validating environment
14+
- if [ -z "${ECR_ENDPOINT}" ] || [ -z "${GIT_REF}" ] || [ -z "${IMAGE_REPO_NAME}" ] || [ -z "${IMAGE_TAG}" ]; then echo "Invalid environment. Please set required variables"; exit 1; fi
15+
- echo Logging in to Amazon ECR...
16+
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECR_ENDPOINT
17+
- echo Cloning ParallelCluster GitHub repository...
18+
- git clone https://github.com/aws/aws-parallelcluster aws-parallelcluster && cd aws-parallelcluster && git checkout $GIT_REF
19+
build:
20+
commands:
21+
- echo Build started on `date`
22+
- echo Building the Docker image...
23+
- sh api/docker/awslambda/docker-build.sh
24+
- echo Build completed on `date`
25+
post_build:
26+
commands:
27+
- if [ $CODEBUILD_BUILD_SUCCEEDING = 0 ]; then echo Build failed; exit 1; fi
28+
- echo Pushing the Docker images...
29+
- docker tag pcluster-lambda:latest $ECR_ENDPOINT/$IMAGE_REPO_NAME:$IMAGE_TAG
30+
- docker push $ECR_ENDPOINT/$IMAGE_REPO_NAME:$IMAGE_TAG

api/docker/awslambda/docker-build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
5+
ROOT_DIR="${SCRIPT_DIR}/../../.."
6+
docker build "$@" -f "${ROOT_DIR}/api/docker/awslambda/Dockerfile" "${ROOT_DIR}/cli" -t pcluster-lambda
7+
8+
echo
9+
echo "Use the following to run a shell in the container"
10+
echo " docker run -it --entrypoint /bin/bash pcluster-lambda"
11+
echo
12+
echo "Use the following to run a local AWS Lambda endpoint hosting the API"
13+
echo " docker run -e POWERTOOLS_TRACE_DISABLED=1 -e AWS_REGION=eu-west-1 -p 9000:8080 pcluster-lambda"
14+
echo "Then you can use the following to send requests to the local endpoint"
15+
echo " curl -XPOST \"http://localhost:9000/2015-03-31/functions/function/invocations\" -d @${SCRIPT_DIR}/test-events/event.json"
16+
echo
17+
echo "Use the following to run a local Flask development server hosting the API"
18+
echo " docker run -p 8080:8080 --entrypoint python pcluster-lambda -m pcluster.api.flask_app"
19+
echo "Then you can navigate to the following url to test the API: http://0.0.0.0:8080/ui"
20+
echo "Note that to enable swagger-ui you have to build the docker with '--build-arg PROFILE=dev'"
21+
echo
22+
echo "Use the following command to push the built image to a public ECR repository"
23+
echo " aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/<alias>/<repository-name>"
24+
echo " docker tag pcluster-lambda:latest public.ecr.aws/<alias>/<repository-name>:latest"
25+
echo " docker push public.ecr.aws/<alias>/<repository-name>:latest"

0 commit comments

Comments
 (0)