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

Docker updates 2022 07 22 #4

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.git
.gitignore
**/.DS_Store
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
*.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
lib/WeBWorK/htdocs/js/apps/Problem/problem.css
lib/WeBWorK/bin/*
webwork-open-problem-library/
private/
tmp/
tmp/*
logs/*.log
node_modules
node_modules/*
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "lib/PG"]
path = lib/PG
url = https://github.com/drgrice1/pg.git
branch = ww3-rendering-work-new
url = https://github.com/openwebwork/pg.git
branch = main
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand All @@ -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

Expand Down
53 changes: 53 additions & 0 deletions DockerfileStage1
Original file line number Diff line number Diff line change
@@ -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/*

18 changes: 18 additions & 0 deletions DockerfileStage2
Original file line number Diff line number Diff line change
@@ -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
56 changes: 36 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,42 +13,58 @@ 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 now set the MOJO_MODE and mount locations in docker-compose.yml
# instead of 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
docker-compose build --no-cache
```

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
Expand Down
49 changes: 49 additions & 0 deletions docker-compose.yml.dist
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion lib/PG
Submodule PG updated 239 files
25 changes: 13 additions & 12 deletions lib/RenderApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ BEGIN {
use Mojo::File;
$main::dirname = Mojo::File::curfile->dirname;

#RENDER_ROOT is required for initializing conf files
# RENDER_ROOT is required for initializing conf files.
$ENV{RENDER_ROOT} = $main::dirname->dirname
unless ( defined( $ENV{RENDER_ROOT} ) );

#WEBWORK_ROOT is required for PG/lib/WeBWorK/IO
$ENV{WEBWORK_ROOT} = $main::dirname . '/WeBWorK'
unless ( defined( $ENV{WEBWORK_ROOT} ) );
# WEBWORK_ROOT is required for PG/lib/WeBWorK/IO.
# PG_ROOT is required for PG/lib/PGEnvironment.pm.
# These are hardcoded to avoid conflict with environment variables for webwork2.
# There is no need for these to be configurable.
$ENV{WEBWORK_ROOT} = $main::dirname . '/WeBWorK';
$ENV{PG_ROOT} = $main::dirname . '/PG';

#used for reconstructing library paths from sym-links
# Used for reconstructing library paths from sym-links.
$ENV{OPL_DIRECTORY} = "webwork-open-problem-library";
$WeBWorK::Constants::WEBWORK_DIRECTORY = $main::dirname . "/WeBWorK";
$WeBWorK::Constants::PG_DIRECTORY = $main::dirname . "/PG";
Expand Down Expand Up @@ -60,7 +63,7 @@ sub startup {

# Handle optional CORS settings
if (my $CORS_ORIGIN = $self->config('CORS_ORIGIN')) {
die "CORS_ORIGIN ($CORS_ORIGIN) must be an absolute URL or '*'"
die "CORS_ORIGIN ($CORS_ORIGIN) must be an absolute URL or '*'"
unless ($CORS_ORIGIN eq '*' || $CORS_ORIGIN =~ /^https?:\/\//);

$self->hook(before_dispatch => sub {
Expand Down Expand Up @@ -108,12 +111,10 @@ sub startup {
$r->post('/render-api/tags')->to('IO#setTags');
}

# pass all requests via ww2_files through to lib/WeBWorK/htdocs
my $staticPath = $WeBWorK::Constants::WEBWORK_DIRECTORY."/htdocs/";
$r->any('/webwork2_files/*static' => sub {
my $c = shift;
$c->reply->file($staticPath.$c->stash('static'));
});
# Static file routes
$r->any('/webwork2_files/CAPA_Graphics/*static')->to('StaticFiles#CAPA_graphics_file');
$r->any('/webwork2_files/tmp/*static')->to('StaticFiles#temp_file');
$r->any('/pg_files/*static')->to('StaticFiles#pg_file');

# any other requests fall through
$r->any('/*fail' => sub {
Expand Down
Loading