diff --git a/.dockerignore b/.dockerignore index 51d21e85c..808f30c7e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,9 +3,7 @@ config/database.yml config/site.yml coverage db/*.sqlite3 -doc features log public/assets -test tmp diff --git a/.github/workflows/build-latest.yml b/.github/workflows/build-latest.yml index 53bf9d347..c9d1cce5e 100644 --- a/.github/workflows/build-latest.yml +++ b/.github/workflows/build-latest.yml @@ -35,6 +35,7 @@ jobs: uses: docker/build-push-action@v3 with: context: . + target: production push: true tags: | tracksapp/tracks:latest diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index ccc9a016f..f70b4a331 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -35,6 +35,7 @@ jobs: uses: docker/build-push-action@v3 with: context: . + target: production push: true tags: | tracksapp/tracks:${{ github.event.release.name }} diff --git a/Dockerfile b/Dockerfile index 1a637febf..fb60c2346 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,13 @@ -FROM ruby:3.3 - -# throw errors if Gemfile has been modified since Gemfile.lock -RUN bundle config --global frozen 1 +ARG RUBY_VERSION=3.3 +FROM ruby:${RUBY_VERSION} AS base 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 netcat-openbsd +RUN gem install bundler RUN mkdir /app/log @@ -38,10 +32,33 @@ COPY db /app/db/ COPY .git /app/.git -RUN RAILS_ENV=production bundle exec rake assets:precompile +COPY Gemfile* /app/ ENTRYPOINT ["/app/docker-entrypoint.sh"] - EXPOSE 3000 - CMD ["./bin/rails", "server", "-b", "0.0.0.0"] + +FROM base AS precompile +RUN bundle config set with assets +RUN bundle config set deployment true +RUN bundle install --jobs 4 +RUN RAILS_GROUPS=assets bundle exec rake assets:precompile + +# Build the environment-specific stuff +FROM base AS production +RUN bundle config --global frozen 1 +RUN bundle install --jobs 4 +COPY --from=precompile /app/public/assets /app/public/assets + +FROM base AS test +COPY test /app/test/ +# For testing the API client +COPY doc /app/doc/ +RUN bundle config set with development test assets +RUN bundle config --global frozen 1 +RUN bundle install --jobs 4 +RUN RAILS_GROUPS=assets bundle exec rake assets:precompile + +FROM base AS development +RUN bundle config set with development test +RUN bundle install --jobs 4 diff --git a/Dockerfile-3.0 b/Dockerfile-3.0 deleted file mode 100644 index 534d5c926..000000000 --- a/Dockerfile-3.0 +++ /dev/null @@ -1,30 +0,0 @@ -FROM ruby:3.0 - -# throw errors if Gemfile has been modified since Gemfile.lock -RUN bundle config --global frozen 1 - -WORKDIR /app - -RUN touch /etc/app-env - -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 - -COPY Gemfile* /app/ -RUN gem install bundler -RUN bundle install --jobs 4 - -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-3.1 b/Dockerfile-3.1 deleted file mode 100644 index 13ee22a20..000000000 --- a/Dockerfile-3.1 +++ /dev/null @@ -1,30 +0,0 @@ -FROM ruby:3.1 - -# throw errors if Gemfile has been modified since Gemfile.lock -RUN bundle config --global frozen 1 - -WORKDIR /app - -RUN touch /etc/app-env - -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 - -COPY Gemfile* /app/ -RUN gem install bundler -RUN bundle install --jobs 4 - -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-3.2 b/Dockerfile-3.2 deleted file mode 100644 index 0e143fd71..000000000 --- a/Dockerfile-3.2 +++ /dev/null @@ -1,30 +0,0 @@ -FROM ruby:3.2 - -# throw errors if Gemfile has been modified since Gemfile.lock -RUN bundle config --global frozen 1 - -WORKDIR /app - -RUN touch /etc/app-env - -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 - -COPY Gemfile* /app/ -RUN gem install bundler -RUN bundle install --jobs 4 - -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 a55f6a626..3e281bad6 100644 --- a/Gemfile +++ b/Gemfile @@ -28,20 +28,20 @@ gem 'sanitize', '~> 6.1' gem 'tracks-chartjs-ror' gem 'will_paginate' -# See https://github.com/sstephenson/execjs#readme for more supported runtimes -gem 'mini_racer', group: :therubyracer - # Use --without argument to skip unnecessary drivers gem 'sqlite3', group: :sqlite gem 'mysql2', '~> 0.5.6', group: :mysql gem 'pg', '~> 1.5.6', group: :postgresql -group :development do +group :assets, :optional => true do + gem 'listen' + gem 'tolk', '~> 5.0.1' +end + +group :development, :optional => true do gem 'spring', '~> 4' gem 'yard' - gem 'tolk', '~> 5.0.1' - gem 'bullet' gem 'rack-mini-profiler' gem 'solargraph' @@ -49,22 +49,25 @@ group :development do gem 'i18n-tasks', '~> 1.0.14' end -group :development, :test do +group :development, :test, :optional => true do gem 'byebug' - gem 'listen' - gem 'rubocop', '~> 1.65', require: false + gem 'rubocop', '~> 1.65' + gem 'mini_racer' end -group :test do - +group :test, :optional => true do # get test coverage info on codeclimate - gem 'codeclimate-test-reporter', '1.0.9', group: :test, require: nil + gem 'codeclimate-test-reporter', '1.0.9' gem 'database_cleaner', '~> 1' gem 'factory_bot_rails' gem 'minitest-stub-const' - gem 'mocha', :require => false + gem 'mocha' gem 'rails-controller-testing' gem 'rails-dom-testing', '~> 2.2.0' gem 'rspec-expectations' gem 'simplecov' end + +group :stripe, :optional => true do + gem 'stripe', "~> 5.24.0" +end diff --git a/Gemfile.lock b/Gemfile.lock index 0813fee83..fad802ed2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -304,7 +304,7 @@ GEM tilt (~> 2.0) yard (~> 0.9, >= 0.9.24) spring (4.2.1) - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) @@ -313,6 +313,7 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.6.9) mini_portile2 (~> 2.8.0) + stripe (5.24.0) strscan (3.1.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) @@ -383,6 +384,7 @@ DEPENDENCIES solargraph spring (~> 4) sqlite3 + stripe (~> 5.24.0) tolk (~> 5.0.1) tracks-chartjs-ror uglifier (>= 1.3.0) diff --git a/docker-compose.yml b/docker-compose.yml index 008724631..b60ecad3a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,9 @@ services: volumes: - db-data:/var/lib/mysql web: - build: . + build: + context: . + target: production # can also be development or test environment: # These are set in script/ci-build, so we need to pass-thru them. RAILS_ENV: $RAILS_ENV diff --git a/script/cibuild b/script/cibuild index 564941a48..a68de2ad0 100755 --- a/script/cibuild +++ b/script/cibuild @@ -2,7 +2,9 @@ set -e -docker_compose="docker-compose --file test-envs/docker-compose-$1-$2.yml" +export RUBY_VERSION=$1 + +docker_compose="docker-compose --file test-envs/docker-compose-$2.yml" function cleanup() { $docker_compose down diff --git a/script/poll-for-db b/script/poll-for-db index 05b1db4b9..4be07922a 100755 --- a/script/poll-for-db +++ b/script/poll-for-db @@ -2,13 +2,15 @@ echo "==> Polling DB…" -appdir=$(cd $(dirname "$0")/.. && pwd) -[ -f /etc/app-env ] || exec "$appdir/script/docker-environment" $0 $@ +if [ "$DATABASE_TYPE" == "mysql" ]; then + appdir=$(cd $(dirname "$0")/.. && pwd) + [ -f /etc/app-env ] || exec "$appdir/script/docker-environment" $0 $@ -for i in {1..60}; do - nc -z -w5 db 3306 && exit - sleep 1 -done + for i in {1..60}; do + nc -z -w5 db 3306 && exit + sleep 1 + done -echo "Unable to reach database!" -exit 1 + echo "Unable to reach database!" + exit 1 +fi diff --git a/test-envs/docker-compose-3.0-mysql.yml b/test-envs/docker-compose-3.0-mysql.yml deleted file mode 100644 index 2cd0413fe..000000000 --- a/test-envs/docker-compose-3.0-mysql.yml +++ /dev/null @@ -1,29 +0,0 @@ -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-3.0 - 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-3.1-mysql.yml b/test-envs/docker-compose-3.1-mysql.yml deleted file mode 100644 index 03f609e5d..000000000 --- a/test-envs/docker-compose-3.1-mysql.yml +++ /dev/null @@ -1,29 +0,0 @@ -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-3.1 - 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-3.2-mysql.yml b/test-envs/docker-compose-3.2-mysql.yml deleted file mode 100644 index 48b2e6d9b..000000000 --- a/test-envs/docker-compose-3.2-mysql.yml +++ /dev/null @@ -1,29 +0,0 @@ -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-3.2 - 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-3.3-postgres.yml b/test-envs/docker-compose-3.3-postgres.yml deleted file mode 100644 index a66d41b21..000000000 --- a/test-envs/docker-compose-3.3-postgres.yml +++ /dev/null @@ -1,32 +0,0 @@ -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-3.3-sqlite.yml b/test-envs/docker-compose-3.3-sqlite.yml deleted file mode 100644 index 4fd50bd59..000000000 --- a/test-envs/docker-compose-3.3-sqlite.yml +++ /dev/null @@ -1,17 +0,0 @@ -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-3.3-mysql.yml b/test-envs/docker-compose-mysql.yml similarity index 91% rename from test-envs/docker-compose-3.3-mysql.yml rename to test-envs/docker-compose-mysql.yml index 67e67f174..6982fe3a3 100644 --- a/test-envs/docker-compose-3.3-mysql.yml +++ b/test-envs/docker-compose-mysql.yml @@ -10,7 +10,9 @@ services: web: build: context: .. - dockerfile: Dockerfile + target: test + args: + RUBY_VERSION: ${RUBY_VERSION} environment: # These are set in script/ci-build, so we need to pass-thru them. RAILS_ENV: $RAILS_ENV diff --git a/test-envs/docker-compose-3.0-postgres.yml b/test-envs/docker-compose-postgres.yml similarity index 92% rename from test-envs/docker-compose-3.0-postgres.yml rename to test-envs/docker-compose-postgres.yml index 0c6d9b03e..378d30cf8 100644 --- a/test-envs/docker-compose-3.0-postgres.yml +++ b/test-envs/docker-compose-postgres.yml @@ -10,7 +10,9 @@ services: web: build: context: .. - dockerfile: Dockerfile-3.0 + target: test + args: + RUBY_VERSION: ${RUBY_VERSION} environment: # These are set in script/ci-build, so we need to pass-thru them. RAILS_ENV: $RAILS_ENV diff --git a/test-envs/docker-compose-3.0-sqlite.yml b/test-envs/docker-compose-sqlite.yml similarity index 69% rename from test-envs/docker-compose-3.0-sqlite.yml rename to test-envs/docker-compose-sqlite.yml index ba4d37094..374ff3eb9 100644 --- a/test-envs/docker-compose-3.0-sqlite.yml +++ b/test-envs/docker-compose-sqlite.yml @@ -3,15 +3,19 @@ services: web: build: context: .. - dockerfile: Dockerfile-3.0 + target: test + args: + RUBY_VERSION: ${RUBY_VERSION} 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_NAME: "/app/db/db.sqlite" DATABASE_TYPE: sqlite3 volumes: - - ${VOLUME:-..}:/app:Z + - ${VOLUME:-sqlite}:/app/db:Z - ${VOLUME:-..}/config/database.docker.yml:/app/config/database.yml:Z - ${VOLUME:-..}/config/site.docker.yml:/app/config/site.yml:Z ports: - 3000:3000 +volumes: + sqlite: {}