Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker dev system #1

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.gem
*.sqlite3
.bundle
.rvmrc
.ruby-version
Gemfile.lock
gemfiles/*.lock
pkg/*
*.rbc
tmp/*
.*.sw[a-z]
database.log
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ruby:2.5

RUN apt-get update && apt-get install -y \
mysql-client \
postgresql

WORKDIR /usr/src/app

# Pull in a full profile for gem/bundler
SHELL ["/bin/bash", "-l", "-c"]

RUN gem install --no-document bundler -v 1.16.6

# Copy only what's needed for bundler
COPY Gemfile ar-octopus.gemspec /usr/src/app/
COPY lib/octopus/version.rb /usr/src/app/lib/octopus/version.rb

RUN bundle install --path=.bundle

# Uncomment if you want to copy the octopus repo
# into the Docker image itself. docker-compose is
# set up to use a bind mount of your local directory
# from the host
#COPY . /usr/src/app

# This just keeps the container running. Replace
# this with a rails server if you want
CMD ["/bin/sleep", "infinity"]
41 changes: 41 additions & 0 deletions README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,47 @@ bundle install
cucumber
```

### Using Docker Compose

For a more consistent build/test/development environment, use [Docker Compose](https://docs.docker.com/compose/install/).

```bash
[me@host octopus]$ docker-compose -f docker-compose.yml up
Creating network "octopus_default" with the default driver
Creating octopus_postgres_1 ...
Creating octopus_mysql_1 ...
Creating octopus_postgres_1
. . .
octopus_1 | mysqld is alive
octopus_1 | MySQL is ready
octopus_1 | + bundle exec rake db:prepare
. . .
octopus_1 | + bundle exec rake spec
. . .
octopus_1 | Finished in 7 minutes 44 seconds (files took 0.71416 seconds to load)
octopus_1 | 359 examples, 0 failures, 2 pending

(Ctrl+C to shut down the stack)
```

Your workstation's octopus clone is mounted inside the docker container, so
you may still use your favorite development tools. The `octopus_1` container
is available for re-running the test suite. To start a new shell in another
terminal, run:

```bash
[me@host octopus]$ docker-compose exec octopus /bin/bash
root@f6ae68df6fc8:/usr/src/app#
# run bundle exec rake spec again
```

To completely destory the stack and start over:

```bash
[me@host octopus]$ docker-compose -f docker-compose.yml down
[me@host octopus]$ docker-compose -f docker-compose.yml up
```

If you are having issues running the octopus spec suite, verify your database users and passwords match those inside the config files and your permissions are correct.

## Contributors:
Expand Down
7 changes: 5 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ namespace :db do
task :build_databases do
pg_spec = {
:adapter => 'postgresql',
:host => 'localhost',
:host => (ENV['POSTGRES_HOST'] || ''),
:username => (ENV['POSTGRES_USER'] || 'postgres'),
:password => (ENV['POSTGRES_PASSWORD'] || ''),
:encoding => 'utf8',
}

mysql_spec = {
:adapter => 'mysql2',
:host => 'localhost',
:host => (ENV['MYSQL_HOST'] || ''),
:username => (ENV['MYSQL_USER'] || 'root'),
:password => (ENV['MYSQL_PASSWORD'] || ''),
:encoding => 'utf8',
}

Expand Down Expand Up @@ -64,6 +66,7 @@ namespace :db do
# the model be a descendent of ActiveRecord::Base.
class BlankModel < ActiveRecord::Base; end

puts "Preparing shard #{shard_symbol}"
BlankModel.using(shard_symbol).connection.initialize_schema_migrations_table
BlankModel.using(shard_symbol).connection.initialize_metadata_table if Octopus.atleast_rails50?

Expand Down
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3'

services:
octopus:
build: .
# Your local clone binds to /usr/src/app
volumes:
- .:/usr/src/app
environment:
POSTGRES_HOST: postgres # image name below
POSTGRES_USER: postgres
POSTGRES_PASSWORD: testpassword # password below
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: testpassword
depends_on:
- mysql
- postgres
# Wait for databases to start up, run test suite
command: ./docker/startup.sh
mysql:
image: mysql:8
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: testpassword
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 10s
timeout: 20s
retries: 5
postgres:
image: postgres:11
restart: always
environment:
POSTGRES_PASSWORD: testpassword
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
30 changes: 30 additions & 0 deletions docker/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -e

# Wait for our two databases to startup
# (docker-compose v3 removes the health check stuff)
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 10
done

>&2 echo "Postgres is ready"

until mysqladmin -u$MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD ping; do
>&2 echo "MySQL is unavailable - sleeping"
sleep 10
done

>&2 echo "MySQL is ready"

set -x
bundle install
bundle exec rake db:prepare
bundle exec rake appraisal:install
bundle exec rake spec
#Not working yet
#./sample_app/script/ci_build
set +x
echo Octopus is ready for you. Run \"docker-compose exec octopus /bin/bash\"
/bin/sleep infinity
5 changes: 3 additions & 2 deletions sample_app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ gem 'rails', '3.2.13'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'sqlite3'
gem 'pg', '~> 0.11'
gem 'sqlite3', '~> 1.3.5'
gem 'ar-octopus', '0.6.0'
gem 'pry'
gem 'json', '~> 1.8.6'

group :test do
gem 'capybara'
Expand Down
Loading