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 all 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
56 changes: 46 additions & 10 deletions docker/development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,63 @@ RUN GOOS=js GOARCH=wasm go build -o pdfcomprezzor.wasm
RUN cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .

# Now build the actual mampf application
FROM ruby:3.1.4
# https://hub.docker.com/_/ruby/
FROM ruby:3.1.4-bullseye
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 && \
apt-get update && \
apt-get install --no-install-recommends -y ffmpeg ghostscript imagemagick \
libarchive-tools nodejs pdftk postgresql-client-13 sqlite3 wget \
wait-for-it yarn shared-mime-info && \
rm -rf /var/lib/apt/lists/* && apt-get clean
# 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

# Install Yarn (see https://yarnpkg.com/getting-started/install)
# https://github.com/nodejs/corepack#corepack-prepare--nameversion
ENV YARN_VERSION=1.22.19
RUN corepack enable
RUN corepack prepare "yarn@${YARN_VERSION}" --activate
RUN which yarn; yarn --version
# even though this is not specified in the corepack documentation, we need to
# run "set version", otherwise the app user will have an old version of
# yarn avaialble instead of our specified version
RUN yarn set version "${YARN_VERSION}"
christian-heusel marked this conversation as resolved.
Show resolved Hide resolved

# Install other dependencies
# Note that postgresql-client-13 is available through debian bullseye
# that the ruby image is based on
RUN apt update && \
apt-get install -y --no-install-recommends \
ffmpeg imagemagick pdftk ghostscript shared-mime-info \
libarchive-tools postgresql-client-13 sqlite3 wget wait-for-it

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

WORKDIR /usr/src/app
ENTRYPOINT ["./entrypoint.sh"]

COPY ./Gemfile ./Gemfile.lock ./yarn.lock ./package.json /usr/src/app/
RUN bundle install
RUN 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 /
61 changes: 51 additions & 10 deletions docker/production/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,70 @@ EXPOSE 9394

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

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
RUN apt-get update
# install all the dependencies
RUN apt-get install -y --no-install-recommends \
# 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; node --version
RUN npm --version

# Install Yarn (see https://yarnpkg.com/getting-started/install)
# https://github.com/nodejs/corepack#corepack-prepare--nameversion
ENV YARN_VERSION=1.22.19
RUN corepack enable
RUN corepack prepare "yarn@${YARN_VERSION}" --activate
RUN which yarn; yarn --version
# even though this is not specified in the corepack documentation, we need to
# run "set version", otherwise the app user will have an old version of
# yarn avaialble instead of our specified version
RUN yarn set version "${YARN_VERSION}"

# Make Node.js tooling available for other users
# 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 tooling to /usr/local/
# so that it can be used by the app user later
RUN n=$(which node); n=${n%/bin/node}; chmod 755 $n/bin/node; chmod 755 $n/bin/yarn; cp -r $n/{bin,lib,share} /usr/local
Splines marked this conversation as resolved.
Show resolved Hide resolved

# Install other dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ffmpeg imagemagick pdftk ghostscript rsync shared-mime-info
RUN apt-get install -y nodejs yarn

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

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


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

# Log Node.js tooling versions that the `app` user uses
RUN which node; node --version; which yarn; yarn --version

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
RUN yarn install --production=true

RUN bundle install && \
yarn install --production=false
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
59 changes: 47 additions & 12 deletions docker/run_cypress_tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,61 @@ RUN GOOS=js GOARCH=wasm go build -o pdfcomprezzor.wasm
RUN cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .

# Now build the actual mampf application
FROM ruby:3.1.4
# https://hub.docker.com/_/ruby/
FROM ruby:3.1.4-bullseye
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 && \
apt-get update && \
apt-get install --no-install-recommends -y ffmpeg ghostscript imagemagick \
libarchive-tools nodejs pdftk postgresql-client-13 sqlite3 wget \
wait-for-it yarn shared-mime-info && \
rm -rf /var/lib/apt/lists/* && apt-get clean
# 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

# Install Yarn (see https://yarnpkg.com/getting-started/install)
# https://github.com/nodejs/corepack#corepack-prepare--nameversion
ENV YARN_VERSION=1.22.19
RUN corepack enable
RUN corepack prepare "yarn@${YARN_VERSION}" --activate
RUN which yarn; yarn --version
# even though this is not specified in the corepack documentation, we need to
# run "set version", otherwise the app user will have an old version of
# yarn avaialble instead of our specified version
RUN yarn set version "${YARN_VERSION}"

# Install other dependencies
# Note that postgresql-client-13 is available through debian bullseye
# that the ruby image is based on
RUN apt update && \
apt-get install -y --no-install-recommends \
ffmpeg imagemagick pdftk ghostscript shared-mime-info \
libarchive-tools postgresql-client-13 sqlite3 wget wait-for-it

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

WORKDIR /usr/src/app

COPY ./Gemfile ./Gemfile.lock ./yarn.lock ./package.json /usr/src/app/
RUN bundle install && \
yarn install --production=false
RUN bundle install
RUN 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
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
"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": "^4.46.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.1"
},
"scripts": {
"lint": "eslint ."
}
}
}
Loading