-
Notifications
You must be signed in to change notification settings - Fork 0
How to setup up a deployment pipeline with OpenShift, Nodejs, Bitbucket and Wercker
WARNING : I wrote this as a guide for myself when working with this particular stack. Was tired of scouring my pocket articles each time i had to deploy a new project.
- You know what you are doing.
- You have an Openshift, Bitbucket and Wercker Account
Put your source code on Bitbucket (This should be straight foward).
I'd suggest starting with a barebones nodejs cartridge, cloning the Openshift repo and pushing it to bitbucket first before putting in your custom code.
Grant wercker access to the repo you would like built by creating a new application.( Again, pretty straight foward ).
Add a wercker.yml
file to the root of your project that configures how wercker will work with your project.Since we are working with nodejs, you could look at the javascript getting started guide.
For brevity's sake, here's the sample wercker.yml
file i always use as of the last commit timestamp of this wiki.
# This references the default nodejs container from
# the Docker Hub: https://registry.hub.docker.com/_/node/
# If you want Nodesource's container you would reference nodesource/node
# Read more about containers on our dev center
# http://devcenter.wercker.com/docs/containers/index.html
box: node
# This is the build pipeline. Pipelines are the core of wercker
# Read more about pipelines on our dev center
# http://devcenter.wercker.com/docs/pipelines/index.html
# You can also use services such as databases. Read more on our dev center:
# http://devcenter.wercker.com/docs/services/index.html
# services:
# - postgres
# http://devcenter.wercker.com/docs/services/postgresql.html
# - mongodb
# http://devcenter.wercker.com/docs/services/mongodb.html
build:
# The steps that will be executed on build
# Steps make up the actions in your pipeline
# Read more about steps on our dev center:
# http://devcenter.wercker.com/docs/steps/index.html
steps:
# A step that executes `npm install` command
- npm-install
# A step that executes `npm test` command
- npm-test
# A custom script step, name value is used in the UI
# and the code value contains the command that get executed
- script:
name: echo nodejs information
code: |
echo "node version $(node -v) running"
echo "npm version $(npm -v) running"
deploy:
steps:
- add-ssh-key:
keyname: OPENSHIFT_SSH_KEY
host: $OPENSHIFT_HOST
- add-to-known_hosts:
hostname: $OPENSHIFT_HOST
- script:
name: git setup
code: |
git config --global user.email $EMAIL_ADDRESS
git config --global user.name $USER_NAME
git config --global push.default matching
- script:
name: deploy
code: |
git push $OPENSHIFT_GIT_URL $OPENSHIFT_BRANCH
Go to the Wercker settings for your app and create a new ssh key pair named OPENSHIFT_SSH_KEY
(or whatever the hell you want to call it, but i'll use OPENSHIFT_SSH_KEY
for the rest of this tutorial ).
Copy the public key to Openshift. You could call it wercker
, but, it's a free world.
Create a new pipeline from the wercker settings for your app called deploy-to-openshift
( or whatever you ... blah, blah, blah ) and set the YML pipeline name as deploy
(unless you changed it in the wercker.yml
file ).
Since we are chaining this pipeline to the default build
pipeline, we leave the Hook type to default.
Add the Following environment variables to the deploy-to-openshift
pipeline.
-
OPENSHIFT_SSH_KEY
: It's an ssh key pair and yeah it's the one we created inStep 4
-
OPENSHIFT_HOST
: The application url from openshift withouthttp://
. Copy the url with therhcloud.com
domain ( Even if you're using a custom domain ). -
OPENSHIFT_GIT_URL
: The git url given to you by Openshift. -
OPENSHIFT_BRANCH
: The branch to which you want to upload to. it'smaster
by default in Openshift. -
EMAIL_ADDRESS
: Bitbucket email address. -
USER_NAME
: Bitbucket username.
Chain the deploy-to-openshift
pipeline to the build
pipeline on the master
branch ( or... blah blah blah ) in the workflow settings area for your app.
Push a commit on the master
to bitbucket and see your pipeline come to life!