Skip to content

Latest commit

 

History

History
65 lines (42 loc) · 3.04 KB

File metadata and controls

65 lines (42 loc) · 3.04 KB

OpenShift Artifactory integration example with Node.js

Prerequisites Details

Install Artifactory in OpenShift:

Create Node.js micro service

  • We will use node-version as an example project to demonstrate this integration.

Command to test node-version package:

  • Set npm command line client to work with Artifactory Npm Registry.
    create .npmrc file and paste following content to it:
    registry = https://$ARTIFACTORY_URL/api/npm/$ARTIFACTORY_NPM_REPO_NAME/
    _auth = $ARTIFACTORY_USER:$ARTIFACTORY_PASSWORD
    email = youremail@email.com
    always-auth = true
    
  • Install dependencies: npm install
  • Start node Server: npm start
  • Access Application on: http://localhost:3000

Command to build docker image and push it to Artifactory:

  • Build docker image: docker build -t $DOCKER_REGISTRY/node-version .
  • Run docker container: docker run -d -p 3000:3000 $DOCKER_REGISTRY/node-version
  • Login to Artifactory docker registry: docker login -u ARTIFACTORY_USER -p $ARTIFACTORY_PASSWORD $DOCKER_REGISTRY
  • Push docker image: docker push $DOCKER_REGISTRY/node-version

Configure OpenShift to build, package and deploy node-version

Step 1: Create OC Secrets to use Artifactory as Docker Registry and NPM Repository

  • Create OC secret to access Artifactory NPM repository given an existing .npmrc file:
    • oc create secret generic secret-npmr .npmrc=.npmrc
  • Create OC secret to access Docker repository:
    • oc create secret docker-registry rt-docker-registry --docker-server=<RT_DOCKER_REPO> --docker-username=<YOUR_USER> --docker-password=<YOUR_PASSWORD> --docker-email=<YOUR_EMAIL>
  • Link docker secret to at-least 3 service accounts:
    • oc secrets add serviceaccount/default secrets/rt-docker-registry --for=pull
    • oc secrets add serviceaccount/builder secrets/rt-docker-registry
    • oc secrets add serviceaccount/deployer secrets/rt-docker-registry

Step 2: Create Nodejs project (Build, Deploy, Service and Route Creation templates)

Note: Replace <RT_DOCKER_REPO> with Artifactory docker registry domain in Build Config and Deployment Config before running following commands: