├── .gitignore ├── .htaccess ├── README.md ├── app.js ├── deploy.sh ├── ecosystem.json ├── index.html └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | node_modules 3 | ssh 4 | -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | RedirectMatch 404 /\.git 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Continuous Deployment with SemaphoreCI 2 | 3 | ### Create an SSH key 4 | ``` 5 | ssh-keygen -C semaphore 6 | ``` 7 | - save it as ~/.ssh/id_rsa.semaphore 8 | - don't give it a password 9 | 10 | ### Setup your server 11 | - paste the contents of your `~/.ssh/id_rsa.semaphore.pub` to your server's `~/.ssh/authorized_keys` file: 12 | - on your machine: 13 | ``` 14 | cat ~/.ssh/id_rsa.semaphore.pub | pbcopy 15 | ``` 16 | - on the server: 17 | echo "" >> ~/.ssh/authorized_keys 18 | - clone your git repo to be the html directory on your server 19 | ```bash 20 | git clone https://@github.com/willrstern/example-deployment.git html 21 | ``` 22 | 23 | ### Setup Semaphore 24 | - create a new project 25 | - setup test command (or just do `echo ok` if you don't have tests) 26 | - setup a server 27 | - add these 2 deployment commands 28 | ``` 29 | ssh-keyscan -H -p 22 45.55.153.229 >> ~/.ssh/known_hosts 30 | ssh root@45.55.153.229 'bash -s' < deploy.sh 31 | ``` 32 | - paste the contents of `~/.ssh/id_rsa.semaphore` as your private key 33 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | require("express")() 2 | .get("/", (req, res, next) => { 3 | res.send("hello world") 4 | }) 5 | .listen(3000) 6 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | cd /usr/share/nginx/html/ 2 | git fetch --all 3 | git reset --hard origin/master 4 | -------------------------------------------------------------------------------- /ecosystem.json: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | * Application configuration section 4 | * http://pm2.keymetrics.io/docs/usage/application-declaration/ 5 | */ 6 | apps : [ 7 | 8 | { 9 | name : "node app", 10 | script : "app.js", 11 | env_production : { 12 | NODE_ENV: "production" 13 | } 14 | } 15 | ], 16 | 17 | /** 18 | * Deployment section 19 | * http://pm2.keymetrics.io/docs/usage/deployment/ 20 | */ 21 | deploy : { 22 | production : { 23 | user : "dep", 24 | host : "104.236.108.202", 25 | ref : "origin/master", 26 | repo : "git@github.com:repo.git", 27 | path : "node-app", 28 | ssh_options: "-i ssh/id_rsa", 29 | "post-deploy" : "nvm install && npm install && pm2 startOrRestart ecosystem.json --env production" 30 | }, 31 | dev : { 32 | user : "node", 33 | host : "212.83.163.1", 34 | ref : "origin/master", 35 | repo : "git@github.com:repo.git", 36 | path : "/var/www/development", 37 | "post-deploy" : "npm install && pm2 startOrRestart ecosystem.json --env dev", 38 | env : { 39 | NODE_ENV: "dev" 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Hello World!!!!!!!

5 | 6 | 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-deployment", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo 'tests passed'" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/willrstern/example-deployment.git" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "bugs": { 17 | "url": "https://github.com/willrstern/example-deployment/issues" 18 | }, 19 | "homepage": "https://github.com/willrstern/example-deployment#readme", 20 | "dependencies": { 21 | "express": "^4.14.0" 22 | }, 23 | "devDependencies": { 24 | "pm2": "^2.0.18" 25 | } 26 | } 27 | --------------------------------------------------------------------------------