Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build and deploy an app from local directory?

Tags:

openshift

I just started exploring OpenShift Online 3 and it seems really awesome. I'm trying to setup a simple HTTP server. Here are my steps using CLI:

  1. oc login <...>
  2. oc new-project <...>
  3. oc new-app .

My current working folder consists of two files package.json and server.js.

Package.json

{
  "name": "test",
  "version": "0.0.1",
  "description": "Node.js app for OpenShift 3",
  "main": "server.js",
  "dependencies": {
    "express": "^4.13.4"
  },
  "engine": {
    "node": "*",
    "npm": "*"
  },
  "scripts": {
    "start": "node server.js"
  }
}

Server.js

const express = require('express')
const app = express()

const port = process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080
const ip = process.env.IP   || process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0'

app.get('/', function (req, res) {
  res.status(200).send({ message: 'OK' })
})

// error handling
app.use(function(err, req, res, next){
  console.error(err.stack)
  res.status(500).send('Something bad happened!')
})

app.listen(port, ip)
console.log('Server running on http://%s:%s', ip, port)

module.exports = app

Here's console output:

--> Creating resources ...
    imagestream "olmeo-openshift" created
    buildconfig "olmeo-openshift" created
    deploymentconfig "olmeo-openshift" created
    service "olmeo-openshift" created
--> Success
    Build scheduled, use 'oc logs -f bc/olmeo-openshift' to track its progress.
    Run 'oc status' to view your app.

After build is done web console shows an error:

Environment: 
    DEV_MODE=false
    NODE_ENV=production
    DEBUG_PORT=5858
Launching via npm...
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm ERR! Linux 3.10.0-693.12.1.el7.x86_64
npm ERR! argv "/opt/rh/rh-nodejs6/root/usr/bin/node" "/opt/rh/rh-nodejs6/root/usr/bin/npm" "run" "-d" "start"
npm ERR! node v6.11.3
npm ERR! npm  v3.10.9
npm ERR! path /opt/app-root/src/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/opt/app-root/src/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/opt/app-root/src/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /opt/app-root/src/npm-debug.log

Apparently, package.json can't be found. What am I missing?

like image 615
manidos Avatar asked Oct 28 '25 03:10

manidos


1 Answers

If you use:

oc new-app .

in a git workarea cloned off a remotely hosted Git repository, the build will be set up to pull files from the hosted Git repository. This means that if you make local changes and don't add/commit/push them to the hosted Git repository, then they will never be used.

If you want to work from a local directory and not use a hosted Git repository, you need to use a binary input build. To do that first run:

oc new-build --binary --image-stream nodejs --name olmeo-openshift

Then start a build by running:

oc start-build olmeo-openshift --from-dir=.

This will upload files from the local directory.

Once the first image has been built, then you can run:

oc new-app olmeo-openshift

to deploy the image, and:

oc expose svc/olmeo-openshift

to give it a public URL.

Each time you make code changes, run again:

oc start-build olmeo-openshift --from-dir=.
like image 145
Graham Dumpleton Avatar answered Oct 30 '25 00:10

Graham Dumpleton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!