Last active
December 26, 2023 06:53
-
-
Save loginov-rocks/cd6ccbc585b17a63419c806c0b706682 to your computer and use it in GitHub Desktop.
How to build and package Node.js Lambda code along with dependencies in Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BASE | |
FROM amazonlinux:2023.3.20231218.0 AS base | |
RUN yum -y install gzip tar zip | |
RUN touch ~/.bashrc | |
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash | |
RUN source ~/.bashrc && nvm install 18.9.0 | |
# BUILD | |
FROM base AS build | |
WORKDIR /app | |
# Install dependenciess. | |
COPY package*.json ./ | |
RUN source ~/.bashrc && npm install | |
# Build artifacts. | |
COPY . . | |
RUN source ~/.bashrc && npm run build | |
# APPLICATION | |
FROM base AS applicaion | |
WORKDIR /app | |
# Install runtime dependencies only. | |
COPY --from=build /app/package*.json ./ | |
RUN source ~/.bashrc && npm install --only=production | |
# Copy build artifacts only. | |
COPY --from=build /app/dist ./ | |
# Package artifacts with dependencies. | |
RUN zip -r function.zip . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment