Skip to content

Commit fc18f35

Browse files
authored
Merge pull request #1 from calh/docker-dev-system
Docker dev system
2 parents 43c367e + 8e2671d commit fc18f35

File tree

14 files changed

+291
-86
lines changed

14 files changed

+291
-86
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.gem
2+
*.sqlite3
3+
.bundle
4+
.rvmrc
5+
.ruby-version
6+
Gemfile.lock
7+
gemfiles/*.lock
8+
pkg/*
9+
*.rbc
10+
tmp/*
11+
.*.sw[a-z]
12+
database.log

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM ruby:2.5
2+
3+
RUN apt-get update && apt-get install -y \
4+
mysql-client \
5+
postgresql
6+
7+
WORKDIR /usr/src/app
8+
9+
# Pull in a full profile for gem/bundler
10+
SHELL ["/bin/bash", "-l", "-c"]
11+
12+
RUN gem install --no-document bundler -v 1.16.6
13+
14+
# Copy only what's needed for bundler
15+
COPY Gemfile ar-octopus.gemspec /usr/src/app/
16+
COPY lib/octopus/version.rb /usr/src/app/lib/octopus/version.rb
17+
18+
RUN bundle install --path=.bundle
19+
20+
# Uncomment if you want to copy the octopus repo
21+
# into the Docker image itself. docker-compose is
22+
# set up to use a bind mount of your local directory
23+
# from the host
24+
#COPY . /usr/src/app
25+
26+
# This just keeps the container running. Replace
27+
# this with a rails server if you want
28+
CMD ["/bin/sleep", "infinity"]

README.mkdn

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,47 @@ bundle install
229229
cucumber
230230
```
231231

232+
### Using Docker Compose
233+
234+
For a more consistent build/test/development environment, use [Docker Compose](https://docs.docker.com/compose/install/).
235+
236+
```bash
237+
[me@host octopus]$ docker-compose -f docker-compose.yml up
238+
Creating network "octopus_default" with the default driver
239+
Creating octopus_postgres_1 ...
240+
Creating octopus_mysql_1 ...
241+
Creating octopus_postgres_1
242+
. . .
243+
octopus_1 | mysqld is alive
244+
octopus_1 | MySQL is ready
245+
octopus_1 | + bundle exec rake db:prepare
246+
. . .
247+
octopus_1 | + bundle exec rake spec
248+
. . .
249+
octopus_1 | Finished in 7 minutes 44 seconds (files took 0.71416 seconds to load)
250+
octopus_1 | 359 examples, 0 failures, 2 pending
251+
252+
(Ctrl+C to shut down the stack)
253+
```
254+
255+
Your workstation's octopus clone is mounted inside the docker container, so
256+
you may still use your favorite development tools. The `octopus_1` container
257+
is available for re-running the test suite. To start a new shell in another
258+
terminal, run:
259+
260+
```bash
261+
[me@host octopus]$ docker-compose exec octopus /bin/bash
262+
root@f6ae68df6fc8:/usr/src/app#
263+
# run bundle exec rake spec again
264+
```
265+
266+
To completely destory the stack and start over:
267+
268+
```bash
269+
[me@host octopus]$ docker-compose -f docker-compose.yml down
270+
[me@host octopus]$ docker-compose -f docker-compose.yml up
271+
```
272+
232273
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.
233274

234275
## Contributors:

Rakefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ namespace :db do
1313
task :build_databases do
1414
pg_spec = {
1515
:adapter => 'postgresql',
16-
:host => 'localhost',
16+
:host => (ENV['POSTGRES_HOST'] || ''),
1717
:username => (ENV['POSTGRES_USER'] || 'postgres'),
18+
:password => (ENV['POSTGRES_PASSWORD'] || ''),
1819
:encoding => 'utf8',
1920
}
2021

2122
mysql_spec = {
2223
:adapter => 'mysql2',
23-
:host => 'localhost',
24+
:host => (ENV['MYSQL_HOST'] || ''),
2425
:username => (ENV['MYSQL_USER'] || 'root'),
26+
:password => (ENV['MYSQL_PASSWORD'] || ''),
2527
:encoding => 'utf8',
2628
}
2729

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

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

docker-compose.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: '3'
2+
3+
services:
4+
octopus:
5+
build: .
6+
# Your local clone binds to /usr/src/app
7+
volumes:
8+
- .:/usr/src/app
9+
environment:
10+
POSTGRES_HOST: postgres # image name below
11+
POSTGRES_USER: postgres
12+
POSTGRES_PASSWORD: testpassword # password below
13+
MYSQL_HOST: mysql
14+
MYSQL_USER: root
15+
MYSQL_PASSWORD: testpassword
16+
depends_on:
17+
- mysql
18+
- postgres
19+
# Wait for databases to start up, run test suite
20+
command: ./docker/startup.sh
21+
mysql:
22+
image: mysql:8
23+
command: --default-authentication-plugin=mysql_native_password
24+
restart: always
25+
environment:
26+
MYSQL_ROOT_PASSWORD: testpassword
27+
healthcheck:
28+
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
29+
interval: 10s
30+
timeout: 20s
31+
retries: 5
32+
postgres:
33+
image: postgres:11
34+
restart: always
35+
environment:
36+
POSTGRES_PASSWORD: testpassword
37+
healthcheck:
38+
test: ["CMD-SHELL", "pg_isready -U postgres"]
39+
interval: 10s
40+
timeout: 5s
41+
retries: 5

docker/startup.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Wait for our two databases to startup
6+
# (docker-compose v3 removes the health check stuff)
7+
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -c '\q'; do
8+
>&2 echo "Postgres is unavailable - sleeping"
9+
sleep 10
10+
done
11+
12+
>&2 echo "Postgres is ready"
13+
14+
until mysqladmin -u$MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD ping; do
15+
>&2 echo "MySQL is unavailable - sleeping"
16+
sleep 10
17+
done
18+
19+
>&2 echo "MySQL is ready"
20+
21+
set -x
22+
bundle install
23+
bundle exec rake db:prepare
24+
bundle exec rake appraisal:install
25+
bundle exec rake spec
26+
#Not working yet
27+
#./sample_app/script/ci_build
28+
set +x
29+
echo Octopus is ready for you. Run \"docker-compose exec octopus /bin/bash\"
30+
/bin/sleep infinity

sample_app/Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ gem 'rails', '3.2.13'
55
# Bundle edge Rails instead:
66
# gem 'rails', :git => 'git://github.com/rails/rails.git'
77

8-
gem 'pg'
9-
gem 'sqlite3'
8+
gem 'pg', '~> 0.11'
9+
gem 'sqlite3', '~> 1.3.5'
1010
gem 'ar-octopus', '0.6.0'
1111
gem 'pry'
12+
gem 'json', '~> 1.8.6'
1213

1314
group :test do
1415
gem 'capybara'

0 commit comments

Comments
 (0)