Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Node.js to v16 and update frontend dependencies #519

Merged
merged 29 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9073cdf
Use npm audit to update npm packages
Splines Jun 19, 2023
31b0550
Use Node.js version 16 in Docker development
Splines Jun 20, 2023
4ac0062
Use node after installation
Splines Jun 20, 2023
9557ea2
Split installation of Node.js to multiple RUN commands
Splines Jun 21, 2023
f60c4fb
Uniy sass packages and update yarn lock
Splines Jun 21, 2023
4b0df7a
Reflect changes in production and test Dockerfiles
Splines Jun 21, 2023
8777bcf
Add comments to Dockerfile and tighten run commands
Splines Jun 21, 2023
361e19e
Add sass-loader back as dependency
Splines Jun 21, 2023
ab67db4
Switch back to old version of sass-loader
Splines Jun 21, 2023
bd3146f
Use "-no-install-recommends" for yarn install in prod
Splines Jun 21, 2023
9265739
Use consistent ${} syntax in Dockerfile & fix Node path
Splines Jun 21, 2023
12c20b8
Copy Node.js over to /usr/local
Splines Jun 21, 2023
e1cbade
Apply quote arguments suggestion (in code review)
Splines Jun 23, 2023
5bad229
Quote arguments in other Dockerfiles as well
Splines Jun 23, 2023
96f8379
Replace deprecated apt-key and improve Dockerfiles
Splines Jun 23, 2023
b681e56
Upgrade to Yarn 2 and add packages for non-error webpack build
Splines Jun 23, 2023
8cbe0ce
Copy Yarn to usr folder alongside other Node.js tooling
Splines Jun 24, 2023
a15a28e
Activate Yarn for app user
Splines Jun 24, 2023
82a2175
Only copy node over to usr folder
Splines Jun 24, 2023
a5f057f
Go back to Yarn1 and explicitly set Yarn version
Splines Jun 25, 2023
10dfa35
Remove ".yarn" from .gitignore
Splines Jun 25, 2023
1a7018b
Remove unnecessary dependencies from package.json
Splines Jun 25, 2023
b9172d3
Add back missing "--production=false" to "yarn install"
Splines Jun 26, 2023
63de309
Use "ruby:3.1.4-bullseye" to have PostgreSQL available
Splines Jun 26, 2023
67676e4
Add missing `apt update` in dev and test Dockerfiles
Splines Jun 26, 2023
9868679
Group `update` and `install` in one RUN statement
Splines Jun 26, 2023
01db6bb
Remove superfluous newline
Splines Jun 26, 2023
4fae533
Make Node.js version logging one RUN statement
Splines Jun 26, 2023
5ad36ce
Explicitly set `--production=true` during `yarn install`
Splines Jun 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions docker/development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,37 @@ ENV RAILS_ENV=production
EXPOSE 3000
EXPOSE 9394

# https://github.com/nodesource/distributions#installation-instructions
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
# use "--login" option, so that .bashrc is sourced in new shells
SHELL ["/bin/bash", "--login", "-c"]

# Install Node.js
# https://github.com/nodesource/distributions/issues/1583#issuecomment-1597489401
# https://stackoverflow.com/a/57546198/
# Unfortunately, we have to explicitly specify the node version here
# and cannot use 16.x as we need to put the node binary into the PATH
# and therefore require the exact version to find the folder
ENV NODE_VERSION=16.20.1
RUN curl -o- https://github.com/raw/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN source ${NVM_DIR}/nvm.sh && nvm install ${NODE_VERSION} && \
nvm use ${NODE_VERSION} && nvm alias default ${NODE_VERSION}

ENV NODE_PATH="${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/"
ENV PATH="${NODE_PATH}:${PATH}"

