Last active
July 12, 2019 09:27
-
-
Save getjump/7e5a87d3f4d77591e025 to your computer and use it in GitHub Desktop.
Docker + Rails + Unicorn + Nginx + Gulp + PostgreSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db: | |
| image: postgres | |
| ports: | |
| - "5432" | |
| web: | |
| build: . | |
| command: bash -c "rm -fR tmp/pids/* ; bundle exec unicorn -c config/unicorn.rb" | |
| volumes: | |
| - .:/myapp | |
| - /tmp/sockets | |
| links: | |
| - db | |
| nginx: | |
| restart: always | |
| build: ./nginx/ | |
| ports: | |
| - "80:80" | |
| volumes_from: | |
| - web | |
| links: | |
| - web:web |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ruby:2.2.0 | |
| RUN apt-get update -qq && apt-get install -y build-essential libpq-dev | |
| RUN mkdir /myapp | |
| RUN mkdir /tmp/sockets | |
| WORKDIR /myapp | |
| ADD Gemfile /myapp/Gemfile | |
| RUN bundle install | |
| ADD . /myapp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # nginx/Dockerfile | |
| # Set nginx base image | |
| FROM nginx | |
| # Copy custom configuration file from the current directory | |
| COPY nginx_sites.conf /etc/nginx/conf.d/default.conf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var gulp, sass, sourcemaps, browserify, coffeeify, source, util, watchify, _, livereload, notify, browserSync, rev; | |
| gulp = require('gulp'); | |
| util = require('gulp-util'); | |
| watchify = require('watchify'); | |
| sass = require('gulp-sass'); | |
| sourcemaps = require('gulp-sourcemaps'); | |
| browserify = require('browserify'); | |
| coffeeify = require('coffeeify'); | |
| source = require('vinyl-source-stream'); | |
| livereload = require('gulp-livereload'); | |
| _ = require('lodash'); | |
| notify = require("gulp-notify"); | |
| browserSync = require('browser-sync'); | |
| rev = require('gulp-rev'); | |
| function browserifyInstance(fileName, userOpts) { | |
| if(!userOpts) { | |
| userOpts = {}; | |
| } | |
| var defaultOpts = { | |
| extensions: ['.coffee', '.js'] | |
| }; | |
| return browserify(fileName, _.assign(defaultOpts, userOpts)) | |
| } | |
| gulp.task('browserSync', function() { | |
| browserSync({ | |
| proxy: '127.0.0.1:3000', | |
| files: ['./app/views/**'] | |
| }); | |
| }); | |
| gulp.task('watch', ['watch-styles', 'watch-coffee', 'browserSync'], function() { | |
| livereload.listen(); | |
| }); | |
| gulp.task('rev', function() { | |
| gulp.src(['public/**/*.css', 'public/**/*.js'], { base: './' }) | |
| .pipe(rev()) | |
| .pipe(gulp.dest('.')) | |
| .pipe(rev.manifest()) | |
| .pipe(gulp.dest('.')); | |
| }); | |
| gulp.task('watch-styles', function() { | |
| gulp.watch(['app/assets/stylesheets/**/*.sass', 'app/assets/stylesheets/**/*.scss'], ['compile-styles']); | |
| }); | |
| gulp.task('watch-coffee', function() { | |
| var watchBrowserify = watchify(browserifyInstance('./app/assets/javascripts/application.coffee', _.assign(watchify.args, { debug: true }))); | |
| var updateOnChange = function() { | |
| return watchBrowserify | |
| .bundle() | |
| .on('error', util.log.bind(util, 'Browserify Error')) | |
| .pipe(source('bundle.js')) | |
| .pipe(gulp.dest('public/javascripts')) | |
| .pipe(browserSync.reload({stream:true})); | |
| }; | |
| watchBrowserify | |
| .transform('coffeeify') | |
| .on('log', util.log) | |
| .on('update', updateOnChange) | |
| updateOnChange(); | |
| }); | |
| gulp.task('default', ['compile-styles', 'compile-coffee']); | |
| gulp.task('compile-styles', function() { | |
| //gulp.src('bower_components/foundation/scss/*') | |
| // .pipe(sourcemaps.init()) | |
| // .pipe(sass({ includePaths: ['bower_components/foundation/scss'] })) | |
| // .pipe(sourcemaps.write()) | |
| // .pipe(gulp.dest('public/stylesheets')); | |
| gulp.src(['app/assets/stylesheets/**/*.sass', 'app/assets/stylesheets/**/*.scss']) | |
| .pipe(sourcemaps.init()) | |
| .pipe(sass()) | |
| .pipe(sourcemaps.write()) | |
| .pipe(gulp.dest('public/stylesheets')) | |
| .pipe(livereload()) | |
| .pipe(browserSync.reload({stream:true})); | |
| }); | |
| gulp.task('compile-coffee', function() { | |
| //gulp.src('bower_components/foundation/js/**/*') | |
| // .pipe(gulp.dest('public/javascripts')); | |
| var stream = browserifyInstance('./app/assets/javascripts/application.coffee', | |
| { debug: true /* enables source maps */ } | |
| ) | |
| .transform('coffeeify') | |
| .bundle(); | |
| stream.pipe(source('bundle.js')) | |
| .pipe(gulp.dest('public/javascripts')) | |
| .pipe(livereload()); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # nginx/nginx_sites.conf | |
| upstream unicorn_server { | |
| server unix:/tmp/sockets/unicorn.sock fail_timeout=0; | |
| } | |
| server { | |
| listen 80; | |
| root /myapp/public; | |
| try_files $uri @unicorn_server; | |
| location @unicorn_server { | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header Host $http_host; | |
| #proxy_set_header X-Forwarded-Proto https; # if use ssl | |
| proxy_redirect off; | |
| proxy_pass http://unicorn_server; | |
| } | |
| location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { | |
| gzip_static on; | |
| expires max; | |
| add_header Cache-Control public; | |
| add_header Last-Modified ""; | |
| add_header ETag ""; | |
| open_file_cache max=1000 inactive=500s; | |
| open_file_cache_valid 600s; | |
| open_file_cache_errors on; | |
| break; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "yolo2", | |
| "version": "1.0.0", | |
| "description": "== README", | |
| "main": "index.js", | |
| "directories": { | |
| "test": "test" | |
| }, | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "devDependencies": { | |
| "browser-sync": "^2.9.11", | |
| "browserify": "^11.2.0", | |
| "coffeeify": "^1.1.0", | |
| "gulp": "^3.9.0", | |
| "gulp-buffer": "0.0.2", | |
| "gulp-livereload": "^3.8.1", | |
| "gulp-notify": "^2.2.0", | |
| "gulp-rev": "^6.0.1", | |
| "gulp-sass": "^2.0.4", | |
| "gulp-sourcemaps": "^1.6.0", | |
| "gulp-util": "^3.0.7", | |
| "jquery": "^2.1.4", | |
| "lodash": "^3.10.1", | |
| "vinyl-source-stream": "^1.1.0", | |
| "watchify": "^3.5.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment