Browse Source

Fix docker compose flow (#275)

* Make docker-compose actually useful

* Add docker-compose debug instructions to readme

* Add db seed for docker-compose instructions to readme

* Update readme to include migrate step

* DB connection
pull/276/head^2
baarkerlounger 3 years ago committed by GitHub
parent
commit
0db5f3a4dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Dockerfile
  2. 33
      Dockerfile_dev
  3. 4
      Gemfile.lock
  4. 28
      README.md
  5. 4
      config/database.yml
  6. 8
      docker-compose.yml

2
Dockerfile

@ -16,7 +16,7 @@ RUN apk add --no-cache build-base yarn postgresql-dev git
# Install bundler to run bundle exec
# This should be the same version as the Gemfile.lock
RUN gem install bundler:2.2.3 --no-document
RUN gem install bundler:2.3.4 --no-document
# Install gems defined in Gemfile
COPY .ruby-version Gemfile Gemfile.lock /app/

33
Dockerfile_dev

@ -0,0 +1,33 @@
# Build compilation image
FROM ruby:3.0.3-alpine3.14 as builder
# The application runs from /app
WORKDIR /app
# Add the timezone as it's not configured by default in Alpine
RUN apk add --update --no-cache tzdata && cp /usr/share/zoneinfo/Europe/London /etc/localtime && echo "Europe/London" > /etc/timezone
RUN apk add --no-cache build-base yarn postgresql-dev git bash
# Install bundler to run bundle exec
# This should be the same version as the Gemfile.lock
RUN gem install bundler:2.3.4 --no-document
# Install gems defined in Gemfile
COPY .ruby-version Gemfile Gemfile.lock /app/
ARG BUNDLE_FLAGS="--jobs=4 --no-binstubs --no-cache"
RUN bundle install ${BUNDLE_FLAGS}
# Install node packages defined in package.json, including webpack
COPY package.json yarn.lock /app/
RUN yarn install --frozen-lockfile
# Copy all files to /app (except what is defined in .dockerignore)
COPY . /app/
ENV PORT=8080
EXPOSE ${PORT}
CMD RAILS_ENV=${RAILS_ENV} bundle exec rake db:migrate && bundle exec rails s -e ${RAILS_ENV} -p ${PORT} --binding=0.0.0.0

4
Gemfile.lock

@ -8,7 +8,7 @@ GIT
GIT
remote: https://github.com/baarkerlounger/devise.git
revision: ac956cc2a58daa57e071202967a212a1dac08053
revision: 6d0b6b52a9d0e87ae6d9f9acb562169751623078
branch: dluhc-fixes
specs:
devise (4.8.1)
@ -31,7 +31,7 @@ GIT
GIT
remote: https://github.com/tagliala/activeadmin.git
revision: d1492c54e76871d95f3a7ff20e445b48f455d4cb
revision: 920f14393bcf56cea9dc155276d20bcd10f4fa85
branch: feature/railties-7
specs:
activeadmin (2.9.0)

28
README.md

@ -29,25 +29,37 @@ Pre-requisites:
4. Run the database migrations:\
`rake db:migrate`
5. Install the frontend depenencies:\
5. Seed the database if required:\
`rake db:seed`
6. Install the frontend depenencies:\
`yarn install`
6. Start the Rails server:\
7. Start the Rails server:\
`bundle exec rails s`
The Rails server will start on <http://localhost:3000>.
### Using Docker
```sh
docker-compose build
docker-compose run --rm app rails db:create
docker-compose up
```
1. Build the image:\
`docker-compose build`
2. Run the database migrations:\
`docker-compose run --rm app /bin/bash -c 'rake db:migrate'`
3. Seed the database if required:\
`docker-compose run --rm app /bin/bash -c 'rake db:seed'`
4. To be able to debug with Pry run the app using:\
`docker-compose run --service-ports app`
If this is not needed you can run `docker-compose up` as normal
The Rails server will start on <http://localhost:8080>.
Note `docker-compose` runs the production docker image (`RAILS_ENV=production`) as the Dockerfile doesn’t include development gems to keep the image size down.
## Infrastructure

4
config/database.yml

@ -28,8 +28,8 @@ default: &default
development:
<<: *default
database: data_collector_development
host: localhost
database: <%= ENV['DB_DATABASE'] || 'data_collector_development' %>
host: <%= ENV['DB_HOST'] || 'localhost' %>
staging:
<<: *default

8
docker-compose.yml

@ -5,7 +5,7 @@ volumes:
services:
db:
image: postgres:13.3-alpine
image: postgres:13.5-alpine
restart: always
# To preserve data between runs of docker-compose, we mount a folder from the host machine.
volumes:
@ -20,9 +20,7 @@ services:
app:
build:
context: .
dockerfile: ./Dockerfile
args:
GIT_COMMIT_SHA: DOCKER_COMPOSE_GIT_COMMIT_SHA
dockerfile: ./Dockerfile_dev
ports:
- 8080:8080
depends_on:
@ -32,7 +30,7 @@ services:
- DB_DATABASE=data_collector
- DB_USERNAME=postgres
- DB_PASSWORD=password
- RAILS_ENV=production
- RAILS_ENV=development
- RAILS_SERVE_STATIC_FILES=true
- RAILS_LOG_TO_STDOUT=true
- SECRET_KEY_BASE=abcd1234

Loading…
Cancel
Save