RUN nvm current
RUN node --version
RUN npm --version

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -y lsb-release && \
# https://wiki.postgresql.org/wiki/Apt
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
Splines marked this conversation as resolved.
Show resolved Hide resolved
curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
Splines marked this conversation as resolved.
Show resolved Hide resolved
apt-get update && \
apt-get install --no-install-recommends -y ffmpeg ghostscript imagemagick \
libarchive-tools nodejs pdftk postgresql-client-13 sqlite3 wget \
libarchive-tools pdftk postgresql-client-13 sqlite3 wget \
wait-for-it yarn shared-mime-info && \
rm -rf /var/lib/apt/lists/* && apt-get clean

Expand Down
41 changes: 35 additions & 6 deletions docker/production/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,58 @@ EXPOSE 9394

ENTRYPOINT ["/usr/src/app/docker/entrypoint-worker.sh"]

# use "--login" option, so that .bashrc is sourced in new shells
SHELL ["/bin/bash", "--login", "-c"]

# Install Node.js
# https://github.com/nodesource/distributions/issues/1583#issuecomment-1597489401
# https://stackoverflow.com/a/57546198/
# Unfortunately, we have to explicitly specify the node version here
# and cannot use 16.x as we need to put the node binary into the PATH
# and therefore require the exact version to find the folder
ENV NODE_VERSION=16.20.1
RUN curl -o- https://github.com/raw/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN source ${NVM_DIR}/nvm.sh && nvm install ${NODE_VERSION} && \
nvm use ${NODE_VERSION} && nvm alias default ${NODE_VERSION}

ENV NODE_PATH="${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/"
ENV PATH="${NODE_PATH}:${PATH}"

RUN nvm current
RUN node --version
RUN npm --version

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash
# update the sources with the repos set up
# update the sources with the repos set up
RUN apt-get update
# install all the dependencies
# install all the dependencies
RUN apt-get install -y --no-install-recommends \
ffmpeg imagemagick pdftk ghostscript rsync shared-mime-info
RUN apt-get install -y nodejs yarn
RUN apt-get install --no-install-recommends -y yarn

RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml

RUN groupadd -g 501 app && useradd -g 501 -u 501 -m -d /usr/src/app app && \
mkdir /private /caches && chown app:app /private /caches

# see https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps
# this command copies the currently active nvm node version to /usr/local/ directory
# so that it can be used by the app user later
RUN n=$(which node); n=${n%/bin/node}; chmod 755 $n/bin/nodejs; chmod 755 $n/bin/node; chmod 755 $n/bin/nvm; chmod 755 $n/bin/npm; cp -r $n/{bin,lib,share} /usr/local


# ============= Now switch to the app user
WORKDIR /usr/src/app
USER app

COPY --from=build-pdfcomprezzor /go/src/pdfcomprezzor.wasm /go/src/wasm_exec.js /usr/src/app/public/pdfcomprezzor/

COPY --chown=app:app ./Gemfile ./Gemfile.lock ./yarn.lock ./package.json /usr/src/app/

RUN bundle install && \
yarn install --production=false
yarn install --production=false
Splines marked this conversation as resolved.
Show resolved Hide resolved

COPY --chown=app:app . /usr/src/app
RUN cp -r $(bundle info --path sidekiq)/web/assets /usr/src/app/public/sidekiq && \
SECRET_KEY_BASE="$(bundle exec rails secret)" DB_ADAPTER=nulldb bundle exec rails assets:precompile
36 changes: 30 additions & 6 deletions docker/run_cypress_tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,37 @@ FROM ruby:3.1.4
ENV RAILS_ENV=production
EXPOSE 3000

# https://github.com/nodesource/distributions#installation-instructions
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
# use "--login" option, so that .bashrc is sourced in new shells
SHELL ["/bin/bash", "--login", "-c"]

# Install Node.js
# https://github.com/nodesource/distributions/issues/1583#issuecomment-1597489401
# https://stackoverflow.com/a/57546198/
# Unfortunately, we have to explicitly specify the node version here
# and cannot use 16.x as we need to put the node binary into the PATH
# and therefore require the exact version to find the folder
ENV NODE_VERSION=16.20.1
RUN curl -o- https://github.com/raw/nvm-sh/nvm/v0.39.0/install.sh | bash
ENV NVM_DIR=/root/.nvm
RUN source ${NVM_DIR}/nvm.sh && nvm install ${NODE_VERSION} && \
nvm use ${NODE_VERSION} && nvm alias default ${NODE_VERSION}
Splines marked this conversation as resolved.
Show resolved Hide resolved

ENV NODE_PATH="${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/"
ENV PATH="${NODE_PATH}:${PATH}"

RUN nvm current
RUN node --version
RUN npm --version

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -y lsb-release && \
# https://wiki.postgresql.org/wiki/Apt
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install --no-install-recommends -y ffmpeg ghostscript imagemagick \
libarchive-tools nodejs pdftk postgresql-client-13 sqlite3 wget \
libarchive-tools pdftk postgresql-client-13 sqlite3 wget \
wait-for-it yarn shared-mime-info && \
rm -rf /var/lib/apt/lists/* && apt-get clean

Expand All @@ -26,7 +50,7 @@ WORKDIR /usr/src/app

COPY ./Gemfile ./Gemfile.lock ./yarn.lock ./package.json /usr/src/app/
RUN bundle install && \
yarn install --production=false
yarn install --production=false

COPY --from=build-pdfcomprezzor /go/src/pdfcomprezzor.wasm /go/src/wasm_exec.js /usr/src/app/public/pdfcomprezzor/
COPY --from=build-pdfcomprezzor /go/src/pdfcomprezzor.wasm /go/src/wasm_exec.js /
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
"name": "mampf",
"private": true,
"dependencies": {
"@rails/webpacker": "5.4.3",
"@webpack-cli/serve": "^1.6.1",
"@rails/webpacker": "5.4.4",
"@webpack-cli/serve": "^1.7.0",
"coffee-loader": "^1.0.1",
"coffeescript": "2.6.1",
"core-js": "^3.21.1",
"core-js": "^3.31.0",
"css-loader": "^5.2.7",
"friendly-challenge": "^0.9.1",
"friendly-challenge": "^0.9.12",
"imports-loader": "^1.2.0",
"jquery-datetimepicker": "^2.5.21",
"moment": "^2.29.1",
"node-sass": "^7.0.1",
"regenerator-runtime": "^0.13.7",
"moment": "^2.29.4",
"regenerator-runtime": "^0.13.11",
"sass": "^1.63.4",
"sass-loader": "^10.1.1",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.1"
},
"scripts": {
"lint": "eslint ."
Expand Down
Loading