I'm trying to deploy my first DocPad website to the Gandi.net hosting provider, with this service :
https://www.gandi.net/hebergement/simple?language=nodejs&grid=A
My code is here :
https://github.com/nylnook/nylnook-website
It's running fine locally on my computer.
Technically it seem to be a 'vhost', and I'm supposed to write a "server.js" file to deploy DocPad in production to the gandi server, after I used :
git push gandi master
('gandi' being my git remote repo at their server)
and also used a custom command (XXX instead of my login) :
ssh XXXXX#git.XXX.gpaas.net 'deploy default.git'
They have a guide for their Node.js instance :
http://wiki.gandi.net/en/simple/instance/nodejs?s[]=node
and a guide for git usage on their servers :
http://wiki.gandi.net/en/simple/git
that suggest to use this code :
https://github.com/visionmedia/express/blob/master/examples/vhost/index.js
but I a newbie to node.js, learning with DocPad, so I can't figure how to do that !
Last link, the DocPad guide for deployment I followed so far :
http://docpad.org/docs/deploy
Thanks for you help !
Edit : another lead maybe :http://docpad.org/docs/api#using-with-express
Answering myself for documentation :
you need to modify 3 files
in server.js (thanks plflannery : https://github.com/bevry/docpad/issues/819) :
var spawn = require('child_process').spawn
var args = ['server'];
spawn('node_modules/.bin/docpad', args, {stdio:'inherit'}).on('close', function(err) {
if (err)
console.log("docpad failed");
else
console.log("docpad running");
});
in docpad.coffee, put :
port: 8080
in docpadConfig fonction, to change default port (9778) to
8080, as required by Gandi, explanations here :
https://github.com/bobobo1618/docpad-docum...
and in package.json put
"main": "server.js"
instead of
"main": "node_modules/docpad/bin/docpad-server"
So to launch docpad and install dependencies when deployment via Git.
Example of a working code :
https://github.com/nylnook/nylnook-website
Good luck in your projects !
Related
I'm running a next.js react app in a docker container. It's being composed with several other contains: one running Ghost (I'm using the API), one running mysql, and one running NGINX. I've got everything running in development mode.
It works perfectly when run using next dev. But when I run it by doing next build and next start, I start seeing errors like Error: getaddrinfo ENOTFOUND ghost-api when I try to make server-side HTTP requests to my Ghost API container. I'm not entirely sure what the issue is but it seems like there's some issue with how Node is making requests after being built. I've been digging through a lot of Docker/Node questions trying to figure this one out but haven't had any luck.
The entire project can be found here: https://github.com/MichaelWashburnJr/react-cms
The problem may exist in the environment variable that you are using. In both getGhostApi and getGhostApiKey function, you are using the environment variable.
In NextJs you'll have to specify a next.config.js in which you define the variables that you need for
Ex. next.config.js
module.exports = {
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: 'secret',
secondSecret: process.env.SECOND_SECRET, // Pass through env variables
},
publicRuntimeConfig: {
// Will be available on both server and client
staticFolder: '/static',
},
}
You can also refer to the next documentation for the same.
https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration
I'm not able to reproduce the error. How are you starting the frontend container in prod mode?
From the error it appears like you might be trying to start the frontend container or the frontend app as a separate process without starting it as part of the compose project. If that is the case, the name ghost-api won't be resolvable and you would get the Error: getaddrinfo ENOTFOUND ghost-api error.
I've changed the command key of frontend container as follows:
command: [ "yarn", "start-prod" ]
Changed the "start-prod" script in frontend/package.json as follows:
"start-prod": "next build && NODE_ENV='production' next start"
and everything worked as it worked in dev mode. I got some UNKNOWN_CONTENT_API_KEY error in both dev and prod mode but definitely there is no ghost-api name resolution error.
After cloning your repos:
$ grep -R ST_API *
frontend/.env.development:GHOST_API_URL=http://ghost-api:2368
frontend/.env.production:GHOST_API_URL=http://ghost-api:2368
frontend/src/constants/Config.js:export const getGhostApi = () => process.env.GHOST_API_URL || 'http://localhost:8000';
ghost-api is not a domain name: to make it work you need to edit your hosts file or (for a real production environment) to change http://ghost-api:2368 in frontend/.env.production file with the real deploy domain name.
If you are asking why you can't trust on docker compose networking, the answer is: you can, but only in the containers; while the front end will run in the browser of your application client, which is outside the containers.
Hope this helps.
It seems that Docker's hostname resolution does not work during build time. That is why ghost-api is not found.
Instead of referencing the other container by its name (ghost-api), on Mac you can try host.docker.internal. On Linux, using host networking during build worked for me:
nextjs-app:
build:
network: "host"
# ...
network_mode: "host"
This way, you can reference the other container using localhost.
thanks for taking time to help me
im deploying a nodejs express js project
these are the steps that i have done:
1- change the port to: process.env.PORT
code:
const PORT = process.env.PORT || 9000;
app.listen(PORT , function() {
console.log('Application is listening on 9000');
});
2- create Procfile with: web: node server.js
3- make sure in package json the npm start command points to "node path/server.js"
the server works locally
4- important note: I am sending an AJAX request from my front end to the server to get data
I have read on you documentation that i should add 0.0.0.0
$.ajax({
url: "0.0.0.0/hotels",
cache: false,
type: 'GET',
success: function(result) {
bla bla ....
}
});
also i have tried to add the url of heroku the one i get after creating
thanks in advance
have a great day
did not solve it yet but i organized some helpful heroku commands
useful commands
git remote -v
git remote rm heroku
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
heroku logs --tail
heroku run bash
Your code there looks fine (except 0.0.0.0 -- just use a relative path like /). I would ensure you've actually pushed the changes you have there. If you run heroku run bash, do you see your Procfile? When you run node server.js in that environment, does it run successfully?
I've seen Heroku customers get stuck on an issue like this, when the reality is that the code they have locally wasn't properly sent to Heroku.
Hello #jmccartie thank you for replying but it still does not work
could it be the static __dirname? im starting to question every part of the code :D
I changed the path and just to make sure i understood correctly
it used to be : "http://localhost:9000/data/hotels"
now is: "/data/hotels"
would you mind taking a look at my code?
just double check the parts i mentioned
https://github.com/hibaAkroush/herokuNode
i will name the files to make it easier for you
1- Procfile in the root
2- server in server/index.js line 24
3- the front end (where im sending an ajax get request) client/home.js line 6
4- packagejson line 10: "start": "node server/index.js"
thanks
ok i fixed it ...
wohoo!
not sure which thing i made fixed it
but what i did was:
1- I moved the server to the root and of course changed the code a bit so it would still work than i tested it locally to make sure
2- pushed on github
3- added ./ to procfile so it became
web: node ./index.js
instead of web: node index.js
thanks everyone !
I'm trying to deploy the Starter Kit of React.js (available here : https://github.com/kriasoft/react-starter-kit) on Openshift. To do that, I modified some little things that I explain here.
First, the logs in Openshift tells me that the import keyword in the servers.js file is not recognized. I think Babel is not used by Openshift at this point.
A workaround for that is mentioned here : How do I modify the node startup command in Open Shift?
So I modified the server.js content (because Openshift run the node server.js command and not the babel-node tools/run start defined in the scripts.start property of package.json) with the recommended content and renamed my base server.js to app.js.
Now, the logs tells me that babel-core is not found so I modified the package.json file to put babel-core and babel-cli in dependencies instead of devDependencies and remove a DEV value of another property.
All the times, when I push my code on Openshift (code of the src folder), the compilation failed at a random time (when dependencies are installed) and it take a long long time. However, when I reboot the cartridge I can see logs I explained.
My current situation is that things are looking better but the problem is the disk space : not enough. That's surprising me because the cartridge can host 1GB and on my local machine all files with dependencies take ~148MB. I tried to delete and recreate the cartridge : the same thing appears.
Does anybody know what can be wrong here ? The fact that the cardridge exceed 1GB is weird...
Thank you all.
Here's the solution... I hope it will save hours for some people !
Set the "production" mode to the cartridge app (so that in don't download so many inodes) :
rhc set-env NODE_ENV=production --app appname
Don't forget to modify config.js :
export const port = process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3000;
export const host = process.env.OPENSHIFT_NODEJS_IP || 'localhost';
export const databaseUrl = 'sqlite:' + process.env.OPENSHIFT_DATA_DIR + 'database.sqlite';
Modify app.js (include the host):
import { port, host, auth, analytics } from './config';
//...
models.sync().catch(err => console.error(err.stack)).then(() => {
app.listen(port, host, () => {
console.log(`The server is running at http://${host}:${port}/`);
});
I am migrating my data back-end to openshift from parse.com.
Step 1. I changed openshift port binding of project into following
//var port = process.env.PORT || 1337;
var port = parseInt(process.env.OPENSHIFT_NODEJS_PORT) || 8080;
var httpServer = http.createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
and folked as my new repo https://github.com/kyawzinsoe/parse-server-example.git
Step 2.
Then I create a gear with my parse-server repo with following command.
rhc app-create myserver nodejs-0.10 mongodb-2 --from-code=https://github.com/kyawzinsoe/parse-server-example.git
But it show 8080 port problem as following
What am I missing? Please help me.
You need use Node 4.1+ with parse server. OpenShift is running 0.10.x
You can use this repo https://github.com/h4t0n/nodejs-4-lts-openshift in order to run Node 4.1+ on your OpenShift app.
Update:
I have set up a deploy to OpenShift button that will do most of the work for you:
you will still need to set up you "appId" and "masterKey" either by editing index.js file or with rhc env set APP_ID=myAppId MASTER_KEY=myMasterKey -a myAppName
This is how you can do it the same thing with rhc tool:
rhc app create parseaio http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-nodejs http://cartreflect-claytondev.rhcloud.com/github/icflorescu/openshift-cartridge-mongodb --from-code https://github.com/antt001/parse-server-example --env APP_ID=myAppId MASTER_KEY=myMasterKey
for more in-depth instructions, check out my blog post on this topic
Original answer
create app using cartridge from http://github.com/icflorescu/openshift-cartridge-nodejs
paste url from Github page into "Code Anything" textbox at the bottom of the page of application creation Choose a type of application page.
on next page paste https://github.com/antt001/parse-server-example into Source Code textbox, to grab parse example project, modified for openshift settings
add recent MongoDB cartridge as instructed at http://github.com/icflorescu/openshift-cartridge-mongodb
clone your repo from OpenShift
replace "appId" and "masterKey" values in the index.js file with your app id and key.
It works fine, I am running this configuration right now.
Update 2
I have removed the snippet, since it is now on a GitHub repo that I mentioned above.
P.S.
as mentioned by #radzio, there is a problem with compiling native nodejs that requires GCC 4.8, however, this configuration does not need any of this and works as is, it uses bcrypt-nodejs instead of native
Thanks to #ionut-cristian-florescu for custom cartriges
My Problem is solved by #Jiri Fiala's comment that I need to set openshift IP
I have working SailsJS app that I want to deploy to Openshift, but as usual it doesn't go smoothly.
Here's what I did so far:
rhc app create myApp nodejs-0.10
rhc cartridge add mongodb-2.4
After these two, I can see that app is created and when I visit given URL, I got Welcome page.
I installed RockMongo, and I see that I can visit my mongodb as well.
Since I already have code, I proceed with following:
git remote add openshift -f <openshift-git-repo-url>
git merge openshift/master -s recursive -X ours
git push openshift HEAD
After I merge my existing code with remote openshift (like in commands above), things start to go wrong.
When I visit url to application, I receive 503 Service temporarily unavailable. If I visit RockMongo and try to login with given credentials, I receive
Unable to connect MongoDB, please check your configurations.
MongoDB said:Failed to connect to: 127.10.37.130:27017: Transport endpoint is not connected.
Also, in Applications Panel, status of my application is building (and stays like that for hours). After pushing code to openshift, application stopped, and after rebuilding it (automatically) I receive some errors, where the last one is
remote: An error occurred executing 'gear postreceive' (exit code: 34)
remote: Error message: CLIENT_ERROR: Failed to execute: 'control build' for /var/lib/openshift/538f1c205004461655000227/nodejs
Does anyone has idea what's going on?
Maybe I didn't set up ports, application url, db url properly? But then again, why RockMongo stopped working?
UPDATE
Here's my mongo config:
mongo: {
module: 'sails-mongo',
user: 'admin',
password: '********',
url: process.env.OPENSHIFT_MONGODB_DB_URL + 'surge'
}
Do I need to set up server_port = process.env.OPENSHIFT_NODEJS_PORT and server_ip_address = process.env.OPENSHIFT_NODEJS_IP as well?
I have some server.js file in root of my application, and I see that these variables are used here.
Here's what I get if I run env | grep NODEJS
OPENSHIFT_NODEJS_PATH_ELEMENT=/var/lib/openshift/538f1c205004461655000227//.node_modules/.bin:/opt/rh/nodejs010/root/usr/bin
OPENSHIFT_NODEJS_PORT=8080
OPENSHIFT_NODEJS_LD_LIBRARY_PATH_ELEMENT=/opt/rh/nodejs010/root/usr/lib64
OPENSHIFT_NODEJS_IDENT=redhat:nodejs:0.10:0.0.17
OPENSHIFT_NODEJS_LOG_DIR=/var/lib/openshift/538f1c205004461655000227/app-root/logs/
OPENSHIFT_NODEJS_IP=127.10.37.129
OPENSHIFT_NODEJS_PID_DIR=/var/lib/openshift/538f1c205004461655000227/nodejs//run/
OPENSHIFT_NODEJS_VERSION=0.10
OPENSHIFT_NODEJS_DIR=/var/lib/openshift/538f1c205004461655000227/nodejs/
and here's what I get for env | grep mongo:
OPENSHIFT_ROCKMONGO_DIR=/var/lib/openshift/538f1c205004461655000227/rockmongo/
PHPRC=/var/lib/openshift/538f1c205004461655000227/rockmongo/etc/conf/php.ini
OPENSHIFT_ROCKMONGO_IDENT=redhat:rockmongo:1.1:0.0.12
OPENSHIFT_MONGODB_IDENT=redhat:mongodb:2.4:0.2.11
OPENSHIFT_MONGODB_DB_URL=mongodb://admin:PASSWORD_HERE#127.10.37.130:27017/
OPENSHIFT_MONGODB_DIR=/var/lib/openshift/538f1c205004461655000227/mongodb/
Just in case someone else stumbles upon this problem, here is what I had to do.
I created separate file config/application.js, and there I placed
module.exports = {
port: process.env.OPENSHIFT_NODEJS_PORT,
host: process.env.OPENSHIFT_NODEJS_IP,
environment: 'production'
};
Also I found what was the problem with application not starting. Post-install was failing (bower install did not finish successfully). To fix it, one should add to scripts section of package.json
"postinstall": "export HOME=/var/lib/openshift/[instance-id]/app-root/runtime/repo; ./node_modules/bower/bin/bower install"