Skip to content

Instantly share code, notes, and snippets.

@mbledkowski
Created April 29, 2023 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbledkowski/48425dc5d5ff384aa90d429e6e9d927b to your computer and use it in GitHub Desktop.
Save mbledkowski/48425dc5d5ff384aa90d429e6e9d927b to your computer and use it in GitHub Desktop.
Dockerfile
# Specify the base Docker image. You can read more about
# the available images at https://crawlee.dev/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node-playwright-chrome:16 AS builder
# Install pnpm
RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
# Use the shell form of RUN to source the .bashrc file before running pnpm
SHELL ["/bin/bash", "-c", "source /home/myuser/.bashrc"]
# Copy just package.json and pnpm-lock.yaml
# to speed up the build using Docker layer cache.
COPY ./scraper/package.json ./scraper/
COPY ./scraper/pnpm-lock.yaml ./scraper/
# Install all dependencies. Don't audit to speed up the installation.
RUN cd ./scraper && pnpm install --include=dev --audit=false
COPY ./interface/package.json ./interface/
COPY ./interface/pnpm-lock.yaml ./interface/
RUN cd ./interface && pnpm install --include=dev --audit=false
# Next, copy the source files using the user set
# in the base image.
COPY ./scraper ./scraper
# Install all dependencies and build the project.
# Don't audit to speed up the installation.
RUN cd ./scraper && pnpm run build
COPY ./interface ./interface
RUN cd ./interface && pnpm run build
# Create final image
FROM apify/actor-node-playwright-chrome:16
# Install pnpm
RUN wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
# Use the shell form of RUN to source the .bashrc file before running pnpm
SHELL ["/bin/bash", "-c", "source /home/myuser/.bashrc"]
# Copy only built JS files and from builder image
COPY --from=builder /home/myuser/scraper/dist ./app/scraper/dist
COPY --from=builder /home/myuser/interface/dist ./app/interface/dist
# Copy just package.json and pnpm-lock.yaml
# to speed up the build using Docker layer cache.
COPY ./scraper/package.json ./app/scraper/
COPY ./scraper/pnpm-lock.yaml ./app/scraper/
COPY ./interface/package.json ./app/interface/
COPY ./interface/pnpm-lock.yaml ./app/interface/
# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN cd ./app/scraper \
&& pnpm install --prod -s \
&& echo "Installed PNPM packages:" \
&& (pnpm list --prod || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "PNPM version:" \
&& pnpm --version
# Install python
RUN apt-get update && apt-get install -y python3 python3-pip
COPY stringNormalizers/verToSemVer/hardCodedApproach ./stringNormalizers/verToSemVer/hardCodedApproach
# Install python dependencies
RUN pip3 install -r ./stringNormalizers/verToSemVer/hardCodedApproach/requirements.txt
COPY stringNormalizers/nameToStdName ./stringNormalizers/nameToStdName
RUN pip3 install -r ./stringNormalizers/nameToStdName/requirements.txt
# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./app
# Change working directory to /usr/src/app/scraper
WORKDIR /home/myuser/app/scraper
VOLUME "/home/myuser/repository"
ENTRYPOINT ["bash"]
# CMD ["dist/main.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment