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

add docker workers to the images #1086

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
188 changes: 94 additions & 94 deletions packages/jsreport/docker/default/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
FROM node:18.16-alpine3.16
EXPOSE 5488
USER root
ARG TARGETPLATFORM

ENV GOSU_VERSION 1.12
RUN set -eux; \
\
apk add --no-cache --virtual .gosu-deps \
ca-certificates \
dpkg \
gnupg \
; \
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
\
# verify the signature
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
command -v gpgconf && gpgconf --kill all || :; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
# clean up fetch dependencies
apk del --no-network .gosu-deps; \
\
chmod +x /usr/local/bin/gosu; \
# verify that the binary works
gosu --version; \
gosu nobody true

RUN addgroup -S jsreport && adduser --shell /bin/bash -S -G jsreport jsreport

# this condition is useful when the alpine registry contain different latest versions
# per architecture, if the versions match then just use the same version number on both paths
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
export CHROMIUM_TO_INSTALL_VERSION="114.0.5735.133-r0"; \
elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
export CHROMIUM_TO_INSTALL_VERSION="114.0.5735.133-r0"; \
fi && \
echo "Installing Chromium $CHROMIUM_TO_INSTALL_VERSION version.." && \
apk update --no-cache && \
echo @edge http://dl-cdn.alpinelinux.org/alpine/v3.16/community >> /etc/apk/repositories && \
echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \
apk add --no-cache \
libstdc++@edge \
chromium@edge=$CHROMIUM_TO_INSTALL_VERSION\
nss \
freetype \
harfbuzz \
ttf-freefont@edge \
# just for now as we npm install from git
git \
# so user can docker exec -it test /bin/bash
bash

RUN rm -rf /var/cache/apk/* /tmp/*

RUN mkdir -p /app

# we need to create the volume and give it expected owner
# before the VOLUME step in order for the volume to be created with non-root user
RUN mkdir /jsreport
RUN chown jsreport:jsreport /jsreport
RUN chmod g+s /jsreport

VOLUME ["/jsreport"]

ENV NPM_CONFIG_PREFIX /home/jsreport/.npm-global
ENV PATH $PATH:/home/jsreport/.npm-global/bin

WORKDIR /app

ENV PUPPETEER_SKIP_DOWNLOAD true

RUN npm i -g @jsreport/jsreport-cli
RUN jsreport init

RUN npm cache clean -f && rm -rf /tmp/*

COPY ./packages/jsreport/docker/default/editConfig.js editConfig.js
COPY ./packages/jsreport/docker/default/run.sh run.sh
RUN node editConfig.js

RUN chown -R jsreport:jsreport /app

ENV chrome_launchOptions_executablePath /usr/lib/chromium/chrome
ENV chrome_launchOptions_args --no-sandbox,--disable-dev-shm-usage


CMD ["bash", "run.sh"]
FROM node:18.16-alpine3.16
EXPOSE 5488
USER root
ARG TARGETPLATFORM
ENV GOSU_VERSION 1.12
RUN set -eux; \
\
apk add --no-cache --virtual .gosu-deps \
ca-certificates \
dpkg \
gnupg \
; \
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
\
# verify the signature
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
command -v gpgconf && gpgconf --kill all || :; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
# clean up fetch dependencies
apk del --no-network .gosu-deps; \
\
chmod +x /usr/local/bin/gosu; \
# verify that the binary works
gosu --version; \
gosu nobody true
RUN addgroup -S jsreport && adduser --shell /bin/bash -S -G jsreport jsreport
# this condition is useful when the alpine registry contain different latest versions
# per architecture, if the versions match then just use the same version number on both paths
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
export CHROMIUM_TO_INSTALL_VERSION="115.0.5790.170-r0"; \
elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
export CHROMIUM_TO_INSTALL_VERSION="115.0.5790.170-r0"; \
fi && \
echo "Installing Chromium $CHROMIUM_TO_INSTALL_VERSION version.." && \
apk update --no-cache && \
echo @edge http://dl-cdn.alpinelinux.org/alpine/v3.16/community >> /etc/apk/repositories && \
echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \
apk add --no-cache \
libstdc++@edge \
chromium@edge=$CHROMIUM_TO_INSTALL_VERSION\
nss \
freetype \
harfbuzz \
ttf-freefont@edge \
# for docker workers extension
docker-cli
RUN rm -rf /var/cache/apk/* /tmp/*
RUN mkdir -p /app
# we need to create the volume and give it expected owner
# before the VOLUME step in order for the volume to be created with non-root user
RUN mkdir /jsreport
RUN chown jsreport:jsreport /jsreport
RUN chmod g+s /jsreport
VOLUME ["/jsreport"]
ENV NPM_CONFIG_PREFIX /home/jsreport/.npm-global
ENV PATH $PATH:/home/jsreport/.npm-global/bin
WORKDIR /app
ENV PUPPETEER_SKIP_DOWNLOAD true
RUN npm i -g @jsreport/jsreport-cli
RUN jsreport init
RUN npm i @jsreport/jsreport-docker-workers
RUN npm cache clean -f && rm -rf /tmp/*
COPY ./packages/jsreport/docker/default/editConfig.js editConfig.js
COPY ./packages/jsreport/docker/default/run.sh run.sh
RUN node editConfig.js
RUN chown -R jsreport:jsreport /app
ENV chrome_launchOptions_executablePath /usr/lib/chromium/chrome
ENV chrome_launchOptions_args --no-sandbox,--disable-dev-shm-usage
RUN apk add bash
CMD ["bash", "run.sh"]
3 changes: 2 additions & 1 deletion packages/jsreport/docker/default/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ if [ "$(ls -A /jsreport)" ]; then
fi

if [ "$(id -u)" = '0' ]; then
# If we are root, run the app as the lower-privilege `jsreport` user
chown jsreport /var/run/docker.sock &> /dev/null
# If we are root, run the app as the lower-privilege `jsreport` user
exec gosu jsreport node "server.js"
else
# If we're not root, we can't use `gosu` (and don't need to)
Expand Down
5 changes: 5 additions & 0 deletions packages/jsreport/docker/full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ RUN npm install --save --save-exact @jsreport/jsreport-ejs@3.0.1 \
@jsreport/jsreport-fs-store-aws-s3-persistence@3.1.0 \
@jsreport/jsreport-fs-store-azure-storage-persistence@3.0.0 \
@jsreport/jsreport-unoconv@3.0.1 \
@jsreport/jsreport-docker-workers \
cheerio-page-eval@1.0.0

COPY ./packages/jsreport/docker/full/install-or-build-oracledb-for-store.js install-or-build-oracledb-for-store.js
Expand All @@ -79,10 +80,14 @@ RUN node install-or-build-oracledb-for-store.js --target=$TARGETPLATFORM --store

RUN npm cache clean -f && rm -rf /tmp/*

RUN apt-get install -y --no-install-recommends docker.io

COPY ./packages/jsreport/docker/default/editConfig.js editConfig.js
COPY ./packages/jsreport/docker/full/run.sh run.sh
RUN node editConfig.js

RUN usermod -aG docker jsreport

RUN chown -R jsreport:jsreport /app

ENV chrome_launchOptions_args --no-sandbox,--disable-dev-shm-usage
Expand Down