|
| 1 | +# Specify the base Docker image. You can read more about |
| 2 | +# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images |
| 3 | +# You can also use any other image from Docker Hub. |
| 4 | +FROM apify/actor-node:22 AS builder |
| 5 | + |
| 6 | +# Check preinstalled packages |
| 7 | +RUN npm ls crawlee apify puppeteer playwright |
| 8 | + |
| 9 | +# Copy just package.json and package-lock.json |
| 10 | +# to speed up the build using Docker layer cache. |
| 11 | +COPY package*.json ./ |
| 12 | + |
| 13 | +# Install all dependencies. Don't audit to speed up the installation. |
| 14 | +RUN npm install --include=dev --audit=false |
| 15 | + |
| 16 | +# Next, copy the source files using the user set |
| 17 | +# in the base image. |
| 18 | +COPY . ./ |
| 19 | + |
| 20 | +# Install all dependencies and build the project. |
| 21 | +# Don't audit to speed up the installation. |
| 22 | +RUN npm run build |
| 23 | + |
| 24 | +# Create final image |
| 25 | +FROM apify/actor-node:22 |
| 26 | + |
| 27 | +# Check preinstalled packages |
| 28 | +RUN npm ls crawlee apify puppeteer playwright |
| 29 | + |
| 30 | +# Copy just package.json and package-lock.json |
| 31 | +# to speed up the build using Docker layer cache. |
| 32 | +COPY package*.json ./ |
| 33 | + |
| 34 | +# Install NPM packages, skip optional and development dependencies to |
| 35 | +# keep the image small. Avoid logging too much and print the dependency |
| 36 | +# tree for debugging |
| 37 | +RUN npm --quiet set progress=false \ |
| 38 | + && npm install --omit=dev --omit=optional \ |
| 39 | + && echo "Installed NPM packages:" \ |
| 40 | + && (npm list --omit=dev --all || true) \ |
| 41 | + && echo "Node.js version:" \ |
| 42 | + && node --version \ |
| 43 | + && echo "NPM version:" \ |
| 44 | + && npm --version \ |
| 45 | + && rm -r ~/.npm |
| 46 | + |
| 47 | +# Copy built JS files from builder image |
| 48 | +COPY --from=builder /usr/src/app/dist ./dist |
| 49 | + |
| 50 | +# Next, copy the remaining files and directories with the source code. |
| 51 | +# Since we do this after NPM install, quick build will be really fast |
| 52 | +# for most source file changes. |
| 53 | +COPY . ./ |
| 54 | + |
| 55 | +# Create and run as a non-root user. |
| 56 | +RUN adduser -h /home/apify -D apify && \ |
| 57 | + chown -R apify:apify ./ |
| 58 | +USER apify |
| 59 | + |
| 60 | +# Run the image. |
| 61 | +CMD npm run start:prod --silent |
0 commit comments