Giter Club home page Giter Club logo

canvas-docker's Introduction

canvas-docker

Overview

docker-canvas aims to provide a simple, disposable, containerized Canvas instance for fast(ish) integration testing of LTI applications.

Prerequisites

  • docker (developed & tested w/ v1.12.1)

Running

docker run --name canvas-docker -p 3000:3000 -d lbjay/canvas-docker

This repo is registered at Docker Hub as an automated build. So you should also be able to docker pull lbjay/canvas-docker to get the pre-built image.

Building

  1. Clone this repo somewhere.
  2. Build the image: docker build -t canvas-docker .
  3. Start the container: docker run -t -i -p 3000:3000 --name canvas-docker canvas-docker
  4. Point your browser to http://localhost:3000. The admin user/pass login is [email protected] / canvas-docker.

The "fat" container

The Dockerfile and associated build scripts create a resulting docker image where all necessary services of the Canvas instance are run within a single container. This approach is sometimes called a "fat" container. This admittedly goes against the "Docker Philosophy" of one concern per container, but for the intended purposes of the image it offers a couple of advantages, chief among them, faster spin-up times. The functionality focus is on creating a tool for integration testing of external (LTI) apps, not general canvas development, scalability, or, god forbid, actual deployment.

Default developer_key & API access token

The image build includes the injection of default developer_key and access_token entries into the database.

  • developer key: test_developer_key
  • access token: canvas-docker

API requests should be possible, e.g.,

curl -H "Authorization: Bearer canvas-docker" http://localhost:3000/api/v1/courses

The developer key is for use with Canvas's OAuth2 Token Request Flow. For example, if you're making use of harvard-dce/django-canvas-api-token.

Outgoing Email

By default the instance's outgoing email delivery_method will be set to "test", meaning outgoing emails, such as user registration messages, will be sent to the container's stdout.

To configure 'smtp' delivery set the following $ENV values at runtime:

  • EMAIL_DELIVERY_METHOD (set this to "smtp")
  • SMTP_ADDRESS
  • SMTP_PORT
  • SMTP_USER
  • SMTP_PASS

Example using Mandrill:

docker run -d --name=canvas -p 3000:3000 -e EMAIL_DELIVERY_METHOD=smtp -e SMTP_ADDRESS=smtp.mandrillapp.com -e SMTP_PORT=587 -e SMTP_USER=<mandrill_user> -e SMTP_PASS=<mandrill_api_key> lbjay/canvas-docker

Details

  • The resulting canvas image is built and run using RAILS_ENV=development. At some point I might try creating a separate "production" flavor, but, because docker doesn't allow the setting of build-time variables except in the Dockerfile, it would require a separate Dockerfile. Also, when I did try building with RAILS_ENV=production, the resulting instance had issues with routing errors to the compiled assets, and the db:initial_setup rake task threw lots of warnings about missing triggers (?). So that.
  • Everything is currently somewhat "opinionated" in that things that would be nice to have configurable are hard-coded, e.g., postgres and canvas usernames, postgres network settings, path to the postgres data, etc.
  • The Dockerfile build process mostly follows Canvas's Quick Start guidelines with a few exeptions:
    • as mentioned above, RAILS_ENV=development
    • redis is installed, configured and used
    • the delated_job background task is executed
    • postgres is configured to not require a password for local connections, or for connections originating within a network defined by Docker's default network bridge setup: 172.17.0.0/16.

Contributors

License

Apache 2.0

Copyright

2016 President and Fellows of Harvard College

canvas-docker's People

Contributors

lbjay avatar wassimseif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

canvas-docker's Issues

Automatic user registration emails don't work.

Hi there!
I've pulled and run the latest version of canvas-docker from the docker hub, and I noticed that automatic emails don't get sent. This poses a problem when I try to create a new user, as I can't initiate a user with a password (they must confirm their email address by clicking on the link in the email they never received).

The stacktrace I found in the logs is:

Exception: SocketError: getaddrinfo: Name or service not known
...
/usr/lib/ruby/2.1.0/net/smtp.rb:520:in `start'
/opt/canvas-lms/vendor/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
/opt/canvas-lms/vendor/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
/opt/canvas-lms/vendor/bundle/ruby/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:232:in `block in deliver'
...
script/delayed_job:10:in `<main>'

It looks like the stacktrace is pointing to: https://github.com/instructure/canvas-lms/blob/stable/app/models/message.rb#L690

It looks like canvas uses this ruby gem to send emails: https://github.com/mikel/mail and according to the docs, it defaults to a local smtp server.

I'm not sure if canvas makes this configurable or not (could be verified by someone at instructure), but this could probably be resolved by adding http://www.postfix.org/ to the docker container setup process.

Can't get this to run

Seems like there is a very verbose Gems error that is preventing the database from starting? A line:

PG::ConnectionBad: FATAL: the database system is starting up

install error, asking for "workspaces-experimental true" in .yarnrc

I'm running docker build -t canvas-docker . per the first step in the README.

i'm getting:

error The workspace feature is currently experimental and needs to be manually enabled - please add "workspaces-experimental true" to your .yarnrc file.

I'll include a bit more context:

Step 31/40 : RUN yarn install --pure-lockfile
 ---> Running in a8e8ece83d62
yarn install v0.27.5
error The workspace feature is currently experimental and needs to be manually enabled - please add "workspaces-experimental true" to your .yarnrc file.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command '/bin/sh -c yarn install --pure-lockfile' returned a non-zero code: 1

Here's the full output of the command:
https://pastebin.com/raw/eVNxu9cC

I know that the yarn being used here is inside Docker, because I don't even have yarn on my local machine.

I added RUN yarn config set workspaces-experimental true to the Dockerfile, and that got me past this error -- YAY!

I'll send a pull request; you all can accept if you determine the experimental config to not pose any security risk or whatever. Thanks! (my first PR!)

Dockerfile pulls directly from canvas-lms's git master

This makes repeatable builds impossible (the build is broken right now, for example).

Here's a patch which pins the Canvas version (albeit to an older one) and seems to build:

diff --git a/Dockerfile b/Dockerfile
index bdf0776..e27e278 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,17 +10,12 @@ RUN apt-get update \
     && apt-get -y install curl software-properties-common \
     && add-apt-repository -y ppa:brightbox/ruby-ng \
     && apt-get update \
-    && apt-get install -y ruby2.1 ruby2.1-dev supervisor redis-server \
+    && apt-get install -y ruby2.3 ruby2.3-dev supervisor redis-server \
         zlib1g-dev libxml2-dev libxslt1-dev libsqlite3-dev postgresql \
         postgresql-contrib libpq-dev libxmlsec1-dev curl make g++ git \
     && apt-get clean \
     && rm -Rf /var/cache/apt
 
-RUN curl -sL https://deb.nodesource.com/setup_6.x | bash \
-    && apt-get install -y nodejs \
-    && apt-get clean \
-    && rm -Rf /var/cache/apt
-
 # Set the locale to avoid active_model_serializers bundler install failure
 RUN locale-gen en_US.UTF-8
 ENV LANG en_US.UTF-8
@@ -32,8 +27,6 @@ RUN groupadd -r canvasuser -g 433 && \
     adduser canvasuser sudo && \
     echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
 
-RUN gem install bundler --version 1.12.5
-
 COPY assets/dbinit.sh /opt/canvas/dbinit.sh
 COPY assets/start.sh /opt/canvas/start.sh
 RUN chmod 755 /opt/canvas/*.sh
@@ -43,7 +36,12 @@ COPY assets/pg_hba.conf /etc/postgresql/9.3/main/pg_hba.conf
 RUN sed -i "/^#listen_addresses/i listen_addresses='*'" /etc/postgresql/9.3/main/postgresql.conf
 
 RUN cd /opt/canvas \
-    && git clone https://github.com/instructure/canvas-lms.git
+    && curl -L https://github.com/instructure/canvas-lms/archive/release/2017-01-28.18.tar.gz -o canvas.tar.gz
+
+RUN cd /opt/canvas \
+    && tar -zxf canvas.tar.gz \
+    && rm canvas.tar.gz \
+    && mv canvas-lms-release-2017-01-28.18 canvas-lms
 
 WORKDIR /opt/canvas/canvas-lms
 
@@ -57,11 +55,19 @@ RUN for config in amazon_s3 delayed_jobs domain file_store security external_mig
        ; do cp config/$config.yml.example config/$config.yml \
        ; done
 
+RUN gem install bundler --version 1.12.5
 RUN $GEM_HOME/bin/bundle install --without="mysql"
 
-RUN npm install --unsafe-perm \
-    && $GEM_HOME/bin/bundle exec rake canvas:compile_assets \
-    && sudo npm install --unsafe-perm -g [email protected]
+RUN curl -sL https://deb.nodesource.com/setup_4.x | bash \
+    && apt-get install -y nodejs \
+    && apt-get clean \
+    && rm -Rf /var/cache/apt
+
+RUN npm install --unsafe-perm
+
+RUN $GEM_HOME/bin/bundle exec rake canvas:compile_assets_dev
+
+RUN sudo npm install --unsafe-perm -g [email protected]
 
 RUN mkdir -p log tmp/pids public/assets public/stylesheets/compiled \
     && touch Gemmfile.lock

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.