Skip to content

Commit

Permalink
Merge pull request #2960 from manosnoam/cypress_npm_ci
Browse files Browse the repository at this point in the history
Create NPM Cache directories for CI and run `npm ci` in Dockerfile build
  • Loading branch information
openshift-merge-bot[bot] authored Jun 28, 2024
2 parents e687eb8 + 58e92d1 commit 0c6256d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions scripts/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ FROM quay.io/fedora/fedora:40
ARG USER=cypress
ARG USER_HOME=/home/$USER
ARG NPM_CACHE=/opt/app-root/src/.npm-global
ARG CYPRESS_CACHE=/home/jenkins/.cypress-cache
ARG CYPRESS_CACHE=$USER_HOME/.cypress-cache
ARG CHROME=https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
ARG OCP_CLI=https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz
ARG NVM_INSTALLER=https://raw.githubusercontent.com/creationix/nvm/v0.39.7/install.sh
ARG NODE_VERSION=v20.10.0
ARG NODE_VERSION=v20.15.0

USER root

Expand All @@ -16,9 +16,16 @@ RUN mkdir -p "$USER_HOME"
RUN useradd -m -g root "$USER" -d "$USER_HOME" --uid 1000
RUN chgrp -R 0 "$USER_HOME"
RUN chmod -R g=u "$USER_HOME"
RUN mkdir -p $NPM_CACHE

# Create global NPM cache directory
RUN mkdir -p "$NPM_CACHE"
RUN chgrp -R 0 "$NPM_CACHE"
RUN chmod -R 777 $NPM_CACHE
RUN chmod -R 777 "$NPM_CACHE"

# Create local Cypress cache directory
RUN mkdir -p "$CYPRESS_CACHE"
RUN chgrp -R 0 "$CYPRESS_CACHE"
RUN chmod -R 777 "$CYPRESS_CACHE"

# Install tools including Xvfb and Chrome
RUN dnf update -y
Expand All @@ -41,7 +48,7 @@ RUN rm -rf /var/cache/yum
# Set capability to adjust OOM score for Node
RUN echo CAP_SYS_NICE >> /etc/security/limits.conf

# Copy NodeJS package.json from "frontend" directory
# Copy NodeJS packages lists (json files) from "frontend" directory
WORKDIR $USER_HOME
COPY ./frontend/package*.json ./
RUN chown $USER:0 ./*
Expand All @@ -55,16 +62,16 @@ ENV NODE_PATH "$NVM_DIR/versions/node/$NODE_VERSION/lib/node_modules"
ENV PATH "$NVM_DIR/versions/node/$NODE_VERSION/bin:/bin:$HOME/.local/bin:/root/.local/bin:$PATH"
RUN mkdir -p $NVM_DIR

# Install Node Version Manager, Node Package Manager, and the "frontend" packages
# Install Node Version Manager, NodeJS and the packages for CI (package-lock.json)
RUN curl -o- $NVM_INSTALLER | bash
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm use --delete-prefix $NODE_VERSION && \
npm config set prefix '$NPM_CACHE' && \
echo 'export PATH=$PATH' >> '$USER_HOME/.profile' && \
source $USER_HOME/.profile && \
npm install -g npm@latest && \
npm cache -g clean --force"
npm cache -g clean --force && \
npm ci --cache=$NPM_CACHE"

# Export NPM and Cypress Cache directories (to be accesible by rootless user)
ENV NPM_CONFIG_CACHE $NPM_CACHE
Expand Down

0 comments on commit 0c6256d

Please sign in to comment.