Skip to content

Instantly share code, notes, and snippets.

@kmassada
Last active February 8, 2018 12:22
Show Gist options
  • Save kmassada/cbb64ce81aba8a366be1 to your computer and use it in GitHub Desktop.
Save kmassada/cbb64ce81aba8a366be1 to your computer and use it in GitHub Desktop.
My GHOST BLOG workflow

STRUCTURE

  • we try out best to separate ghost/ from our application
  • depending on prod/dev ghost/ is git, or latest zip
  • Prod is started using pm2.
.
├── Capfile                        #cap task management 
├── README.md
├── app
│   ├── config.js
│   └── content                    #blog content
│       ├── apps
│       │   └── README.md
│       ├── data
│       │   ├── README.md
│       │   └── ghost-dev.db
│       ├── images
│       │   ├── 2015
│       │   └── README.md
│       └── themes
│           └── monologue          #purchased theme
├── config                         #capistrano content
│   ├── deploy
│   │   ├── production.rb
│   │   └── staging.rb
│   └── deploy.rb
├── ghost                         #latest-ghost.zip OR ghost.git
└── lib
    └── capistrano
        └── tasks

New Blog Workflow

REPO=repo.git
SITE=blog.com

#clone
git clone $REPO $SITE
cd $SITE

Ghost replace

** PROD **

#populate ghost/
wget -q https://ghost.org/zip/ghost-latest.zip
unzip -q -d ghost ghost-latest.zip
cd ghost

#run tasks
npm install --production
grunt prod

** DEV **

#populate ghost/
git clone git://github.com/tryghost/ghost.git ghost
cd ghost
git checkout stable

#run tasks
npm install
grunt init

Linking files

ghost environment shares app/ content and theme via link

cd ghost
rm config.js
rm -rf content/{apps,data,images}
ln -s ../app/config.example.js config.js
ln -s ../../app/content/{apps,data,images} content/
ln -s ../../../app/content/themes/monologue content/themes/.

Start

** PROD **

npm install -g pm2
NODE_ENV="production" pm2 start index.js  --name "Ghost"
NODE_ENV="production" pm2 restart Ghost

** DEV **

npm start
LoadModule proxy_module /usr/lib64/httpd/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib64/httpd/modules/mod_proxy_http.so
<VirtualHost *:80>
ServerName blog.com
ServerAlias blog.com www.blog.com
Redirect / https://blog.com/
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile [CERT FILE]
SSLCertificateKeyFile [PV KEY]
SSLCACertificateFile [CA FILE]
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 E
ECDH+aRSA+RC4 EECDH EDH+aRSA !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"
SSLProtocol all -SSLv2 -SSLv3
#SSLOpenSSLConfCmd DHParameters /etc/pki/tls/certs/dhparams.pem
ServerName blog.com
ServerAlias blog.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/
RequestHeader set X-Forwarded-Proto "https"
</VirtualHost>
lock '3.4.0'
set :application, 'blog.com'
set :repo_url, '[email protected]:user/blog.com.git'
set :deploy_to, '/var/www/blog.com'
set :scm, :git
set :format, :pretty
set :log_level, :debug
set :pty, true
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence do
execute 'cd #{deploy_to}/current/ghost; NODE_ENV="production" pm2 start index.js --name "Ghost"'
execute 'cd #{deploy_to}/current/ghost; NODE_ENV=production pm2 restart Ghost'
end
end
desc 'Provision application'
task :provision do
on roles(:app), in: :sequence do
execute 'cd #{deploy_to}/current/ghost; NODE_ENV=production grunt prod'
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
desc 'Ghost - install'
task :ghost_install do
on roles(:app), in: :sequence do
within release_path do
execute :wget, "-q https://ghost.org/zip/ghost-latest.zip"
execute :unzip, "-q -d ghost ghost-latest.zip"
execute :rm, "ghost-latest.zip"
end
end
end
desc 'Ghost - symlink'
task :ghost_symlink do
on roles(:app), in: :sequence do
within "#{release_path}/ghost" do
execute :rm, "-rf config.js"
execute :ln, "-s ../app/config.js"
execute :rm, "-rf content/{apps,data,images}"
execute :ln, "-s ../../app/content/{apps,data,images} content/"
execute :ln, "-s ../../../app/content/themes/monologue content/themes/."
end
end
end
desc 'Ghost - npm'
task :ghost_npm do
on roles(:app), in: :sequence do
within "#{release_path}/ghost" do
execute :npm, "install --production --silent &>/dev/null"
end
end
end
before :updated, 'deploy:ghost_install'
before :updated, 'deploy:ghost_symlink'
before :updated, 'deploy:ghost_npm'
after :publishing, :provision
after :publishing, :restart
end
server 'blog.com', user: 'deployment-user', roles: %w{app db web}
server 'blog.com',
user: 'deployment-user',
roles: %w{web app db},
ssh_options: {
user: 'deploy', # overrides user setting above
keys: %w(/home/user/.ssh/trusted/key),
forward_agent: false,
auth_methods: %w(publickey password)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment