From 3f22c8a03610bf7a293664375ada4b7319f1c24b Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 16:12:57 +0300 Subject: [PATCH 1/8] Better Docker config: Use entrypoint to setup the environment, run in production mode by default, defaults for all config values --- Dockerfile | 8 ++++-- config/database.docker.yml | 56 ++++++++++++-------------------------- config/site.docker.yml | 6 ---- config/site.yml.tmpl | 6 ---- docker-entrypoint.sh | 17 ++++++++++++ docker-startserver.sh | 4 --- 6 files changed, 40 insertions(+), 57 deletions(-) create mode 100755 docker-entrypoint.sh delete mode 100755 docker-startserver.sh diff --git a/Dockerfile b/Dockerfile index f1f36a06d..08e473f17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,11 @@ COPY . /app/ COPY config/database.docker.yml /app/config/database.yml COPY config/site.docker.yml /app/config/site.yml -COPY docker-startserver.sh / +RUN RAILS_ENV=production bundle exec rake assets:precompile + +COPY docker-entrypoint.sh / +ENTRYPOINT ["./docker-entrypoint.sh"] EXPOSE 3000 -#CMD ["rails", "server", "-e", "production", "-b", "0.0.0.0"] -CMD ["./docker-startserver.sh"] +CMD ["rails", "server", "-b", "0.0.0.0"] diff --git a/config/database.docker.yml b/config/database.docker.yml index 790d8f779..cabb221f4 100644 --- a/config/database.docker.yml +++ b/config/database.docker.yml @@ -1,44 +1,24 @@ -#development: -# adapter: mysql2 -# database: tracks_dev -# # set this if you are storing utf8 in your mysql database to handle strings -# # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode -# # encoding: utf8 -# host: docker -# port: 3307 -# username: tracks_dev -# password: FqUKMWPz5mh8UPhypZvq - -#development: -# adapter: postgresql -# database: tracks_dev -# # set this if you are storing utf8 in your mysql database to handle strings -# # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode -# # encoding: utf8 -# host: docker -# port: 5432 -# username: tracks_dev -# password: password - -#development: -# adapter: sqlite3 -# database: db.sqlite - -#test: -# adapter: mysql2 -# database: tracks_test -# # set this if you are storing utf8 in your mysql database to handle strings -# # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode -# # encoding: utf8 -# host: docker -# port: 3307 -# username: tracks_tst -# password: 9rMNV4y6RVcqmJTo2QoR +test: + adapter: <%= ENV.fetch('DATABASE_TYPE') %> + encoding: <%= ENV.fetch('DATABASE_ENCODING') %> + database: <%= ENV.fetch('DATABASE_NAME') %> + host: <%= ENV.fetch('DATABASE_HOST') %> + port: <%= ENV.fetch('DATABASE_PORT') %> + username: <%= ENV.fetch('DATABASE_USERNAME') %> + password: <%= ENV.fetch('DATABASE_PASSWORD') %> -# Production config is disabled by default -# development: adapter: <%= ENV.fetch('DATABASE_TYPE') %> + encoding: <%= ENV.fetch('DATABASE_ENCODING') %> + database: <%= ENV.fetch('DATABASE_NAME') %> + host: <%= ENV.fetch('DATABASE_HOST') %> + port: <%= ENV.fetch('DATABASE_PORT') %> + username: <%= ENV.fetch('DATABASE_USERNAME') %> + password: <%= ENV.fetch('DATABASE_PASSWORD') %> + +production: + adapter: <%= ENV.fetch('DATABASE_TYPE') %> + encoding: <%= ENV.fetch('DATABASE_ENCODING') %> database: <%= ENV.fetch('DATABASE_NAME') %> host: <%= ENV.fetch('DATABASE_HOST') %> port: <%= ENV.fetch('DATABASE_PORT') %> diff --git a/config/site.docker.yml b/config/site.docker.yml index 02c8b373b..0b1a04d3a 100644 --- a/config/site.docker.yml +++ b/config/site.docker.yml @@ -25,12 +25,6 @@ secret_token: "secret" # Set to true when your application is running with https force_ssl: false -# Configure how static assets (images, stylesheets, etc.) will be served. -# The best practice is to have a proxying web server such as Apache or Nginx -# serve static assets (images, stylesheets, javascript) for you. Change -# this to 'true' if you want Rails to be responsible for serving the static assets -# serve_static_assets: false - # Uncomment if you want to dispatch todos that come from email based on the To: # address rather than the From: address. # email_dispatch: 'to' diff --git a/config/site.yml.tmpl b/config/site.yml.tmpl index 362c8ef63..29c53704c 100644 --- a/config/site.yml.tmpl +++ b/config/site.yml.tmpl @@ -28,12 +28,6 @@ secret_token: "change-me" # Set to true when your application is running with https force_ssl: false -# Configure how static assets (images, stylesheets, etc.) will be served. -# The best practice is to have a proxying web server such as Apache or Nginx -# serve static assets (images, stylesheets, javascript) for you. Change -# this to 'true' if you want Rails to be responsible for serving the static assets -# serve_static_assets: false - # Uncomment if you want to dispatch todos that come from email based on the To: # address rather than the From: address. # email_dispatch: 'to' diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 000000000..689318450 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +export RAILS_ENV=${RAILS_ENV:-production} +export DATABASE_NAME=${DATABASE_NAME:-tracks} +export DATABASE_HOST=${DATABASE_HOST:-db} +export DATABASE_PORT=${DATABASE_PORT:-3306} +export DATABASE_USERNAME=${DATABASE_USERNAME:-tracks} +export DATABASE_PASSWORD=${DATABASE_PASSWORD:-password} +export DATABASE_TYPE=${DATABASE_TYPE:-mysql2} +export DATABASE_ENCODING=${DATABASE_ENCODING:-utf8} + +export RAILS_SERVE_STATIC_FILES=TRUE +export RAILS_LOG_TO_STDOUT=TRUE + +rails db:migrate + +exec "$@" diff --git a/docker-startserver.sh b/docker-startserver.sh deleted file mode 100755 index dfe1e6e5e..000000000 --- a/docker-startserver.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -rails db:migrate -rails server -b 0.0.0.0 From 4d65a8f761fc44defc27ea316a35267a8d88536e Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 17:20:35 +0300 Subject: [PATCH 2/8] Overhaul the environment system in bin/ to make the defaults easier to understand. Update the installation instructions. Fixes #2170, #2372, #2329, #2368 --- bin/bundle | 4 ++-- bin/rails | 4 ++-- bin/rake | 4 ++-- bin/spring | 4 ++-- doc/installation.md | 29 +++++++++++++++++++---------- doc/upgrading.md | 9 +++++++++ script/docker-environment | 8 +------- 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/bin/bundle b/bin/bundle index d63e647b2..e3b1daa19 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -unless ENV["RAILS_ENV"] == "production" || File.exist?("#{__dir__}/../.skip-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +if File.exist?("#{__dir__}/../.use-docker") + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) end ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index e8199c68a..4ed2026f9 100755 --- a/bin/rails +++ b/bin/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -unless ENV["RAILS_ENV"] == "production" || File.exist?("#{__dir__}/../.skip-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +if File.exist?("#{__dir__}/../.use-docker") + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) end APP_PATH = File.expand_path('../config/application', __dir__) diff --git a/bin/rake b/bin/rake index f0ccc9e22..e68ed28a7 100755 --- a/bin/rake +++ b/bin/rake @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -unless ENV["RAILS_ENV"] == "production" || File.exist?("#{__dir__}/../.skip-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +if File.exist?("#{__dir__}/../.use-docker") + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) end require_relative '../config/boot' require 'rake' diff --git a/bin/spring b/bin/spring index 1e0477273..a036d6b45 100755 --- a/bin/spring +++ b/bin/spring @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -unless ENV["RAILS_ENV"] == "production" || File.exist?("#{__dir__}/../.skip-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +if File.exist?("#{__dir__}/../.use-docker") + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) end # This file loads spring without using Bundler, in order to be fast diff --git a/doc/installation.md b/doc/installation.md index 23204be26..d8a2a8632 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -1,10 +1,10 @@ # Installing Tracks -The following instructions will guide you through the installation of Tracks from source. +Tracks can be installed several ways: You can run it through Docker, which is recommended because all requirements have already been taken care of for you, or you can install it on a custom server from source. -This description is intended for people installing Tracks from scratch. If you would like to upgrade an existing installation, please see the [upgrade documentation](upgrading.md). +Instructions for the Docker-based installation as well as other options are available in the Tracks wiki: https://github.com/TracksApp/tracks/wiki/Installation. The wiki also has tips and instructions for specific environments. These instructions are only for installation from source in a custom environment. -For alternative installation options and tips for specific environments, please see [Installation](https://github.com/TracksApp/tracks/wiki/Installation) on the wiki. +This description is intended for people installing Tracks from scratch. If you would like to upgrade an existing installation, please see the [upgrade documentation](upgrading.md). ## Prerequisites @@ -12,7 +12,7 @@ Tracks has a few software requirements that must be satisfied before installatio 1. **Ruby**. Tracks requires Ruby 2.4 or greater, but is not tested with 2.7. 2. **Bundler**. Tracks requires a recent version of [Bundler](http://bundler.io) to handle the installation of dependencies. Bundler is typically installed by running `gem install bundler`. -3. **Database**. Tracks is tested on [MySQL](http://www.mysql.com/) and [SQLite](http://www.sqlite.org/), but [PostgreSQL](http://www.postgresql.org/) can also be used. Of the three, SQLite requires the least configuration. Whatever your choice, the appropriate database software must be installed. +3. **Database**. Tracks is tested on [MySQL](http://www.mysql.com/) and [SQLite](http://www.sqlite.org/), but [PostgreSQL](http://www.postgresql.org/) can also be used. Of the three, SQLite requires the least configuration but is also the least performant and may make it difficult to operate in the future. We recommend either MySQL or PostgreSQL. Whatever your choice, the appropriate database software must be installed. ## Get Tracks @@ -29,15 +29,23 @@ There are two methods of downloading Tracks: ## Set up the database -*This section only applies if you will be using Tracks with a MySQL database.* +*This section doesn't apply if using SQLite.* + +You need to create a database and database-user to use with Tracks. For this, you can use an GUI tool or go into a terminal and issue the following commands: -You need to create a database and database-user to use with Tracks. For this, you can use MySQL Administrator or go into a terminal and issue the following commands: +### MySQL - mysql -u root -p + $ mysql -u root -p mysql> CREATE DATABASE tracks; mysql> GRANT ALL PRIVILEGES ON tracks.* TO yourmysqluser@localhost \ IDENTIFIED BY 'password-goes-here' WITH GRANT OPTION; +### PostgreSQL + + $ sudo -u postgres psql + postgres=# CREATE USER tracks WITH ENCRYPTED PASSWORD 'password-goes-here'; + postgres=# CREATE DATABASE tracks OWNER=tracks; + ## Install dependencies Tracks is built upon a number of Ruby libraries (known as ‘gems’). The Bundler tool makes it easy to install all the gems that Tracks needs, and ensures that they are all the correct versions. @@ -64,8 +72,7 @@ Tracks is built upon a number of Ruby libraries (known as ‘gems’). The Bundl 2. Open the file `config/database.yml` and edit the `production:` section with the details of your database. If you are using MySQL the `adapter:` line should read `adapter: mysql2`, `host: localhost` (in the majority of cases), and your username and password should match those you assigned when you created the database. If you are using SQLite3, you should have only two lines under the production section: `adapter: sqlite3` and `database: db/tracks.db`. 3. Open the file `config/site.yml`, and read through the settings to make sure that they suit your setup. In most cases, all you need to change are the `secret_token`, the administrator email address (`admin_email`), and the time zone setting. For the time zone setting you can use the command `bundle exec rake time:zones:local` to see all available timezones on your machine 4. If you are using Windows, you may need to check the ‘shebang’ lines (`#!/usr/bin/env ruby`) of the `/public/dispatch.*` files and all the files in the `/script` directory. They are set to `#!/usr/bin/env ruby` by default. This should work for all Unix based setups (Linux or Mac OS X), but Windows users will probably have to change it to something like `#c:/ruby/bin/ruby` to point to the Ruby binary on your system. -5. If you intend to deploy Tracks using its included web server, you’ll need to uncomment and change the `serve_static_assets` configuration option to `true` in `config/site.yml` in order for the images, stylesheets, and javascript files to be served correctly. -6. If you intend to use Tracks behind a web server or reverse proxy with https enabled, ensure to set `force_ssl` option to `true`. +5. If you intend to use Tracks behind a web server or reverse proxy with https enabled, ensure to set `force_ssl` option to `true`. ## Populate your database with the Tracks schema @@ -85,10 +92,12 @@ Static assets (images, stylesheets, and javascript) need to be compiled in order While still in the Terminal inside the Tracks root directory, issue the following command: - bundle exec rails server -e production + RAILS_SERVE_STATIC_FILES=TRUE bundle exec rails server -e production If all goes well, you should see some text informing you that the server is running: `=> Rails application starting in production on http://localhost:3000`. If you are already running other services on port 3000, you need to select a different port when running the server, using the `-p` option. +Optimally you should serve static files using Nginx or Apache, especially in larger production instances. If you do this, you can omit the RAILS_SERVE_STATIC_FILES=TRUE from the start of the command. + ## Visit Tracks in a browser Visit `http://localhost:3000/signup` in a browser (or whatever URL and port was reported when you started the server in the step above) and chose a user name and password for admin user. Once logged in as admin, you can add other (ordinary level) users. If you need to access Tracks from a mobile/cellular phone browser, visit `http://yourdomain.com/mobile/`. This mobile version is a special, lightweight version of Tracks, designed to use on a mobile browser. diff --git a/doc/upgrading.md b/doc/upgrading.md index b0d86911a..8e481ddf5 100644 --- a/doc/upgrading.md +++ b/doc/upgrading.md @@ -1,4 +1,13 @@ # Upgrading Tracks +## Upgrading from Tracks 2.4.2 to 2.5 + +* If you're using the Docker Compose environment and want to run the commands in + the bin/ directory inside the container from the host system, add a .use-docker + file to the root directory. This replaces the old .skip-docker file requirement + to favor the more common setup and avoid placing unexpected requirements. + +* The Docker environment has been changed quite a bit. However, it should work + at least as before for the usual needs. ## Upgrading from Tracks 2.3 to 2.4.2 diff --git a/script/docker-environment b/script/docker-environment index 423122d6f..cfdb447c3 100755 --- a/script/docker-environment +++ b/script/docker-environment @@ -1,14 +1,8 @@ #!/bin/sh -# Run a command in the app's environment set -e -# Find our app dir and just run the command in we're in the container since the -# container is built with an /etc/app-env file inside of it. -appdir=$(cd $(dirname "$0")/.. && pwd) -[ -f /etc/app-env ] && exec "$@" - -# Otherwise, run docker compose to run our command in the container +# Check if we've been told to run the command in Docker Composer. cmd="$@"; [ "$#" -eq 0 ] && cmd=bash export VOLUME="$appdir:/app" image=${DOCKER_IMAGE:=web} From 2e408791235b58e22c8f53913d954974629056cf Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 17:34:11 +0300 Subject: [PATCH 3/8] Fix the Docker Compose configuration and remove the database config from VCS Fixes #2248. --- Dockerfile | 2 -- config/database.yml | 32 -------------------------------- docker-compose.yml | 2 ++ 3 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 config/database.yml diff --git a/Dockerfile b/Dockerfile index 08e473f17..d0062ab34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,6 @@ 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 diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index 757be5fe4..000000000 --- a/config/database.yml +++ /dev/null @@ -1,32 +0,0 @@ -development: - adapter: mysql2 - database: tracks - # set this if you are storing utf8 in your mysql database to handle strings - # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode - # encoding: utf8 - host: db - username: root - password: - -test: - adapter: mysql2 - database: tracks_test - # set this if you are storing utf8 in your mysql database to handle strings - # like "Réné". Not needed for sqlite. For PostgreSQL use encoding: unicode - # encoding: utf8 - host: db - username: root - password: - -# Production config is disabled by default -# -# production: -# adapter: mysql2 -# database: tracks -# # set this if you are storing utf8 in your mysql database to handle strings -# # like "Réné".Not needed for sqlite. For PostgreSQL use encoding: unicode -# # encoding: utf8 -# host: localhost -# username: root -# password: - diff --git a/docker-compose.yml b/docker-compose.yml index dc2b55cfd..55a832ec6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,8 @@ services: - db-data:/var/lib/mysql web: build: . + environment: + DATABASE_USERNAME: root volumes: - ${VOLUME:-.:/app} ports: From 53c7c94306192b7cadeaf36728ff833a220d0a3d Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 18:07:23 +0300 Subject: [PATCH 4/8] A few more fixes in hope of fixing the Docker Compose --- Dockerfile | 2 +- script/docker-environment | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d0062ab34..77983a172 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ COPY config/site.docker.yml /app/config/site.yml RUN RAILS_ENV=production bundle exec rake assets:precompile COPY docker-entrypoint.sh / -ENTRYPOINT ["./docker-entrypoint.sh"] +ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 3000 diff --git a/script/docker-environment b/script/docker-environment index cfdb447c3..8df83c1b8 100755 --- a/script/docker-environment +++ b/script/docker-environment @@ -2,6 +2,9 @@ set -e +# Find our app dir +appdir=$(cd $(dirname "$0")/.. && pwd) + # Check if we've been told to run the command in Docker Composer. cmd="$@"; [ "$#" -eq 0 ] && cmd=bash export VOLUME="$appdir:/app" From 85e104006c2829a4d9049e6abadc036f4f5eadba Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 21:30:24 +0300 Subject: [PATCH 5/8] Handle empty database password properly, don't try to run docker-compose inside the container --- Dockerfile | 5 +++-- bin/bundle | 2 +- bin/rails | 2 +- bin/rake | 2 +- bin/spring | 2 +- docker-compose.yml | 3 ++- docker-entrypoint.sh | 7 ++++++- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 77983a172..b1bcce079 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,8 @@ 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 @@ -17,8 +19,7 @@ COPY config/site.docker.yml /app/config/site.yml RUN RAILS_ENV=production bundle exec rake assets:precompile -COPY docker-entrypoint.sh / -ENTRYPOINT ["/docker-entrypoint.sh"] +ENTRYPOINT ["/app/docker-entrypoint.sh"] EXPOSE 3000 diff --git a/bin/bundle b/bin/bundle index e3b1daa19..f7b07eed9 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,6 +1,6 @@ #!/usr/bin/env ruby if File.exist?("#{__dir__}/../.use-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") end ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 4ed2026f9..e2afa025a 100755 --- a/bin/rails +++ b/bin/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby if File.exist?("#{__dir__}/../.use-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") end APP_PATH = File.expand_path('../config/application', __dir__) diff --git a/bin/rake b/bin/rake index e68ed28a7..c9e1ee4c5 100755 --- a/bin/rake +++ b/bin/rake @@ -1,6 +1,6 @@ #!/usr/bin/env ruby if File.exist?("#{__dir__}/../.use-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") end require_relative '../config/boot' require 'rake' diff --git a/bin/spring b/bin/spring index a036d6b45..4feabfe47 100755 --- a/bin/spring +++ b/bin/spring @@ -1,6 +1,6 @@ #!/usr/bin/env ruby if File.exist?("#{__dir__}/../.use-docker") - exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") end # This file loads spring without using Bundler, in order to be fast diff --git a/docker-compose.yml b/docker-compose.yml index 55a832ec6..c2b45a1fe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,8 +11,9 @@ services: build: . environment: DATABASE_USERNAME: root + DATABASE_PASSWORD_EMPTY: 1 volumes: - - ${VOLUME:-.:/app} + - ${VOLUME:-.:/app}:Z ports: - 3000:3000 depends_on: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 689318450..12fe92435 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,7 +5,12 @@ export DATABASE_NAME=${DATABASE_NAME:-tracks} export DATABASE_HOST=${DATABASE_HOST:-db} export DATABASE_PORT=${DATABASE_PORT:-3306} export DATABASE_USERNAME=${DATABASE_USERNAME:-tracks} -export DATABASE_PASSWORD=${DATABASE_PASSWORD:-password} +if [ "$DATABASE_PASSWORD_EMPTY" != 1 ]; +then + export DATABASE_PASSWORD=${DATABASE_PASSWORD:-password} +else + export DATABASE_PASSWORD="" +fi export DATABASE_TYPE=${DATABASE_TYPE:-mysql2} export DATABASE_ENCODING=${DATABASE_ENCODING:-utf8} From 869bf2a9fdd7b08bc9c4a1b9f86396c65ccedaf0 Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 21:44:43 +0300 Subject: [PATCH 6/8] Mount the mandatory config files separately in docker-compose, since it's including the whole /app from host and therefore the copies made in Dockerfile aren't available. --- docker-compose.yml | 4 +++- script/docker-environment | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c2b45a1fe..e6c33269e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,9 @@ services: DATABASE_USERNAME: root DATABASE_PASSWORD_EMPTY: 1 volumes: - - ${VOLUME:-.:/app}:Z + - ${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: diff --git a/script/docker-environment b/script/docker-environment index 8df83c1b8..71e34f196 100755 --- a/script/docker-environment +++ b/script/docker-environment @@ -2,12 +2,14 @@ set -e +echo "Doing it here" + # Find our app dir appdir=$(cd $(dirname "$0")/.. && pwd) # Check if we've been told to run the command in Docker Composer. cmd="$@"; [ "$#" -eq 0 ] && cmd=bash -export VOLUME="$appdir:/app" +export VOLUME="$appdir" image=${DOCKER_IMAGE:=web} port_publish=""; [ "${BIND_DOCKER_SERVICE_PORTS:-}" = 1 ] && port_publish="--service-ports" From b2ede09fe6c71da135c8e888e1939d5d2f48f8a5 Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 21:50:35 +0300 Subject: [PATCH 7/8] Remove unnecessary debug output --- script/docker-environment | 2 -- 1 file changed, 2 deletions(-) diff --git a/script/docker-environment b/script/docker-environment index 71e34f196..d5319e06f 100755 --- a/script/docker-environment +++ b/script/docker-environment @@ -2,8 +2,6 @@ set -e -echo "Doing it here" - # Find our app dir appdir=$(cd $(dirname "$0")/.. && pwd) From 5bb723329bdf7c7c02044503658cdc7692caf131 Mon Sep 17 00:00:00 2001 From: Jyri-Petteri Paloposki Date: Sun, 19 Jul 2020 22:04:45 +0300 Subject: [PATCH 8/8] Few more settings in order for the CI test automation --- docker-compose.yml | 3 +++ script/cibuild | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e6c33269e..008724631 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,9 @@ services: web: build: . 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: diff --git a/script/cibuild b/script/cibuild index af04b27a1..52a870d6a 100755 --- a/script/cibuild +++ b/script/cibuild @@ -12,14 +12,10 @@ function die() { exit 1 } - trap cleanup EXIT export RAILS_ENV=test -export TRACKS_DB=tracks_test - -# Put a config/site.yml file in place since it's needed for operation -cp config/site.yml.tmpl config/site.yml +export DATABASE_NAME=tracks_test $docker_compose build $docker_compose up -d