-
Notifications
You must be signed in to change notification settings - Fork 11
Update README and add Dockerfile #79
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
base: master
Are you sure you want to change the base?
Changes from all commits
ed87856
88f6366
68a6402
358b6f2
3ac4e4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Build invocation: | ||
| # May need to be executed with --memory-swap -1 or else out of memory error | ||
| # docker build --memory-swap -1 . -t nztrain:latest | ||
|
|
||
| # Execution invocation: | ||
| # Privileged mode is required for control groups | ||
| # Must be invoked with '--network host' for port exposure | ||
| # docker run --privileged --network host -it nztrain:latest | ||
| # <C-p> <C-q> to detach | ||
|
|
||
| FROM ubuntu:xenial | ||
|
|
||
| # Services cannot be started within Docker build environment | ||
| RUN printf "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d | ||
| RUN apt-get update && apt-get install -y sudo git \ | ||
| libpq-dev software-properties-common curl locales | ||
|
|
||
| # Set locales for database | ||
| ENV LANG en_US.UTF-8 | ||
| ENV LANGUAGE en_US:en | ||
| ENV LC_ALL en_US.UTF-8 | ||
| RUN echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen && locale-gen | ||
| RUN update-locale LANG=en_US.UTF-8 | ||
|
|
||
| # Install RVM | ||
| RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys \ | ||
| 409B6B1796C275462A1703113804BB82D39DC0E3 \ | ||
| 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | ||
| RUN curl -L https://get.rvm.io | bash -s stable | ||
| ENV PATH="/usr/local/rvm/bin/:${PATH}" | ||
| SHELL ["/bin/bash", "-l", "-c"] | ||
|
|
||
| # Install Ruby 2.3.8 | ||
| RUN rvm requirements | ||
| RUN rvm install 2.3.8 | ||
| RUN gem install bundler --no-ri --no-rdoc | ||
|
|
||
| WORKDIR /nztrain | ||
| COPY script ./script | ||
| RUN bash script/install/maxmind.bash | ||
| RUN yes | bash script/install/imagemagick.bash | ||
|
|
||
| COPY config ./config | ||
| RUN RAILS_ENV=development DATABASE_USERNAME=root DATABASE=nztrain \ | ||
| TEST_DATABASE=nztraintest APP_NAME=nztrain USER=root \ | ||
| APP_USER=root UNICORN_PORT= REDIS_HOST=localhost REDIS_PORT=6379 \ | ||
| REDIS_PASS=@/etc/redis/redis.conf REDIS_INSTALL=true \ | ||
| SERVER_NAME=_ bash script/install/config.bash --defaults | ||
| # Avoid updating as database servers are not live yet | ||
| RUN yes | update=false bash script/install.bash | ||
|
|
||
| COPY Gemfile* ./ | ||
| # Bundle installation is invoked in advance to avoid prompt | ||
| RUN bundle install --deployment | ||
|
|
||
| COPY . . | ||
| RUN service postgresql start; \ | ||
| service redis start; \ | ||
| bash script/update.bash; \ | ||
| rm /var/run/redis/redis.pid; \ | ||
| service postgresql stop | ||
|
|
||
| CMD service redis start; \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we are better to run redis/postgres outside this container and tell the app where to find them via env vars - in host and bridge (default iirc) - means this script can be vastly simplified and we can take advantsge oh GH actions having coomunity support for booting these services |
||
| service postgresql start; \ | ||
| bundle exec rails server -d; \ | ||
| bundle exec rake qless:work | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,84 @@ | ||
| == NZTrain | ||
| Status: {<img src="https://secure.travis-ci.org/NZOI/nztrain.png?branch=master" alt="Build Status" />}[http://travis-ci.org/NZOI/nztrain] {<img src="https://coveralls.io/repos/NZOI/nztrain/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/NZOI/nztrain] {<img src="https://codeclimate.com/github/NZOI/nztrain.png" />}[https://codeclimate.com/github/NZOI/nztrain] | ||
| Workflow: {<img src="https://badge.waffle.io/NZOI/nztrain.png" alt="WIP Issues" />}[http://waffle.io/NZOI/nztrain] | ||
| {<img src="https://secure.travis-ci.org/NZOI/nztrain.png?branch=master" alt="Build Status" />}[http://travis-ci.org/NZOI/nztrain] {<img src="https://coveralls.io/repos/NZOI/nztrain/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/NZOI/nztrain] {<img src="https://codeclimate.com/github/NZOI/nztrain.png" />}[https://codeclimate.com/github/NZOI/nztrain] | ||
|
|
||
| === Installation | ||
| Run `script/install.bash` to install dependencies. | ||
| === Docker Installation | ||
| This requires the Docker engine. | ||
|
|
||
| `script/update.bash` will pull changes from origin and recompile various things. This includes assets - assuming that it is for production purposes. | ||
| First build the image: | ||
|
|
||
| Both scripts depends on `script/install.cfg`, which is built using `script/install/config.bash` automatically. If `script/install.cfg` is incomplete (eg. new configuration is added), `script/install.bash` and `script/update.bash` will prompt for the new configurations required. | ||
| $ docker build --memory-swap -1 . -t nztrain:latest | ||
|
|
||
| Then execute the image: | ||
|
|
||
| $ docker run --privileged --network host -it nztrain:latest | ||
|
|
||
| The website will be served over port +3000+. | ||
|
|
||
| To inspect the running container identify the container name: | ||
|
|
||
| $ docker ps | ||
|
|
||
| Then execute an interactive bash shell in the container: | ||
|
|
||
| $ docker exec -it <container> /bin/bash | ||
|
|
||
| === Manual Installation | ||
| This requires Ubuntu Xenial (16.04). | ||
|
|
||
| Invoke the installation script within this repository: | ||
|
|
||
| $ git clone https://github.com/NZOI/nztrain.git | ||
| $ cd nztrain | ||
| $ ./script/install.bash | ||
|
|
||
| Select all default configuration options by pressing enter repeatedly. | ||
|
|
||
| You will be prompted to select an option to install Ruby. Choose to install +rbenv+ (the fourth option). Then, restart the session and invoke the installation script again: | ||
|
|
||
| $ bash | ||
| $ ./script/install.bash | ||
|
|
||
| You will be prompted to select an option to install Ruby *again*. Choose to install either +RVM+ or +rbenv+. All prompts after this are package installation prompts. You may wish to quit the installation script and invoke it with +yes+. | ||
|
|
||
| $ yes | ./script/install.bash | ||
|
|
||
| Finally, run the website: | ||
|
|
||
| $ bundle exec rails server | ||
| $ bundle exec rake qless:work | ||
|
|
||
| Each of these commands must be kept alive. This can be achieved by running each command in a separate terminal session. Otherwise, you may wish to daemonize (run in the background) the commands: | ||
|
|
||
| $ bundle exec rails server -d | ||
|
|
||
| The website will be served over port +3000+. | ||
|
|
||
| === System User | ||
| This setups a system user for the website. | ||
|
|
||
| First open a Ruby console: | ||
|
|
||
| $ bundle exec rails console | ||
|
|
||
| Then, create a new user with these commands: | ||
|
|
||
| user = User.find(0) | ||
| Role.find_by_name("superadmin").users.push(user) | ||
| user.confirm! | ||
| require 'io/console' | ||
| user.reset_password!(STDIN.getpass("Password: "), STDIN.getpass("Confirm: ")) | ||
|
|
||
| You will be prompted to enter a password twice. The invocation should return true if the user creation was successful. Otherwise, the password may be too short. | ||
|
|
||
| === Updating | ||
| The update script will recompile and pull changes from origin: | ||
|
|
||
| $ cd nztrain | ||
| $ ./script/update.bash | ||
|
|
||
| Both the installation and update script depends on the configuration script: +script/install.cfg+ which is built using +script/install/config.bash+ automatically. If +script/install.cfg+ is incomplete (for example, a new configuration is added) then new configurations will be prompted. | ||
|
|
||
| === Development Tools | ||
| - `spring` instead of `bundle exec` to keep a background copy of rails running, and avoid startup time. | ||
| - `unicorn` starts of a development server (instead of Webrick). | ||
| - Use +spring+ instead of bundle to keep a background copy of Rails running and avoid startup time. | ||
| - +unicorn+ starts a development server (instead of Webrick). | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-p / --expose should also be suitable no?