Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

CI with Vexor

$
0
0

Today I’ve configured CI with Vexor formy personal blog . Actually I use Hexo to generate a static site and then upload the generated static content to the remote machine, hosting the blog. Quite simple.

Generating the static pages and then upload them to the remote machine takes a lot of effort beside writing a post. And the job is so repetitive. So, CI is a very good use case for this. But, as I use private repo for this, most of the prominent CI hosts charge a lot to build for private repositories. After searching a little bit, got the name of Vexor . The best thing is that, they are not limiting you, 1 build unit, 2 build units, private repositoriesetc. You start with free 100 build minutes, then $0.015/min. Quite cheap. And no prior commitment with huge monthly subscriptions (Others are really pricey. I don’t understand, why do they charge over $30/month for a single unit, while builds for most of the normal projects does not go over 1hr. And how many builds per day a project can see. I don’t know.) So, I likedthe pricing matrix of Vexor CI.

One problem with them is they have not yet completed their documentation fully. And their whole doc is full of examples of building Ruby applications. Probably they are fond of Ruby. I’ve no complains. But they should include at-least some full examples for NodeJS. Then I came across one of the features in their build system. You can log into the build container for 30 mins (if you enable ssh) to debug. So, nice feature. Probably use only once for one project but that’s big.

So, I started to configure. First steps are quite straight-forward. Go to Vexor CI . Sign up with Github or GitLab or Bitbucket account. Enable your repo. You should be able to see the repository in your dashboard . As soon as the repositoryis connected, it will try to start the build. But, my repositorywas not configured. Naturally, first build failed. Then I started to configure.

First, added one file to the root of the repo by the name . vexor . yml ( vexor . yml , without the leading dot is also permissible).

As I want to build for NodeJS. I added language : node_js . They have support for several versions of Node. I added for 6.1.0 .

language: node_js node_js: - "6.1.0"

I use Hexo to generate the site. And this needs hexo - cli to be installed globally. So, I added npm install - g hexo - cli and of-course npm install to the install section.

install: - npm install -g hexo-cli - npm install

As I’ve included one post-install hook to the package.json with the command hexo generate , practically I’ve nothing to do for generation of static content in the script section.

{ ... , "scripts": { "postinstall": "hexo generate" }, ... }

Now, I need to upload the generated content to the remote site. So, added some lines (with the help of Domenic’s gist ) to the before_script section to add the ssh - key to ssh agent .

before_script: - chmod 600 /home/vexor/.ssh/id_rsa - eval `ssh-agent -s` - ssh-add /home/vexor/.ssh/id_rsa

The available key in the . ssh directory in $ HOME is the private key you have to add in the settings of the project. You can generate one key pair by ssh - keygen - t rsa - b 4096 - C "your_email@example.com" ( More details ). And add the content of the public key of the pair to a file named authorized_keys in the . ssh directory of home of the user, you want to deploy with, to the remote machine.

To deploy I’ve added one shell script file, named deploy in my repository. (taken from here ). Only I modified the userid , server address , added cd public (from where we need to upload), the remote directory path and removed the exclude - from flag.

#!/bin/bash cd public $ERRORSTRING="Error. Please make sure you've indicated correct parameters" if [ $# -eq 0 ] then echo $ERRORSTRING; elif [ $1 == "live" ] then if [[ -z $2 ]] then echo "Running dry-run" rsync --dry-run -az --force --delete --progress -e "ssh -p22" ./ build@xx.xx.xx.xx:/usr/share/nginx/html elif [ $2 == "go" ] then echo "Running actual deploy" rsync -az --force --delete --progress -e "ssh -p22" ./ build@xx.xx.xx.xx:/usr/share/nginx/html else echo $ERRORSTRING; fi fi This file deploy need to executable. So, added chmod + x . / deploy t

Viewing all articles
Browse latest Browse all 11063