Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker build for raster processing pipeline #1049

Merged
merged 8 commits into from
Jan 22, 2025
Merged
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
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
Loading