diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c2a51a65..73143937 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,11 +1,38 @@ --- -name: Continuous Integration +name: Automated tests on: pull_request jobs: - test: + test25mysql: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - run: bash -x script/cibuild + - run: bash -x script/cibuild 2.5 mysql + + test26mysql: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: bash -x script/cibuild 2.6 mysql + + test27mysql: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: bash -x script/cibuild 2.7 mysql + + test26postgres: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: bash -x script/cibuild 2.6 postgres + + test26sqlite: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: bash -x script/cibuild 2.6 sqlite + +# - run: bash -x script/cibuild 2.5 postgres +# - run: bash -x script/cibuild 2.7 postgres diff --git a/Dockerfile-2.5 b/Dockerfile-2.5 new file mode 100644 index 00000000..a3fb50a1 --- /dev/null +++ b/Dockerfile-2.5 @@ -0,0 +1,30 @@ +FROM ruby:2.5 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +WORKDIR /app + +RUN touch /etc/app-env + +COPY Gemfile* /app/ +RUN gem install bundler +RUN bundle install --jobs 4 + +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN apt-get update && apt-get install -y yarn + +RUN mkdir /app/log + +COPY . /app/ +COPY config/database.docker.yml /app/config/database.yml +COPY config/site.docker.yml /app/config/site.yml + +RUN RAILS_ENV=production bundle exec rake assets:precompile + +ENTRYPOINT ["/app/docker-entrypoint.sh"] + +EXPOSE 3000 + +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/Dockerfile-2.7 b/Dockerfile-2.7 new file mode 100644 index 00000000..a68b373d --- /dev/null +++ b/Dockerfile-2.7 @@ -0,0 +1,30 @@ +FROM ruby:2.7 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +WORKDIR /app + +RUN touch /etc/app-env + +COPY Gemfile* /app/ +RUN gem install bundler +RUN bundle install --jobs 4 + +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN apt-get update && apt-get install -y yarn + +RUN mkdir /app/log + +COPY . /app/ +COPY config/database.docker.yml /app/config/database.yml +COPY config/site.docker.yml /app/config/site.yml + +RUN RAILS_ENV=production bundle exec rake assets:precompile + +ENTRYPOINT ["/app/docker-entrypoint.sh"] + +EXPOSE 3000 + +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/Gemfile b/Gemfile index 8883213e..7db4a340 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem 'jquery-ui-rails' , '~>6.0.1' # Alternatively use --without arguments to bundler to not install that group gem "sqlite3", group: :sqlite gem "mysql2", "~> 0.5.3", group: :mysql +gem "pg", "~> 1.2.3", group: :postgresql gem "RedCloth" gem "sanitize", "~> 5.2" @@ -70,7 +71,6 @@ group :test do gem 'rails-controller-testing' gem 'rails-dom-testing', '~> 2.0.0' - gem "factory_bot_rails" gem "rspec-expectations" gem "database_cleaner" diff --git a/Gemfile.lock b/Gemfile.lock index 1892e92c..02fdaf44 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -165,6 +165,7 @@ GEM parallel (1.19.2) parser (2.7.1.4) ast (~> 2.4.1) + pg (1.2.3) puma (4.3.5) nio4r (~> 2.0) rack (2.2.3) @@ -326,6 +327,7 @@ DEPENDENCIES mocha mysql2 (~> 0.5.3) paperclip + pg (~> 1.2.3) puma (~> 4.3) rack-mini-profiler rails (~> 6.0.3) diff --git a/script/cibuild b/script/cibuild index 783a1833..564941a4 100755 --- a/script/cibuild +++ b/script/cibuild @@ -2,7 +2,7 @@ set -e -docker_compose="docker-compose --file docker-compose.yml" +docker_compose="docker-compose --file test-envs/docker-compose-$1-$2.yml" function cleanup() { $docker_compose down @@ -25,6 +25,12 @@ script/poll-for-db # Leaving this in since it will be needed for Rails 5 $docker_compose run web bin/rails db:environment:set RAILS_ENV=test || true -$docker_compose run web bin/rake db:reset +if [ "$2" == "mysql" ]; +then + $docker_compose run web bin/rake db:reset +else + $docker_compose run web bin/rake db:migrate + $docker_compose run web bin/rake db:seed +fi $docker_compose run web bin/rake test diff --git a/test-envs/docker-compose-2.5-mysql.yml b/test-envs/docker-compose-2.5-mysql.yml new file mode 100644 index 00000000..249e1f35 --- /dev/null +++ b/test-envs/docker-compose-2.5-mysql.yml @@ -0,0 +1,29 @@ +version: '3' +services: + db: + image: mysql:5.7 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + MYSQL_DATABASE: ${TRACKS_DB:-tracks} + volumes: + - db-data:/var/lib/mysql + web: + build: + context: .. + dockerfile: Dockerfile-2.5 + environment: + # These are set in script/ci-build, so we need to pass-thru them. + RAILS_ENV: $RAILS_ENV + DATABASE_NAME: $DATABASE_NAME + DATABASE_USERNAME: root + DATABASE_PASSWORD_EMPTY: 1 + volumes: + - ${VOLUME:-..}:/app:Z + - ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z + - ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z + ports: + - 3000:3000 + depends_on: + - db +volumes: + db-data: diff --git a/test-envs/docker-compose-2.6-mysql.yml b/test-envs/docker-compose-2.6-mysql.yml new file mode 100644 index 00000000..67e67f17 --- /dev/null +++ b/test-envs/docker-compose-2.6-mysql.yml @@ -0,0 +1,29 @@ +version: '3' +services: + db: + image: mysql:5.7 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + MYSQL_DATABASE: ${TRACKS_DB:-tracks} + volumes: + - db-data:/var/lib/mysql + web: + build: + context: .. + dockerfile: Dockerfile + environment: + # These are set in script/ci-build, so we need to pass-thru them. + RAILS_ENV: $RAILS_ENV + DATABASE_NAME: $DATABASE_NAME + DATABASE_USERNAME: root + DATABASE_PASSWORD_EMPTY: 1 + volumes: + - ${VOLUME:-..}:/app:Z + - ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z + - ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z + ports: + - 3000:3000 + depends_on: + - db +volumes: + db-data: diff --git a/test-envs/docker-compose-2.6-postgres.yml b/test-envs/docker-compose-2.6-postgres.yml new file mode 100644 index 00000000..a66d41b2 --- /dev/null +++ b/test-envs/docker-compose-2.6-postgres.yml @@ -0,0 +1,32 @@ +version: '3' +services: + db: + image: postgres:13 + environment: + POSTGRES_DB: ${DATABASE_NAME:-tracks} + POSTGRES_PASSWORD: password + volumes: + - db-data:/var/lib/postgresql/data + web: + build: + context: .. + dockerfile: Dockerfile + environment: + # These are set in script/ci-build, so we need to pass-thru them. + RAILS_ENV: $RAILS_ENV + DATABASE_NAME: $DATABASE_NAME + DATABASE_USERNAME: postgres + DATABASE_PASSWORD: password + DATABASE_TYPE: postgresql + DATABASE_ENCODING: unicode + DATABASE_PORT: 5432 + volumes: + - ${VOLUME:-..}:/app:Z + - ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z + - ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z + ports: + - 3000:3000 + depends_on: + - db +volumes: + db-data: diff --git a/test-envs/docker-compose-2.6-sqlite.yml b/test-envs/docker-compose-2.6-sqlite.yml new file mode 100644 index 00000000..4fd50bd5 --- /dev/null +++ b/test-envs/docker-compose-2.6-sqlite.yml @@ -0,0 +1,17 @@ +version: '3' +services: + web: + build: + context: .. + dockerfile: Dockerfile + environment: + # These are set in script/ci-build, so we need to pass-thru them. + RAILS_ENV: $RAILS_ENV + DATABASE_NAME: "/app/db.sqlite" + DATABASE_TYPE: sqlite3 + volumes: + - ${VOLUME:-..}:/app:Z + - ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z + - ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z + ports: + - 3000:3000 diff --git a/test-envs/docker-compose-2.7-mysql.yml b/test-envs/docker-compose-2.7-mysql.yml new file mode 100644 index 00000000..58e433ff --- /dev/null +++ b/test-envs/docker-compose-2.7-mysql.yml @@ -0,0 +1,29 @@ +version: '3' +services: + db: + image: mysql:5.7 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + MYSQL_DATABASE: ${TRACKS_DB:-tracks} + volumes: + - db-data:/var/lib/mysql + web: + build: + context: .. + dockerfile: Dockerfile-2.7 + environment: + # These are set in script/ci-build, so we need to pass-thru them. + RAILS_ENV: $RAILS_ENV + DATABASE_NAME: $DATABASE_NAME + DATABASE_USERNAME: root + DATABASE_PASSWORD_EMPTY: 1 + volumes: + - ${VOLUME:-..}:/app:Z + - ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z + - ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z + ports: + - 3000:3000 + depends_on: + - db +volumes: + db-data: