Skip to content

Commit

Permalink
Docker improve rebased (#450)
Browse files Browse the repository at this point in the history
* Shortening docker image in ~30%

* Caching bundle, gathering env variables and using newer sintax

* Creating startup script and env file

* Improving travis CI configuration

* Loading assets in production env

* Allow uglifier to interpret ES6

* Don't dettach when building container in travis

* Fix start command

* Fix travis script

* Try to resolve travis tests invocation

* Tweak travis script

* Add delay

* Bundle install before db setup

* Shortening docker image in ~30%

* Caching bundle, gathering env variables and using newer sintax

* Creating startup script and env file

* Improving travis CI configuration

* Loading assets in production env

* Allow uglifier to interpret ES6

* Fix start command

* Fix travis script

* Tweak travis script

* Add delay

* Revert assets changes

* Return to Mysql5.7

* Tweak travis script

* Fix make redeploy-container command

* Add db migrate and precompile step.

* Add bower install to Makefile

* Clean after docker run. Avoid one bower run.
  • Loading branch information
icarito authored Mar 25, 2019
1 parent a35a30b commit 8787224
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 39 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ install:
- cp config/database.yml.example config/database.yml
- cp config/config.yml.example config/config.yml
- cp db/schema.rb.example db/schema.rb
- docker-compose build
- docker-compose run web bash -l -c "sleep 10"
- docker-compose run web bash -l -c "rake db:setup"
- docker-compose run web bash -l -c "rake db:migrate"
- docker-compose run web bower install --allow-root
- docker-compose up -d --build
- docker-compose exec web bash -l -c "sleep 10"
- docker-compose exec web bash -l -c "bundle install"
- docker-compose exec web bash -l -c "rake db:setup || rake db:migrate"

script:
- sed -ri "s/REPO_TOKEN/$REPO_TOKEN/" .coveralls.yml
- docker-compose run web bash -l -c "CI=true TRAVIS=true rake test"
- docker-compose exec web bash -l -c "CI=true TRAVIS=true rake test"
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Dockerfile # Mapknitter
# https://github.com/publiclab/mapknitter/
# This image deploys Mapknitter!

FROM debian:buster
LABEL This image deploys Mapknitter!

# Set correct environment variables.
RUN mkdir -p /app
ENV HOME /root

# Install dependencies
Expand Down Expand Up @@ -40,5 +39,8 @@ RUN sed -i "s/ LONG_PASSWORD |//g" /usr/local/rvm/gems/ruby-*/gems/mysql2-*/lib/

# Add the Rails app
WORKDIR /app
ADD . /app
RUN bower install --allow-root
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
COPY start.sh /app/start.sh

CMD [ "bash", "-l", "start.sh" ]
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ build:
cp config/database.yml.example config/database.yml
cp db/schema.rb.example db/schema.rb
docker-compose build
docker-compose run web bash -l -c "sleep 10 && rake db:setup && rake db:migrate && rake assets:precompile"
docker-compose run --rm web bash -l -c "sleep 10 && bower install --allow-root && rake db:setup && rake db:migrate && rake assets:precompile"

deploy-container:
docker-compose up -d

redeploy-container:
docker-compose up --force-create -d
docker-compose up --force-recreate -d
docker-compose exec web bash -l -c "sleep 10 && rake db:migrate && rake assets:precompile"
2 changes: 0 additions & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
//= require leaflet-providers/leaflet-providers.js
//= require leaflet-toolbar/dist/leaflet.toolbar.js
//= require leaflet-distortableimage/dist/leaflet.distortableimage.js
//= require leaflet-easybutton/src/easy-button.js
//= require leaflet-google/index.js
//= require sparklines/source/sparkline.js
//= require annotations-legacy.js
//= require glfx-js/dist/glfx.js
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//= require knitter
//= require exif-js/exif.js
//= require mapknitter
//= require seiyria-bootstrap-slider/dist/bootstrap-slider.min.js

/* Move navbar links into dropdown if nav is inside the sidebar. */
jQuery(document).ready(function($) {
Expand Down
1 change: 0 additions & 1 deletion app/assets/stylesheets/maps.css.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
*= require seiyria-bootstrap-slider/dist/css/bootstrap-slider.min.css
*= require jquery-ui/themes/overcast/jquery-ui.min.css
*/
/* Variables */
Expand Down
10 changes: 7 additions & 3 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'uglifier'

Mapknitter::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

Expand All @@ -9,13 +11,15 @@
config.action_controller.perform_caching = true

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
config.serve_static_assets = true

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
config.assets.compile = true

config.assets.js_compressor = Uglifier.new(:harmony => true)

# Generate digests for assets URLs
config.assets.digest = true
Expand All @@ -38,7 +42,7 @@
# config.force_ssl = true

# See everything in the log (default is :info)
# config.log_level = :debug
config.log_level = :debug

# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
Expand Down
46 changes: 26 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
db:
image: mysql:5.7
environment:
- MYSQL_DATABASE=mapknitter
- MYSQL_USER=mapknitter
- MYSQL_PASSWORD=mapknitter
- MYSQL_RANDOM_ROOT_PASSWORD=true
volumes:
- ../mysql:/var/lib/mysql
web:
build: .
command: ./start.sh
environment:
- RAILS_ENV=production
volumes:
- ./:/app
ports:
- "127.0.0.1:3000:3000"
links:
- db
version: '3.3'
services:
db:
container_name: db
image: mysql:5.7
env_file:
- mapknitter.env
volumes:
- ../mysql:/var/lib/mysql
web:
container_name: web
build: .
env_file:
- mapknitter.env
volumes:
- .:/app
- bundle_cache:/usr/local/bundle
- bower_cache:/app/public/lib
ports:
- 3000:3000
depends_on:
- db

volumes:
bundle_cache:
bower_cache:
5 changes: 5 additions & 0 deletions mapknitter.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MYSQL_DATABASE=mapknitter
MYSQL_USER=mapknitter
MYSQL_PASSWORD=mapknitter
MYSQL_RANDOM_ROOT_PASSWORD=true
RAILS_ENV=production

0 comments on commit 8787224

Please sign in to comment.