Commit 85f8742b authored by Fred Chasen's avatar Fred Chasen

Add Dockerfile

parent 9cd044bb
.git
*Dockerfile*
*docker-compose*
node_modules
dist
lib
before_script:
- docker info
build_image:
script:
- docker build -t pagedmedia/pagedjs .
- docker run --security-opt 'seccomp=docker-chrome.json' pagedmedia/pagedjs npm test
FROM node:10-stretch
# Application parameters and variables
ENV NODE_ENV=development
ENV PORT=9090
ENV DIRECTORY /home/node/pagedjs
# Configuration for Chrome
ENV CONNECTION_TIMEOUT=60000
ENV CHROME_PATH=/usr/bin/google-chrome
# Configuration for GS4JS
ENV GS4JS_HOME=/usr/lib/x86_64-linux-gnu
# Install ghostscript
RUN apt-get update && \
apt-get install -y build-essential make gcc g++ && \
apt-get -y install ghostscript && apt-get clean && \
apt-get install -y libgs-dev && \
rm -rf /var/lib/apt/lists/*
# See https://crbug.com/795759
RUN apt-get update && apt-get install -yq libgconf-2-4
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update && apt-get install -y wget --no-install-recommends \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /src/*.deb
# helps prevent zombie chrome processes.
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
RUN npm install npm@latest -g
RUN npm install -g node-gyp
RUN mkdir -p $DIRECTORY
# Add user so we don't need --no-sandbox.
# RUN groupadd -r node && useradd -r -g node -G audio,video node \
RUN adduser node audio \
&& adduser node video \
&& mkdir -p /home/node/Downloads \
&& chown -R node:node /home/node \
&& chown -R node:node /usr/lib \
&& chown -R node:node $DIRECTORY
# Run everything after as non-privileged user.
USER node
WORKDIR $DIRECTORY
COPY --chown=node:node . $DIRECTORY
RUN npm install
RUN npm install ghostscript4js
EXPOSE $PORT
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "start"]
......@@ -143,3 +143,25 @@ To update the stored pdf images you can run
```bash
npm run specs -- --updateSnapshot
```
### Docker
A `pagedmedia/pagedjs` docker image contains all the dependencies needed to run the `pagedjs` development server, as well as the pdf comparison tests.
To build the image run
```bash
docker build -t pagedmedia/pagedjs .
```
By default the container will run the development server with `npm start`
```bash
docker run -it -p 9090:9090 pagedmedia/pagedjs
```
The tests and specs can be run within the container by passing a `seccomp` file for Chrome and running `npm test`
```bash
docker run -it --security-opt 'seccomp=seccomp.json' pagedmedia/pagedjs npm test
```
{
"defaultAction": "SCMP_ACT_ERRNO",
"syscalls": [
{
"name": "accept",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "accept4",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "access",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "alarm",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "arch_prctl",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "bind",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "brk",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "capget",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "capset",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "chdir",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "chmod",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "chown",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "chown32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "chroot",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "clock_getres",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "clock_gettime",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "clock_nanosleep",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "clone",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "close",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "connect",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "creat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "dup",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "dup2",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "dup3",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "epoll_create",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "epoll_create1",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "epoll_ctl",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "epoll_ctl_old",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "epoll_pwait",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "epoll_wait",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "epoll_wait_old",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "eventfd",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "eventfd2",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "execve",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "execveat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "exit",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "exit_group",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "faccessat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fadvise64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fadvise64_64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fallocate",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fanotify_init",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fanotify_mark",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fchdir",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fchmod",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fchmodat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fchown",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fchown32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fchownat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fcntl",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fcntl64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fdatasync",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fgetxattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "flistxattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "flock",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fork",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fremovexattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fsetxattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fstat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fstat64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fstatat64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fstatfs",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fstatfs64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "fsync",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "ftruncate",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "ftruncate64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "futex",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "futimesat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getcpu",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getcwd",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getdents",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getdents64",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getegid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getegid32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "geteuid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "geteuid32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getgid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getgid32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getgroups",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getgroups32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getitimer",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getpeername",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getpgid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getpgrp",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getpid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getppid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getpriority",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getrandom",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getresgid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getresgid32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getresuid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getresuid32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getrlimit",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "get_robust_list",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getrusage",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getsid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getsockname",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getsockopt",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "get_thread_area",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "gettid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "gettimeofday",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getuid",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getuid32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "getxattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "inotify_add_watch",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "inotify_init",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "inotify_init1",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "inotify_rm_watch",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "io_cancel",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "ioctl",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "io_destroy",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "io_getevents",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "ioprio_get",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "ioprio_set",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "io_setup",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "io_submit",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "kill",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "lchown",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "lchown32",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "lgetxattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "link",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "linkat",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "listen",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "listxattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "llistxattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "_llseek",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "lremovexattr",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "lseek",
"action": "SCMP_ACT_ALLOW",
"args": null
},
{
"name": "lsetxattr",