diff --git a/.ruby-version b/.ruby-version index a603bb50a..49cdd668e 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.5 +2.7.6 diff --git a/Dockerfile b/Dockerfile index b4ae85464..a0b3d8d61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,21 @@ # Use the official Ruby image because the Rails images have been deprecated -FROM ruby:2.7.5 +FROM ruby:2.7.6 -RUN apt-get update \ - && apt-get install -y --no-install-recommends postgresql-client \ - && rm -rf /var/lib/apt/lists/* - -RUN mkdir /usr/local/node \ - && curl -L https://nodejs.org/dist/v4.4.7/node-v4.4.7-linux-x64.tar.xz | tar Jx -C /usr/local/node --strip-components=1 -RUN ln -s ../node/bin/node /usr/local/bin/ +RUN apt-get update -qq && apt-get install -y nodejs postgresql-client WORKDIR /ohana-api -COPY Gemfile /ohana-api -COPY Gemfile.lock /ohana-api +COPY Gemfile /ohana-api/Gemfile +COPY Gemfile.lock /ohana-api/Gemfile.lock RUN gem install bundler RUN bundle install --jobs 20 --retry 5 --without production +COPY entrypoint.sh /usr/bin/ +RUN chmod +x /usr/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] +EXPOSE 8080 + COPY . /ohana-api -EXPOSE 8080 CMD ["rails", "server", "-b", "0.0.0.0", "-p", "8080"] diff --git a/Gemfile b/Gemfile index e6a021f84..71a15b787 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.7.5' +ruby '2.7.6' gem 'active_model_serializers', '~> 0.8.0' gem 'ancestry' gem 'auto_strip_attributes', '~> 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index ebbfa7c41..5530e645e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -455,7 +455,7 @@ DEPENDENCIES webmock RUBY VERSION - ruby 2.7.5p203 + ruby 2.7.6p219 BUNDLED WITH 2.2.17 diff --git a/config/database.yml b/config/database.yml index 1086703da..94c67c500 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,7 +1,7 @@ default: &default adapter: postgresql encoding: utf8 - host: localhost + host: <%= ENV['DOCKER_DB_HOST'] || 'localhost' %> port: 5432 pool: <%= ENV['DB_POOL'] || ENV['MAX_THREADS'] || 5 %> url: <%= ENV['DATABASE_URL'] %> @@ -10,6 +10,7 @@ default: &default development: <<: *default database: ohana_api_development + password: password # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -17,6 +18,7 @@ development: test: <<: *default database: ohana_api_test + password: password production: pool: <%= ENV['DB_POOL'] || ENV['MAX_THREADS'] || 5 %> diff --git a/docker-compose.yml b/docker-compose.yml index 0acf94008..7f419cff4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,20 @@ -version: '2' +version: "3.9" services: + db: + image: postgres + volumes: + - ./tmp/db:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: password web: build: . + command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 8080 -b '0.0.0.0'" volumes: - .:/ohana-api ports: - "8080:8080" environment: DATABASE_URL: "postgres://postgres@db" + DOCKER_DB_HOST: 'db' depends_on: - db - db: - image: postgres diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 000000000..3af18f749 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Remove a potentially pre-existing server.pid for Rails. +rm -f /myapp/tmp/pids/server.pid + +# Then exec the container's main process (what's set as CMD in the Dockerfile). +exec "$@" diff --git a/foo.txt b/foo.txt new file mode 100644 index 000000000..e69de29bb diff --git a/script/bootstrap b/script/bootstrap index 268c4f522..351f4a5cc 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -8,9 +8,7 @@ echo "===> Building the Docker image..." docker-compose build echo "===> Setting up the database on the Docker image..." -docker-compose run --rm web bundle exec rake db:reset RAILS_ENV=development -docker-compose run --rm web bundle exec rails db:environment:set RAILS_ENV=test -docker-compose run --rm web bundle exec rake db:reset RAILS_ENV=test +docker-compose run --rm web bundle exec rake db:create docker-compose run --rm web pg_restore -c --no-owner -d ohana_api_development /ohana-api/data/ohana_api_development.dump -U postgres -h db echo "===> Starting the Docker image..."