Skip to content

Commit

Permalink
Update docker build for raster processing pipeline (#1049)
Browse files Browse the repository at this point in the history
Update raster processing image to use a new conda-managed environment.
Refs #1029
  • Loading branch information
groutr authored Jan 22, 2025
1 parent f4cfe95 commit 416aae8
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
FROM public.ecr.aws/lambda/python:3.9
FROM mambaorg/micromamba AS micromamba

# Create conda environment for hydrovis
RUN --mount=type=bind,source=conda-linux-64.lock,target=/tmp/conda.lock \
micromamba install -y --file /tmp/conda.lock && \
micromamba clean -afy

# Clean out unnecessary files to reduce image size
RUN find /opt/conda -regex '^.*\(__pycache__\|\.py[co]\)$' -delete && \
find /opt/conda -follow -type f -name '*.a' -delete
RUN rm -rf /opt/conda/man /opt/conda/share/man /opt/conda/share/doc && \
rm -rf /opt/conda/include && \
rm -rf /opt/conda/share/bash-completion && \
rm -rf /opt/conda/share/info && \
rm -rf /opt/conda/share/examples && \
rm -rf /opt/conda/conda-meta

# Copy function code
COPY lambda_function.py ${LAMBDA_TASK_ROOT}
ADD products "${LAMBDA_TASK_ROOT}/products"
COPY serverless.yml ${LAMBDA_TASK_ROOT}
COPY viz_classes.py ${LAMBDA_TASK_ROOT}
COPY viz_lambda_shared_funcs.py ${LAMBDA_TASK_ROOT}

# Install the function's dependencies using file requirements.txt
# from your project folder.
FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal AS alinux

COPY requirements.txt .
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
ENV MAMBA_ROOT_PREFIX="/opt/conda"
ENV MAMBA_EXE="/bin/micromamba"
# Prevent Python from writing bytecode files
ENV PYTHONDONTWRITEBYTECODE=1
# Prevent python from buffering stdout
ENV PYTHONUNBUFFERED=1
COPY --from=micromamba --chown=root "$MAMBA_EXE" "$MAMBA_EXE"
COPY --from=micromamba --chown=root /opt/conda /opt/conda
COPY --from=micromamba --chown=root /usr/local/bin/_*.sh /usr/local/bin/

WORKDIR /home/code

# Copy function code
COPY products/ ./products/
COPY lambda_function.py \
viz_classes.py \
viz_lambda_shared_funcs.py \
./

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "lambda_function.lambda_handler" ]
SHELL ["/usr/local/bin/_dockerfile_shell.sh"]

# Removes severity vulnerabilities
RUN yum -y update
ENTRYPOINT [ "/usr/local/bin/_entrypoint.sh" ]
CMD [ \
"python", "-m", "awslambdaric", "lambda_function.lambda_handler" \
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ phases:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker buildx build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
Expand Down
Loading

0 comments on commit 416aae8

Please sign in to comment.