From 667ab52504e78a0c5284c2a3ee6df7c348b04ef3 Mon Sep 17 00:00:00 2001 From: Felix Auringer <716-felix.auringer@users.noreply.gitlab.hpi.de> Date: Thu, 14 Jan 2021 11:12:04 +0100 Subject: [PATCH] Add new provision script, Vagrantfile and update local setup guide --- Vagrantfile | 14 +-- config/database.yml.example | 1 + config/docker.yml.erb.example | 2 +- docs/LOCAL_SETUP.md | 112 ++++++++++------------ provision.sh | 168 --------------------------------- provision/provision.vagrant.sh | 112 ++++++++++++++++++++++ 6 files changed, 169 insertions(+), 240 deletions(-) delete mode 100644 provision.sh create mode 100644 provision/provision.vagrant.sh diff --git a/Vagrantfile b/Vagrantfile index c8d7aa96..074ded8c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -2,13 +2,13 @@ # vi: set ft=ruby : Vagrant.configure(2) do |config| - config.vm.box = "ubuntu/bionic64" + config.vm.box = "ubuntu/focal64" config.vm.provider "virtualbox" do |v| - v.memory = 8192 - v.cpus = 2 + v.memory = 4096 + v.cpus = 4 end - config.vm.network "private_network", ip: "192.168.59.104" - config.vm.network "forwarded_port", guest: 3035, host: 3035 - # config.vm.synced_folder "../data", "/vagrant_data" - config.vm.provision "shell", path: "provision.sh", privileged: false + config.vm.network "forwarded_port", host_ip: "127.0.0.1", host: 3000, guest: 3000 + config.vm.synced_folder ".", "/home/vagrant/codeocean" + config.vm.synced_folder "../dockercontainerpool", "/home/vagrant/dockercontainerpool" + config.vm.provision "shell", path: "provision/provision.vagrant.sh", privileged: false end diff --git a/config/database.yml.example b/config/database.yml.example index 60ae0d82..e59bdd23 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -4,6 +4,7 @@ default: &default password: CHANGE_ME pool: 16 username: postgres + host: localhost development: <<: *default diff --git a/config/docker.yml.erb.example b/config/docker.yml.erb.example index 3662025e..62e94d52 100644 --- a/config/docker.yml.erb.example +++ b/config/docker.yml.erb.example @@ -14,7 +14,7 @@ development: workspace_root: <%= Rails.root.join('tmp', 'files', Rails.env) %> pool: active: true - location: http://localhost:3000 + location: http://localhost:3100 refill: async: false batch_size: 8 diff --git a/docs/LOCAL_SETUP.md b/docs/LOCAL_SETUP.md index ca30a003..8aa9358b 100644 --- a/docs/LOCAL_SETUP.md +++ b/docs/LOCAL_SETUP.md @@ -1,72 +1,66 @@ # Local Setup If available, we prefer a native setup for best performance and less technical issues. Please see below for some details. - + ## Vagrant -## Install prerequisites -Install Vagrant - https://www.vagrantup.com/docs/installation/ -Install VirtualBox - https://www.virtualbox.org/wiki/Downloads +### Install prerequisites -## Install and setup -### Clone repository -Create a local codeOceanRoot: mkdir /path/to/CodeOcean ==> codeOceanRoot = /path/to/CodeOcean -Clone Repository (https://github.com/openHPI/codeocean) to codeOceanRoot -cd codeOceanRoot +- [Install Vagrant](https://www.vagrantup.com/docs/installation) +- [Install VirtualBox](https://www.virtualbox.org/wiki/Downloads) -### Get Vagrant base image -vagrant box add ubuntu/trusty64 -vagrant up +### Clone repositories -### Trouble shooting -(sometimes, particularly if VirtualBox is running under Windows as the host sysstem, parts of the provision script are) not executed. -vagrant up does not show error messages but later on the trouble starts. +The following two repositories have to be cloned in the same directory: -ln -s /etc/nginx/sites-available/code_ocean /etc/nginx/sites-enabled <= Failed (no such directory) +- [CodeOcean](https://github.com/openHPI/codeocean) +- [DockerContainerPool](https://github.com/openHPI/dockercontainerpool) -#### Make docker daemon useable without sudo -Infos taken from: http://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo +Vagrant assumes that these repositories are completely clean. For example, Vagrant will setup all configuration files in `config` (in both repositories) based on the examples provided in the same directory. Therefore it is **important** that these configuration files do not exist before running vagrant up. It is recommended to have a freshly cloned repository but you can also try to remove untracked files by running `git clean -xf` in both repositories. -vagrant ssh -sudo groupadd docker -sudo gpasswd -a ${USER} docker -sudo service docker restart -newgrp docker +### Create and start VM -apt-get install nginx -ln -s /etc/nginx/sites-available/code_ocean /etc/nginx/sites-enabled - -#### If ruby version needs to be updated (as provision.sh is not up-to-date :( ) -Infos taken from: http://stackoverflow.com/questions/26242712/installing-rvm-getting-error-there-was-an-error23 - -vagrant ssh -rvm group add rvm "$USER" - -logout and login again -rvm fix-permissions (not necessarily required) -rvm install (requested ruby version) - -cd /vagrant -gem install bundler -bundle install - -#### Pending migrations -vagrant ssh -cd /vagrant -rake db:migrate - -#### Missing config files or anything else goes wrong -Check the according parts of the provision.sh file and try to re-run them directly in the vagrant VM. -All problems that have occurred resulted from a more restrictive rights management in the VMs that run under a Windows host system. +- Switch to the `codeocean` directory +- Run `vagrant up` +- If this command fails please try the following: + - Run `vagrant destroy -f` to remove the broken VM + - Make sure that both repositories are freshly cloned, for example by deleting and cloning them again + - Retry to execute `vagrant up` +- The VM pulls only one docker image: [`openhpi/co_execenv_python:3.8`](https://hub.docker.com/layers/openhpi/co_execenv_python/3.8/images/sha256-b048f61d490d1b202016dc3bdf99a5169ec998109ae9bbae441c94bdec18e3d0) ### Start server -vagrant ssh -cd /vagrant -rails s -p 3000 -b 0.0.0.0 -### Login to CodeOcean -192.168.59.104:3000 -admin@example.org:admin +You can [configure vagrant as remote interpreter in RubyMine](https://www.jetbrains.com/help/ruby/configuring-language-interpreter.html#add_remote_ruby_interpreter) and start the rails server via RubyMine or you can start it manually from the command line: + +```bash +vagrant ssh +cd /home/vagrant/dockercontainerpool +rails s -p 3100 + +# using another ssh session +cd /home/vagrant/codeocean +rails s -p 3000 -b 0.0.0.0 +``` + +The default credentials for the administrator are: + +- email: `admin@example.org` +- password: `admin` + +## Execution Environments + +Every exercise is executed in an execution environment which is based on a docker image. In order to install a new image, have a look at the container of the openHPI team on [DockerHub](https://hub.docker.com/u/openhpi). For example you can add an [image for ruby](https://hub.docker.com/layers/openhpi/co_execenv_ruby/latest/images/sha256-70f597320567678bf8d0146d93fb1bd98457abe61c3b642e832d4e4fbe7f4526) by executing `docker pull openhpi/co_execenv_ruby:latest`. +After that make sure to configure the corresponding execution environment for the docker images you want to use in your CodeOcean instance. Therefore sign in on your running CodeOcean server as an administrator and select `Execution Environments` from the `Administration` dropdown. The `Docker Container Pool Size` should be greater than 0 for every execution environment you want to use. + +## Webpack + +This project uses `webpacker` to integrate Webpack with Rails to deliver Frontend assets. During development, the `webpack-dev-server` automatically launches together with the Rails server if not specified otherwise. In case of missing JavaScript or stylesheets or for hot reloading in the browser, you might want to start the `webpack-dev-server` manually *before starting Rails*: + +```shell script +./bin/webpack-dev-server +``` + +This will launch a dedicated server on port 3035 (default setting) and allow incoming WebSocket connections from your browser. ## Native setup (for macOS) @@ -165,13 +159,3 @@ admin@example.org:admin ```shell script rails s ``` - -## Webpack - -This project uses `webpacker` to integrate Webpack with Rails to deliver Frontend assets. During development, the `webpack-dev-server` automatically launches togehter with the Rails server if not specified otherwise. In case of missing JavaScript or stylesheets or for hot reloading in the browser, you might want to start the `webpack-dev-server` manually *before starting Rails*: - -```shell script -./bin/webpack-dev-server -``` - -This will launch a dedicated server on port 3035 (default setting) and allow incoming WebSocket connections from your browser. diff --git a/provision.sh b/provision.sh deleted file mode 100644 index ccd57e4a..00000000 --- a/provision.sh +++ /dev/null @@ -1,168 +0,0 @@ -#!/bin/bash -# rvm/rails installation from https://gorails.com/setup/ubuntu/14.04 -# passenger installation from https://www.phusionpassenger.com/library/install/nginx/install/oss/trusty/ - - -echo "OUTDATED - This script might be outdated due to the dedicated DockerContainerPool" - -######## VERSION INFORMATION ######## - -postgres_version=10 -ruby_version=2.6.3 -rails_version=5.2.3 -geckodriver_version=0.26.0 - -########## INSTALL SCRIPT ########### - -# PostgreSQL -sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main" -wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - -# passenger -sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7 -sudo apt-get -qq -y install apt-transport-https ca-certificates -sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list' - -# yarn & node -curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - -echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list -curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - - -sudo apt-get -qq update - -# code_ocean -sudo apt-get -qq -y install postgresql-client postgresql-$postgres_version postgresql-server-dev-$postgres_version vagrant yarn nodejs - -# Docker -if [ ! -f /etc/default/docker ] -then - # If Docker doesn't start, check this article - # https://medium.com/@dirk.avery/docker-error-response-from-daemon-1d46235ff61d - curl -sSL https://get.docker.com/ | sudo sh -fi -if ! grep code_ocean /etc/default/docker -then - sudo tee -a /etc/default/docker <