diff --git a/.dockerignore b/.dockerignore index cf3913aa0..10f7d7b49 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,2 @@ -.git .gitignore **/.DS_Store diff --git a/.gitignore b/.gitignore index 7204d00bb..2e9633f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.DS_Store render_app.conf +docker-compose.yml lib/WeBWorK/htdocs/tmp/renderer/gif/* lib/WeBWorK/htdocs/tmp/renderer/images/* lib/WeBWorK/htdocs/DATA/*.json diff --git a/Dockerfile b/Dockerfile index 1018d7de0..39d21a93d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,6 +43,9 @@ RUN apt-get update \ libmath-random-secure-perl \ libdata-structure-util-perl \ liblocale-maketext-lexicon-perl \ + libyaml-libyaml-perl \ + && curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \ + && apt-get install -y --no-install-recommends --no-install-suggests nodejs \ && apt-get clean \ && rm -fr /var/lib/apt/lists/* /tmp/* @@ -51,7 +54,7 @@ RUN cpanm install Mojo::Base Statistics::R::IO::Rserve Date::Format Future::Asyn COPY . . -RUN cd lib/WeBWorK/htdocs && npm install && cd ../../.. +RUN cd lib/PG/htdocs && npm install && cd ../../.. && npm install EXPOSE 3000 diff --git a/DockerfileStage1 b/DockerfileStage1 new file mode 100644 index 000000000..af053e44f --- /dev/null +++ b/DockerfileStage1 @@ -0,0 +1,53 @@ +FROM ubuntu:20.04 +MAINTAINER drdrew42 + +WORKDIR /usr/app +ARG DEBIAN_FRONTEND=noninteractive +ENV TZ=America/New_York + +RUN apt-get update \ + && apt-get install -y --no-install-recommends --no-install-suggests \ + apt-utils \ + git \ + gcc \ + npm \ + make \ + curl \ + nodejs \ + dvipng \ + openssl \ + libc-dev \ + cpanminus \ + libssl-dev \ + libgd-perl \ + zlib1g-dev \ + imagemagick \ + libdbi-perl \ + libjson-perl \ + libcgi-pm-perl \ + libjson-xs-perl \ + ca-certificates \ + libstorable-perl \ + libdatetime-perl \ + libuuid-tiny-perl \ + libtie-ixhash-perl \ + libhttp-async-perl \ + libnet-ssleay-perl \ + libarchive-zip-perl \ + libcrypt-ssleay-perl \ + libclass-accessor-perl \ + libstring-shellquote-perl \ + libextutils-cbuilder-perl \ + libproc-processtable-perl \ + libmath-random-secure-perl \ + libdata-structure-util-perl \ + liblocale-maketext-lexicon-perl \ + libyaml-libyaml-perl \ + && curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \ + && apt-get install -y --no-install-recommends --no-install-suggests nodejs \ + && apt-get clean \ + && rm -fr /var/lib/apt/lists/* /tmp/* + +RUN cpanm install Mojo::Base Statistics::R::IO::Rserve Date::Format Future::AsyncAwait Crypt::JWT IO::Socket::SSL CGI::Cookie \ + && rm -fr ./cpanm /root/.cpanm /tmp/* + diff --git a/DockerfileStage2 b/DockerfileStage2 new file mode 100644 index 000000000..fc2e07019 --- /dev/null +++ b/DockerfileStage2 @@ -0,0 +1,18 @@ +FROM renderer-base:latest +LABEL org.opencontainers.image.source=https://github.com/drdrew42/renderer +MAINTAINER drdrew42 + +WORKDIR /usr/app +ARG DEBIAN_FRONTEND=noninteractive +ENV TZ=America/New_York + + +COPY . . + +RUN cd lib/PG/htdocs && npm install && cd ../../.. && npm install + +EXPOSE 3000 + +HEALTHCHECK CMD curl -I localhost:3000/health + +CMD hypnotoad -f ./script/render_app diff --git a/Dockerfile_with_OPL b/Dockerfile_with_OPL index eb5847acb..9e5631fc2 100644 --- a/Dockerfile_with_OPL +++ b/Dockerfile_with_OPL @@ -43,6 +43,9 @@ RUN apt-get update \ libmath-random-secure-perl \ libdata-structure-util-perl \ liblocale-maketext-lexicon-perl \ + libyaml-libyaml-perl \ + && curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \ + && apt-get install -y --no-install-recommends --no-install-suggests nodejs \ && apt-get clean \ && rm -fr /var/lib/apt/lists/* /tmp/* @@ -62,9 +65,7 @@ RUN rm -r webwork-open-problem-library-master/ COPY . . -RUN cp render_app.conf.dist render_app.conf - -RUN cd lib/WeBWorK/htdocs && npm install && cd ../../.. +RUN cd lib/PG/htdocs && npm install && cd ../../.. && npm install EXPOSE 3000 diff --git a/README.md b/README.md index fe51a4216..31f939921 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # WeBWorK Standalone Problem Renderer & Editor -![Commit Activity](https://img.shields.io/github/commit-activity/m/drdrew42/renderer?style=plastic) -![License](https://img.shields.io/github/license/drdrew42/renderer?style=plastic) +![Commit Activity](https://img.shields.io/github/commit-activity/m/openwebwork/renderer?style=plastic) +![License](https://img.shields.io/github/license/openwebwork/renderer?style=plastic) This is a PG Renderer derived from the WeBWorK2 codebase @@ -13,42 +13,62 @@ This is a PG Renderer derived from the WeBWorK2 codebase mkdir volumes mkdir container git clone https://github.com/openwebwork/webwork-open-problem-library volumes/webwork-open-problem-library -git clone --recursive https://github.com/drdrew42/renderer container/ -docker build --tag renderer:1.0 ./container - -docker run -d \ - --rm \ - --name standalone-renderer \ - --publish 3000:3000 \ - --mount type=bind,source="$(pwd)"/volumes/webwork-open-problem-library/,target=/usr/app/webwork-open-problem-library \ - --env MOJO_MODE=development \ - renderer:1.0 -``` +git clone --recursive https://github.com/openwebwork/renderer container/ -If you have non-OPL content, it can be mounted as a volume at `/usr/app/private` by adding the following line to the `docker run` command: +cd container +docker build --no-cache --tag renderer-base:latest -f DockerfileStage1 . + +# If you have a local version of docker-compose.yml you should update it +# as necessary before running the next line. If not, copy the +# docker-compose.yml.dist to docker-compose.yml and edit as necessary. + +docker-compose build --no-cache + +# You set the MOJO_MODE and mount locations in docker-compose.yml +# unlike in the past where it was done in the docker run command + +docker-compose up -d -``` - --mount type=bind,source=/pathToYourLocalContentRoot,target=/usr/app/private \ ``` -A default configuration file is included in the container, but it can be overridden by mounting a replacement at the application root. This is necessary if, for example, you want to run the container in `production` mode. +To stop the container run: +``` +docker-compose down +``` +If you need to rebuild the container, but do not need to change the +packages/installs in the stage 1 build, it suffices to: ``` - --mount type=bind,source=/pathToYour/render_app.conf,target=/usr/app/render_app.conf \ +cd container +git submodule update +docker-compose build --no-cache ``` +Note: the use of `git submodule update` above is needed to make sure that the PG tree +which will be included in the Docker image is up to date. + +If you have non-OPL content, it can be mounted as a volume at `/usr/app/private` by +setting the relevant mount moint in `docker-compose.yml` so that it gets mounted under +`/usr/app/private`. + +A default `render_app.conf` configuration file is included in the container, +but it can be overridden by mounting a replacement at the application root +using `docker-compose.yml`. This is necessary if, for example, you want to run +the container in `production` mode. + ## LOCAL INSTALL ### If using a local install instead of docker: -* Clone the renderer and its submodules: `git clone --recursive https://github.com/drdrew42/renderer` +* Clone the renderer and its submodules: `git clone --recursive https://github.com/openwebwork/renderer` * Enter the project directory: `cd renderer` * Install perl dependencies listed in Dockerfile (CPANMinus recommended) * clone webwork-open-problem-library into the provided stub ./webwork-open-problem-library - `git clone https://github.com/openwebwork/webwork-open-problem-library ./webwork-open-problem-library` * copy `render_app.conf.dist` to `render_app.conf` and make any desired modifications * install other dependencies - - `cd lib/WeBWorK/htdocs` + - `npm install` + - `cd lib/PG/htdocs` - `npm install` * start the app with `morbo ./script/render_app` or `morbo -l http://localhost:3000 ./script/render_app` if changing root url * access on `localhost:3000` by default or otherwise specified root url diff --git a/docker-compose.yml.dist b/docker-compose.yml.dist new file mode 100644 index 000000000..991a34f07 --- /dev/null +++ b/docker-compose.yml.dist @@ -0,0 +1,49 @@ +version: '3.5' + +services: + renderer: + image: renderer:latest + container_name: standalone-renderer + + build: + # For use/building when docker-compose.yml is in the container directory + context: . + # For use/building when docker-compose.yml is OUTSIDE the container directory. + #context: /Path_To/container/ + + # If you would like a 1 stage build process comment out the next line, and just run "docker-compose build". + dockerfile: DockerfileStage2 + + # For the 2 stage build process: + # Stage 1 - base image with OS + CPAN packages + # docker build --no-cache --tag renderer-base:latest -f container/DockerfileStage1 . + # You can add something like + # --build-arg ADDITIONAL_BASE_IMAGE_PACKAGES="vim-tiny" + # to add additional packages to the base image + # Stage 2 - add the renderer to the base image + # docker-compose build --no-cache + + volumes: + + # Local render_app.conf if needed: + #- "./render_app.conf:/usr/app/render_app.conf" + + # OPL - from standard location + - "../volumes/webwork-open-problem-library:/usr/app/webwork-open-problem-library" + + # Private problem directories - from standard location + #- "./volumes/private:/usr/app/private" + + #hostname: myhost.mydomain.edu + + ports: + - "3000:3000" + + environment: + MOJO_MODE: development + + # The system timezone for the container can be set using + #SYSTEM_TIMEZONE: zone/city + # where zone/city must be a valid setting. + # "/usr/bin/timedatectl list-timezones" on an Ubuntu system with + # that tool installed will find valid values.