mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
Merge pull request #2103 from TracksApp/update-docker-configuration
Update the docker configuration
This commit is contained in:
commit
a4476ae74a
15 changed files with 194 additions and 54 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -19,7 +19,6 @@
|
||||||
/log/*.log
|
/log/*.log
|
||||||
/public/assets/
|
/public/assets/
|
||||||
/tmp
|
/tmp
|
||||||
config/database.yml
|
|
||||||
config/deploy.rb
|
config/deploy.rb
|
||||||
config/site.yml
|
config/site.yml
|
||||||
db/data.yml
|
db/data.yml
|
||||||
|
|
|
||||||
33
.travis.yml
33
.travis.yml
|
|
@ -1,22 +1,19 @@
|
||||||
language: ruby
|
sudo: true
|
||||||
sudo: false
|
services:
|
||||||
cache: bundler
|
- docker
|
||||||
rvm:
|
|
||||||
- 1.9.3
|
|
||||||
- 2.0.0
|
|
||||||
- 2.1
|
|
||||||
- 2.2
|
|
||||||
addons:
|
|
||||||
firefox: 45.8.0esr
|
|
||||||
env:
|
env:
|
||||||
- DATABASE_URL=mysql2://localhost/tracks_test
|
- DOCKER_COMPOSE_VERSION=1.21.0
|
||||||
- DATABASE_URL=sqlite3:db/test.sqlite3
|
before_install:
|
||||||
bundler_args: --without development --jobs=3 --retry=3
|
- sudo rm /usr/local/bin/docker-compose
|
||||||
before_script:
|
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
|
||||||
- "export DISPLAY=:99.0"
|
- chmod 0755 docker-compose
|
||||||
- "sh -e /etc/init.d/xvfb start"
|
- sudo mv docker-compose /usr/local/bin
|
||||||
- "cp config/site.yml.tmpl config/site.yml"
|
install: true
|
||||||
script: "if [[ $DATABASE_URL == mysql* ]]; then bundle exec rake ci:full; else bundle exec rake ci:lite; fi"
|
script: "script/cibuild"
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- docker-ce
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
irc:
|
irc:
|
||||||
|
|
|
||||||
43
Dockerfile
43
Dockerfile
|
|
@ -1,41 +1,14 @@
|
||||||
FROM phusion/passenger-ruby22:0.9.18
|
FROM ruby:2.3
|
||||||
|
|
||||||
WORKDIR /home/app/tracks
|
WORKDIR /app
|
||||||
|
|
||||||
# Install gems
|
RUN touch /etc/app-env
|
||||||
COPY Gemfile Gemfile.lock ./
|
|
||||||
RUN bundle install --without development test mysql therubyracer --jobs=3
|
|
||||||
|
|
||||||
# Install and configure the app
|
COPY Gemfile* /app/
|
||||||
ENV RAILS_ENV=production
|
RUN bundle install
|
||||||
ENV DATABASE_URL=sqlite3:/var/tracks/database.sqlite3
|
|
||||||
RUN mkdir /var/tracks && chmod 777 /var/tracks
|
|
||||||
RUN touch /var/tracks/database.sqlite3 && chown app.app /var/tracks/database.sqlite3
|
|
||||||
COPY . ./
|
|
||||||
COPY config/site.yml.tmpl /etc/tracks/config/site.yml
|
|
||||||
RUN ln -sf /etc/tracks/config/site.yml config/site.yml
|
|
||||||
RUN bundle exec rake assets:precompile
|
|
||||||
RUN chown -R app.app .
|
|
||||||
|
|
||||||
# Configure nginx
|
RUN mkdir /app/log
|
||||||
RUN echo "env DATABASE_URL;" > /etc/nginx/main.d/env.conf
|
|
||||||
RUN echo "\
|
|
||||||
server {\n\
|
|
||||||
listen 80 default_server;\n\
|
|
||||||
server_name _;\n\
|
|
||||||
root /home/app/tracks/public;\n\
|
|
||||||
passenger_enabled on;\n\
|
|
||||||
passenger_user app;\n\
|
|
||||||
passenger_ruby /usr/bin/ruby2.2;\n\
|
|
||||||
}" > /etc/nginx/sites-enabled/tracks.conf
|
|
||||||
RUN rm /etc/nginx/sites-enabled/default
|
|
||||||
RUN rm -f /etc/service/nginx/down
|
|
||||||
|
|
||||||
# Migrate the database on startup
|
COPY . /app/
|
||||||
RUN echo "#!/bin/sh\nbundle exec rake db:migrate" > /etc/my_init.d/90_tracks.sh
|
|
||||||
RUN chmod +x /etc/my_init.d/90_tracks.sh
|
|
||||||
|
|
||||||
VOLUME ["/etc/tracks", "/var/tracks"]
|
EXPOSE 3000
|
||||||
|
|
||||||
# Default command for baseimage-docker
|
|
||||||
CMD ["/sbin/my_init"]
|
|
||||||
|
|
|
||||||
41
Dockerfile.passenger
Normal file
41
Dockerfile.passenger
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
FROM phusion/passenger-ruby22:0.9.18
|
||||||
|
|
||||||
|
WORKDIR /home/app/tracks
|
||||||
|
|
||||||
|
# Install gems
|
||||||
|
COPY Gemfile Gemfile.lock ./
|
||||||
|
RUN bundle install --without development test mysql therubyracer --jobs=3
|
||||||
|
|
||||||
|
# Install and configure the app
|
||||||
|
ENV RAILS_ENV=production
|
||||||
|
ENV DATABASE_URL=sqlite3:/var/tracks/database.sqlite3
|
||||||
|
RUN mkdir /var/tracks && chmod 777 /var/tracks
|
||||||
|
RUN touch /var/tracks/database.sqlite3 && chown app.app /var/tracks/database.sqlite3
|
||||||
|
COPY . ./
|
||||||
|
COPY config/site.yml.tmpl /etc/tracks/config/site.yml
|
||||||
|
RUN ln -sf /etc/tracks/config/site.yml config/site.yml
|
||||||
|
RUN bundle exec rake assets:precompile
|
||||||
|
RUN chown -R app.app .
|
||||||
|
|
||||||
|
# Configure nginx
|
||||||
|
RUN echo "env DATABASE_URL;" > /etc/nginx/main.d/env.conf
|
||||||
|
RUN echo "\
|
||||||
|
server {\n\
|
||||||
|
listen 80 default_server;\n\
|
||||||
|
server_name _;\n\
|
||||||
|
root /home/app/tracks/public;\n\
|
||||||
|
passenger_enabled on;\n\
|
||||||
|
passenger_user app;\n\
|
||||||
|
passenger_ruby /usr/bin/ruby2.2;\n\
|
||||||
|
}" > /etc/nginx/sites-enabled/tracks.conf
|
||||||
|
RUN rm /etc/nginx/sites-enabled/default
|
||||||
|
RUN rm -f /etc/service/nginx/down
|
||||||
|
|
||||||
|
# Migrate the database on startup
|
||||||
|
RUN echo "#!/bin/sh\nbundle exec rake db:migrate" > /etc/my_init.d/90_tracks.sh
|
||||||
|
RUN chmod +x /etc/my_init.d/90_tracks.sh
|
||||||
|
|
||||||
|
VOLUME ["/etc/tracks", "/var/tracks"]
|
||||||
|
|
||||||
|
# Default command for baseimage-docker
|
||||||
|
CMD ["/sbin/my_init"]
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
if ENV["RAILS_ENV"] != "production"
|
||||||
|
exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env")
|
||||||
|
end
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
||||||
load Gem.bin_path('bundler', 'bundle')
|
load Gem.bin_path('bundler', 'bundle')
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
if ENV["RAILS_ENV"] != "production"
|
||||||
|
exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env")
|
||||||
|
end
|
||||||
begin
|
begin
|
||||||
load File.expand_path("../spring", __FILE__)
|
load File.expand_path("../spring", __FILE__)
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
if ENV["RAILS_ENV"] != "production"
|
||||||
|
exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env")
|
||||||
|
end
|
||||||
|
|
||||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||||
require_relative '../config/boot'
|
require_relative '../config/boot'
|
||||||
require 'rails/commands'
|
require 'rails/commands'
|
||||||
|
|
|
||||||
3
bin/rake
3
bin/rake
|
|
@ -1,4 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
if ENV["RAILS_ENV"] != "production"
|
||||||
|
exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env")
|
||||||
|
end
|
||||||
require_relative '../config/boot'
|
require_relative '../config/boot'
|
||||||
require 'rake'
|
require 'rake'
|
||||||
Rake.application.run
|
Rake.application.run
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
if ENV["RAILS_ENV"] != "production"
|
||||||
|
exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env")
|
||||||
|
end
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
||||||
# path to your application root.
|
# path to your application root.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
if ENV["RAILS_ENV"] != "production"
|
||||||
|
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
|
# This file loads spring without using Bundler, in order to be fast
|
||||||
# It gets overwritten when you run the `spring binstub` command
|
# It gets overwritten when you run the `spring binstub` command
|
||||||
|
|
|
||||||
32
config/database.yml
Normal file
32
config/database.yml
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
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:
|
||||||
|
|
||||||
19
docker-compose.yml
Normal file
19
docker-compose.yml
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: mysql:5.7
|
||||||
|
environment:
|
||||||
|
MYSQL_ALLOW_EMPTY_PASSWORD: '1'
|
||||||
|
volumes:
|
||||||
|
- "db-data:/var/lib/mysql"
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
volumes:
|
||||||
|
- "${VOLUME:-.:/app/workdir}"
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
volumes:
|
||||||
|
db-data:
|
||||||
|
|
||||||
32
script/cibuild
Executable file
32
script/cibuild
Executable file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
docker_compose="docker-compose --file docker-compose.yml"
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
$docker_compose down
|
||||||
|
}
|
||||||
|
|
||||||
|
function die() {
|
||||||
|
echo $@
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
export RAILS_ENV=test
|
||||||
|
|
||||||
|
# Put a config/site.yml file in place since it's needed for operation
|
||||||
|
cp config/site.yml.tmpl config/site.yml
|
||||||
|
|
||||||
|
$docker_compose build
|
||||||
|
$docker_compose up -d
|
||||||
|
script/poll-for-db
|
||||||
|
|
||||||
|
# Leaving this in since it will be needed for Rails 5
|
||||||
|
# bin/rails db:environment:set RAILS_ENV=test || true
|
||||||
|
|
||||||
|
bin/rake db:reset
|
||||||
|
bin/rake ci:lite
|
||||||
|
|
||||||
16
script/docker-environment
Executable file
16
script/docker-environment
Executable file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#!/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
|
||||||
|
cmd="$@"; [ "$#" -eq 0 ] && cmd=bash
|
||||||
|
export VOLUME="$appdir:/app"
|
||||||
|
image=${DOCKER_IMAGE:=web}
|
||||||
|
|
||||||
|
exec docker-compose run --rm $image $cmd
|
||||||
12
script/poll-for-db
Executable file
12
script/poll-for-db
Executable file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
appdir=$(cd $(dirname "$0")/.. && pwd)
|
||||||
|
[ -f /etc/app-env ] || exec "$appdir/script/docker-environment" $0 $@
|
||||||
|
|
||||||
|
for i in {1..60}; do
|
||||||
|
curl -sf db:3306 >/dev/null && exit
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Unable to reach database!"
|
||||||
|
exit 1
|
||||||
Loading…
Add table
Add a link
Reference in a new issue