diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ae63484 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + + - name: Set environment up + run: | + docker-compose pull + docker-compose build + docker-compose run --rm web bundle install + docker-compose run --rm web bundle exec rake db:setup + docker-compose run --rm web bundle exec rake db:test:prepare + + - name: Run specs + run: | + docker-compose run --rm web bundle exec rspec + + build: + needs: test + runs-on: ubuntu-22.04 + env: + DOCKER_REPOSITORY: 'instedd/mbuilder' + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASS: ${{ secrets.DOCKER_PASS }} + steps: + - uses: actions/checkout@v2 + - name: Build image & push to Docker Hub + run: ./build.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a6bd9b7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: ruby -cache: bundler -services: - - elasticsearch -before_script: - - bundle exec rake db:setup -script: - - bundle exec rspec -notifications: - slack: - secure: L7ysz/oWaFNMmSFmJN4z2iRqyDX2zmT8sqvsukKTNMyl9ENqbZFPyvC53ICMa2DLtP/X/XX1tzfHEqg9hZ2On2hju/Ohn9DG+RRjCm5Cu+05rpkliZO98gfVo1pTAfA4vn3HXsSHHRL5tmjUx7+YxbbF3YugJ2M0TUqFxI/1yiM= diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4fb60e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM ruby:2.0 + +# Cleanup expired Let's Encrypt CA (Sept 30, 2021) +RUN sed -i '/^mozilla\/DST_Root_CA_X3/s/^/!/' /etc/ca-certificates.conf && update-ca-certificates -f + +# # Install dependencies +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + nodejs \ + && apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +WORKDIR /app + +# Install gem bundle +ADD Gemfile /app/ +ADD Gemfile.lock /app/ +RUN bundle install --jobs 3 --without development test + +# Install the application +ADD . /app + +# Precompile assets +RUN bundle exec rake assets:precompile RAILS_ENV=production SECRET_KEY_BASE=secret + +ENV RAILS_LOG_TO_STDOUT=true +ENV RAILS_ENV=production +EXPOSE 80 + +# Add scripts +ADD docker/database.yml /app/config/database.yml + +CMD ["puma", "-e", "production", "-b", "tcp://0.0.0.0:80"] diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..5b8f5ae --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,13 @@ +FROM ruby:2.0 + +# Cleanup expired Let's Encrypt CA (Sept 30, 2021) +RUN sed -i '/^mozilla\/DST_Root_CA_X3/s/^/!/' /etc/ca-certificates.conf && update-ca-certificates -f + +# # Install dependencies +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + nodejs \ + && apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +WORKDIR /app diff --git a/Gemfile b/Gemfile index 3660d93..0ea6667 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,7 @@ source 'https://rubygems.org' +git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } + gem 'rails', '~> 3.2.17' gem 'mysql2' @@ -57,7 +59,7 @@ group :development, :test do gem 'fakefs', :require => 'fakefs/safe' gem 'machinist' gem 'capistrano', '2.15.4' - gem 'rvm-capistrano' + gem 'rvm-capistrano', require: false gem 'timecop' gem 'rails-dev-tweaks' end diff --git a/Gemfile.lock b/Gemfile.lock index d038173..46f3b3f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,26 @@ GIT - remote: git://github.com/instedd/alto_guisso.git + remote: https://bitbucket.org/instedd/pigeon.git + revision: 50f5268e3690071937cdcce581a29922ef723bf7 + branch: master + specs: + instedd-pigeon (0.3.1) + json + rails (~> 3.2) + rest-client + twilio-ruby + twitter_oauth + +GIT + remote: https://bitbucket.org/instedd/resource_map_api_client.git + revision: c08251ba1888e6469c24328b55e279f11c22e152 + branch: master + specs: + resource_map_api_client (0.0.1) + alto_guisso + memoist + +GIT + remote: https://github.com/instedd/alto_guisso revision: 6d72573c211f45ff95d36847af733449acdfa04a branch: master specs: @@ -7,7 +28,7 @@ GIT rack-oauth2 GIT - remote: git://github.com/instedd/alto_guisso_rails.git + remote: https://github.com/instedd/alto_guisso_rails revision: bd944d08c59e5835285f0d956fb1fb00402fc385 branch: master specs: @@ -20,7 +41,7 @@ GIT ruby-openid GIT - remote: git://github.com/instedd/instedd-bootstrap.git + remote: https://github.com/instedd/instedd-bootstrap revision: f7677c0a25064c5feb9e199be739253ec8973b3a branch: master specs: @@ -30,7 +51,19 @@ GIT sass-rails GIT - remote: git://github.com/instedd/ruby-hub_client.git + remote: https://github.com/instedd/recurring_select + revision: a20ad65f609239cd9d37dd8904dc9a43726cef31 + branch: instedd + specs: + recurring_select (1.2.1) + coffee-rails (>= 3.1) + ice_cube (>= 0.11) + jquery-rails (>= 3.0) + rails (>= 3.2) + sass-rails (>= 3.1) + +GIT + remote: https://github.com/instedd/ruby-hub_client revision: 9fef94a685e4ba16a9826e00cc22fd88c3a0cef9 branch: master specs: @@ -38,7 +71,7 @@ GIT rest-client GIT - remote: git://github.com/instedd/telemetry_rails.git + remote: https://github.com/instedd/telemetry_rails revision: cc25f9b8bf6cbafa92f9012c72a9da7e5675d392 branch: master specs: @@ -47,39 +80,6 @@ GIT global_phone_dbgen rails -GIT - remote: https://bitbucket.org/instedd/pigeon.git - revision: 50f5268e3690071937cdcce581a29922ef723bf7 - branch: master - specs: - instedd-pigeon (0.3.1) - json - rails (~> 3.2) - rest-client - twilio-ruby - twitter_oauth - -GIT - remote: https://bitbucket.org/instedd/resource_map_api_client.git - revision: c08251ba1888e6469c24328b55e279f11c22e152 - branch: master - specs: - resource_map_api_client (0.0.1) - alto_guisso - memoist - -GIT - remote: https://github.com/instedd/recurring_select - revision: a20ad65f609239cd9d37dd8904dc9a43726cef31 - branch: instedd - specs: - recurring_select (1.2.1) - coffee-rails (>= 3.1) - ice_cube (>= 0.11) - jquery-rails (>= 3.0) - rails (>= 3.2) - sass-rails (>= 3.1) - GEM remote: https://rubygems.org/ specs: diff --git a/README.md b/README.md index 537595a..e26db32 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,11 @@ mBuilder is a Ruby on Rails application. It uses/depends on: * **guisso** (optional) in order to integrate with InSTEDD's Single Sign-On. [more](http://login.instedd.org) * **resourcemap** (optional) in order to read/write data to resourcemap collections. [more](http://resourcemap.instedd.org) -## Setup +## Docker Development + +You can set up a `docker-compose`-based development environment by running the `./dev-setup.sh` script on the repo's root. Then `docker-compose up` to start all the services. + +## Local Setup 1. Checkout 2. Setup rails project as usual. `$ bundle && rails db:create db:schema:load` diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..b129f6f --- /dev/null +++ b/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -eo pipefail + +# This will load the script from this repository. Make sure to point to a specific commit so the build continues to work +# event if breaking changes are introduced in this repository +source <(curl -s https://raw.githubusercontent.com/manastech/ci-docker-builder/14726d1aa865b754686818b51a9cbefe75da7943/build.sh) + +# Prepare the build +dockerSetup + +# Write a VERSION file for the footer +echo $VERSION > VERSION + +# Build and push the Docker image +dockerBuildAndPush diff --git a/config/database.yml b/config/database.yml index c974a6a..fd42b67 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,5 +1,6 @@ development: adapter: mysql2 + host: <%= ENV["DATABASE_HOST"] %> encoding: utf8 database: mbuilder_development pool: 5 @@ -8,6 +9,7 @@ development: test: adapter: mysql2 + host: <%= ENV["DATABASE_HOST"] %> encoding: utf8 database: mbuilder_test pool: 5 diff --git a/dev-setup.sh b/dev-setup.sh new file mode 100755 index 0000000..b266f7f --- /dev/null +++ b/dev-setup.sh @@ -0,0 +1,6 @@ +#!/bin/sh +docker-compose pull +docker-compose build +docker-compose up -d db +docker-compose run --rm --no-deps web bundle install +docker-compose run --rm web bash -c 'rake db:setup db:seed' diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..49223a7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: '2.0' + +services: + db: + image: mysql:5.5 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + volumes: + - db:/var/lib/mysql + + elasticsearch: + image: elasticsearch:1.7.5 + volumes: + - elasticsearch:/usr/share/elasticsearch/data + + web: &rails + build: + context: . + dockerfile: Dockerfile.dev + environment: + DATABASE_HOST: 'db' + ELASTICSEARCH_URL: 'http://elasticsearch:9200' + volumes: + - .:/app + - bundle:/usr/local/bundle + tmpfs: /app/tmp + depends_on: + - db + - elasticsearch + command: rails server -b 0.0.0.0 -p 80 + ports: + - 80 + + delayed: + <<: *rails + command: "bundle exec rake jobs:work" + ports: [] + +volumes: + db: + bundle: + elasticsearch: diff --git a/docker/database.yml b/docker/database.yml new file mode 100644 index 0000000..acc37b7 --- /dev/null +++ b/docker/database.yml @@ -0,0 +1,2 @@ +production: + url: <%= ENV['DATABASE_URL'] %>