0

Currently my deployment looks as follows:

  1. After committing local changes, I run locally a grunt task to build the project into a /dist folder.

  2. Then I push them to bitbucket. e.g. branch name is feature/deposit

  3. In Bitbucket I merge feature/deposit into develop branch and Codeship builds develop branch (runs test) and after that the following code is executed:

    ssh nodejs@12.345.67.891 'cd project/www; git checkout develop; git pull origin develop; npm install; sudo monit restart project.app.js'

I do not like this approach, because for me it would make much more sense that I deploy what Codeship built. Codeship runs npm install, and I want it to run my grunt:build task and then deploy it to my production server.

I found an article addressing a similar issue and added export CI_COMMIT_ID=$(git rev-parse HEAD) task. But I just do not fully realise what I need to do with it in my deployment script. Besides this example is used with heroku whereas in my case I use custom deployment script.

I also found a github repo with useful deployment scrips and this one might suit my needs.

But what I want to figure out is if I can pull from the built version (the one that Codeship built) in a same fashion as I do it now, but git pull origin develop should be git pull from what Codeship just built

user2814599
  • 1,060
  • 1
  • 13
  • 27
  • 1
    May I ask why you want to keep the built app in your git repository as well? Most of our users follow a slightly different approach: Commit local changes & push to remote repository (GitHub / Bitbucket). This will trigger a build on Codeship, Codeship builds the app (e.g. via `grunt`), runs your tests and then deploys the app via for example `rsync` or by pushing it to Heroku / .... – mlocher May 02 '16 at 09:25
  • @mlocher I do not want to keep /dist in my repo. I do it now but want to avoid this approach. Can you please provide more info on how I can use the rsync to deploy using a custom script.? Thanks! – user2814599 May 02 '16 at 09:43
  • @mlocher - I guess you advise to just copy the built to server without using git there? – user2814599 May 02 '16 at 09:44
  • 1
    Yeah, exactly. I'd recommend removing the `dist` folder from the repository, building it via Codeship and deploy via copying the files to the remote server. You have plenty of possibilities that way, from very basic tools like `scp`, `rsync` (though basic is a variable term here) to Capistrano (Ruby based) or https://www.npmjs.com/package/flightplan (though I haven't used that) yet. – mlocher May 02 '16 at 09:49
  • @mlocher I like this idea but my original question is: how do I access the code that has just been built by Codeship? – user2814599 May 02 '16 at 09:52
  • Same as when you build the application locally. By default you're working out of the root directory of your repository on Codeship. So if your `grunt` task creates a `dist` directory you could upload it via `scp -rp ./dist/* ssh_user@your.server.com:/path/on/server/` – mlocher May 02 '16 at 09:56
  • 1
    See https://codeship.com/documentation/continuous-deployment/deployment-with-ftp-sftp-scp/#continuous-deployment-with-scp for some documentation on SCP or rsync. – mlocher May 02 '16 at 09:57
  • ./dist - is the folder where the built version is. And ssh_user@your.server.com:/path/on/server/ is the production server? Do I use this code in deployment pipeline settings? Sorry for asking for details but I need to understand it. – user2814599 May 02 '16 at 10:16

1 Answers1

0

So I ended up with simply copying /dist folder code to production server. I removed git from production server and added /dist folder to gitignore. Codeship runs all commands including the one to build the project and then copies it to production server. Very fast and convenient way.

Continuous Deployment settings:

rsync -avz -e "ssh" ~/src/bitbucket.org/username/project/dist/ nodejs@11.222.33.444:/home/nodejs/project/www/dist

/src/bitbucket.org/username/project/ - you can get from one of the build steps.

user2814599
  • 1,060
  • 1
  • 13
  • 27