Skip to content

Instantly share code, notes, and snippets.

@filipecrosk
Last active September 4, 2015 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipecrosk/ce4a1aeae7a2b845a9bb to your computer and use it in GitHub Desktop.
Save filipecrosk/ce4a1aeae7a2b845a9bb to your computer and use it in GitHub Desktop.
Ember-cli deploy with Gulp + Nginx + Ubuntu 14.04
//ember-app-root/app/adapters/application.js
import DS from 'ember-data';
import ENV from '../config/environment';
export default DS.ActiveModelAdapter.extend({
namespace: ENV.apiNamespace
});
//ember-app-root/config/environment.js
/* jshint node: true */
module.exports = function(environment) {
var ENV = {
modulePrefix: 'app',
environment: environment,
baseURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
};
if (environment === 'development') {
ENV.apiHost = 'http://localhost:3000';
ENV.apiNamespace = "";
}
if (environment === 'test') {
ENV.apiHost = "http://localhost:3000";
ENV.apiNamespace = "";
}
if (environment === 'production') {
ENV.apiHost = "https://api.example.com";
ENV.apiNamespace = "api/v1";
}
return ENV;
};
//ember-app-root/gulpfile.js
'use strict';
var gulp = require('gulp');
var shell = require('gulp-shell');
var GulpSSH = require('gulp-ssh');
var scp = require('gulp-scp2');
// Build the project using ember-cli
gulp.task('build', shell.task([
'ember build --prod'
]));
var gulpSSH = new GulpSSH({
ignoreErrors: false,
sshConfig: {
host: "yourip or hostname",
username: "deploy",
dest: "/var/www/path/to/your/ember/app",
privateKey: require('fs').readFileSync("/local/path/to/your/privateKey/.ssh/id_rsa"),
}
});
// Delete the dist directory
gulp.task('clean', function() {
return gulpSSH
.shell(['cd /var/www/path/to/your/ember/app', 'rm -rf *'], '')
.pipe(gulp.dest('logs'))
});
gulp.task('deploy:files', function (){
return gulp.src('dist/**/*', {cwd: __dirname})
.pipe(scp({
host: "yourip or hostname",
username: "deploy",
dest: "/var/www/path/to/your/ember/app",
privateKey: require('fs').readFileSync("/local/path/to/your/privateKey/.ssh/id_rsa"),
}))
.on('error', function(err) {
console.log(err);
});
});
// Combine all these tasks into the deploy task
gulp.task('deploy', ['build', 'deploy:assets', 'deploy:index']);
#Put this file on server in the path: /etc/nginx/sites-enabled/
server {
ssl on;
listen 443 ssl;
ssl_certificate /example-cert.crt;
ssl_certificate_key /example-cert.key;
server_name example.com;
root /var/www/path/to/your/ember/app;
location / {
rewrite ^ /index.html break;
}
location ~ ^/(assets|images|javascripts|stylesheets|fonts|wfs|system)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
location /api/v1 {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass https://api.example.com/;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment