From 1d50da987fc50604c38297494940133f06b5bc88 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 22 May 2025 05:07:00 +0000 Subject: [PATCH] Refactor: Update Dockerfile to Node.js Alpine base I've switched the base image from node:22 to node:22-alpine to reduce image size. Key changes include: - Updated FROM instruction to node:22-alpine. - Replaced apt-get with apk for package management. - Updated package names to their Alpine equivalents (e.g., libasound2 to alsa-lib, libgtk-4-1 to gtk+3.0). - Modified Chrome and Chromedriver installation to use Alpine's `chromium` and `chromium-chromedriver` packages instead of manual downloads. - Ensured correct user, working directory permissions, and order of operations, particularly for directory creation and ownership before switching to the 'node' user. Note: The Docker image build process encountered an environmental 'no space left on device' error. Therefore, I could not complete full build verification and subsequent functional testing of the image. The Dockerfile changes are based on best practices for Alpine conversion. --- Dockerfile | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index cd00ca4..3bf3fd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,25 @@ # Use an official Node.js runtime as a parent image -FROM node:22 +FROM node:22-alpine -RUN apt-get update -qq -y && \ - apt-get install -y \ - libasound2 \ - libatk-bridge2.0-0 \ - libgtk-4-1 \ - libnss3 \ +RUN apk add --no-cache \ + alsa-lib \ + at-spi2-atk \ + gtk+3.0 \ + nss \ xdg-utils \ - wget && \ - wget -q -O chrome-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-linux64.zip && \ - unzip chrome-linux64.zip && \ - rm chrome-linux64.zip && \ - mv chrome-linux64 /opt/chrome/ && \ - ln -s /opt/chrome/chrome /usr/local/bin/ && \ - wget -q -O chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chromedriver-linux64.zip && \ - unzip -j chromedriver-linux64.zip chromedriver-linux64/chromedriver && \ - rm chromedriver-linux64.zip && \ - mv chromedriver /usr/local/bin/ - -# Don't run as root -USER node + wget \ + unzip \ + chromium \ + chromium-chromedriver # Set the working directory in the container WORKDIR /usr/src/app -# Create the cache directory -RUN mkdir -p ./cache && chown node:node ./cache +# Create the cache directory and set ownership (as root) +RUN mkdir -p ./cache && chown -R node:node ./cache + +# Don't run as root +USER node # Define environment variables ENV NODE_ENV=production @@ -67,9 +60,11 @@ ENV BITCOIN_PAYEE_NAME="Bitcoin Price Change" VOLUME ./cache # Copy the current directory contents into the container at /usr/src/app +# This should happen after WORKDIR is set and USER is node COPY --chown=node:node . . # Install any needed packages specified in package.json +# This should run as the node user RUN npm install && npm update # Run the app when the container launches