As part of my codeship to heroku deployment hook, I'd like to run database updates/migrations before the app starts. How can I trigger an npm script or a command line script in heroku using the codeship deployment step?
I tried putting it in as part of my npm start script but it seems to have trouble connecting to the database then. e.g.
from package.json
"start": "./node_modules/.bin/knex migrate:latest && node server.js"
If you add a custom deploy script to Codeship after the Heroku deployment step, it should run after the app is running, so you'll have database access. You have access to the heroku toolkit, so you should be able to run: heroku run --app YOUR_APP_NAME -- ./node_modules/.bin/knex migrate:latest
Related
I am trying to deploy an app on AWS Amplify.
The app is React front and and NodeJS Express backend.
The frontend works fine, but the backend is just stuck without any reasonable explanation
My YML file is
version: 1
backend:
phases:
build:
commands:
- npm run build-backend
postBuild:
commands:
- cd ..
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build-frontend
artifacts:
baseDirectory: ./client/build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
build backend-script :
"build-backend": "cd server && npm run start",
npm run start script:
"start": "npm install && node index.js"
The build is getting stuck on the npm install and after 10-20 minutes just "gives up" without the following log
2021-04-22T11:49:20.693Z [INFO]: > server#1.0.0 start /codebuild/output/src650104622/src/myBlog/server
> npm install && node index.js
2021-04-22T11:49:26.976Z [INFO]: > bcrypt#5.0.0 install /codebuild/output/src650104622/src/myBlog/server/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
Thanks
I came across this thread while looking for a solution for my project. And because there are no more answers here, I'll tell you what I could find myself.
Amplify works fine with SSG web applications (Gatsby, etc.), with SSR (React, NextJS, NuxtJS, etc.) and with simple NodeJS and ExpressJS applications (which only run on requests because Amplify uses Lambda-functions to handle it). So:
If you need a simple ExpressJS application for your API you can
use the following serverless Ampl solution:
https://docs.amplify.aws/guides/api-rest/express-server/q/platform/js/
If you need a socket.io application (or another constantly
running application) you need to use AWS Fargate (uses
docker images) or AWS EC2 (works on simple virtual machine
with access by SSH) solutions.
P.S. If you have any other information on this subject, please post it here.
I have loopback 3 project. I want to build it. I am creating a bitbucket pipeline for this.
So for deployment, I want to know how to build loopback 3 project so that I can use these commands into my bitbucket.yml file.
I checked the documentations but for lb3 there is nothing for building the project. I got this into documentations: Preparing-for-deployment. But I am not user how I can use this into the yml file.
For loopback 4 we can use #loopback/build, and its working fine there. But I couldn't find anything for loopback 3.
Is there any other way to build loopback 3 project ?
Thanks in advance!
You can't build a loopback 3 server you can only run it.
To run a loopback server you simply use npm start or node . or even node server/server
Your postest script is running a linter and an audit, not the actual server.
What is running your server is not the script in the package.json it's the AZURE_EXTENSION_COMMAND part.
It's running pm2 start server/server.js which is a process manager that run your node server.
Using pm2 is correct making a separate step for testing and lining is also correct the problem is that you are confusing which part do what role.
This resulted in a response to the wrong question.
I didn't find anything for creating bundle for my loopback 3 app,
we can't make bundle of lb3. we can run server.js file and that's what I did using PM2. AZURE_EXTENSION_COMMAND here you can see that I have pulled to code from my branch and run the server.js file from that.
I used following things into my bitbucket.yml :
> pipelines:
branches:
> master:
> - step:
> script:
> - npm install
>
> - npm run posttest
>
> - step:
> name: Deploy to master
> deployment: production
> script:
> - echo "Deploying to master"
>
> - pipe: microsoft/azure-vm-linux-script-deploy:1.0.1
> variables:
> AZURE_APP_ID: '<appid>'
> AZURE_PASSWORD: '<pass>'
> AZURE_TENANT_ID: '<tenantid>'
> AZURE_RESOURCE_GROUP: '<rg>'
> AZURE_VM_NAME: '<vm name>'
> AZURE_EXTENSION_COMMAND: 'cd <path to my folder> && git remote add origin <my repo> && git pull origin master && npm install -g npm && npm install && sudo -E pm2 start server/server.js'
And in my package.json I have used below script for auditing:
"scripts": {
"posttest": "npm run lint && npm audit --audit-level high"
}
And it is working fine.
I am not sure if this is the very right methode, but i just found it useful.
Hope it can help someone as well.
Thanks!
List item
I am trying to deploy a node - react app on heroku
If you are deploying your app as a node.js application you can run into this issue. Create your heroku app using the create-react-app buildpack:
https://elements.heroku.com/buildpacks/mars/create-react-app-buildpack
Hope this helps!
A 503 error code means the server cannot handle the request because it is either unresponsive or overloaded, as stated on MDN. This could be a result of incorrectly initializing the application on Heroku. Run the following in your directory from the terminal to deploy to heroku.
cd my-project
git init
heroku git:remote -a app-name
git add .
git commit -am "comment"
git push heroku master
More details about deploying a Node app to Heroku can be found here
I have a nodejs express app serving a site. I deployed it with Heroku, using buildpack/nodejs and Github. Every time i push on Github, Heroku detects the push and runs the npm start script.
The problem is that I need to pass to a Docker image containing the nodejs app. I did it and it works locally, I can run it with docker run -d -p 8000:8000 exporter and it works.
I added the docker.yml file on the root folder and pushed on Github. But heroku still runs the npm script in the package.json, ignoring the docker.yml.
Is there a way to make heroku create the container from the Dockerfile every time I push to Github?
For Heroku to understand your heroku.yml file you need a few things.
First off you need to make sure that the Dockerfile is in the root directory.
Second, you need to ensure you are building and running the docker environment.
Finally, make sure you set your heroku stack to docker.
So, given that we want to ensure the directory tree looks like this:
|-my_app
|-app_contents
|-Dockerfile
|-heroku.yml
|-etc...
And that the heroku.yml file looks something like this:
build:
docker:
web: Dockerfile
run:
web: docker run -d -p 8000:8000 exporte
and finally run this in your heroku repo:
heroku stack:set container
Then just make sure you push your changes up.
If this doesn't help. I would recommend updating your post with the following:
The file tree
The Dockerfile
The heroku.yml file
Thanks to the answer of Taylor Cochran I managed to solve the problem.
I first tried to follow this link: https://devcenter.heroku.com/articles/container-registry-and-runtime
It worked but I had to do it from the cli.
After that I removed the entire project and remade it. I followed the indications of Taylor Cochran and pushed from heroku cli. I saw it worked and I then added the github deploy. And now every time I push on Github the new Docker container is automatically built and deployed by Heroku.
NB: I changed web: docker run -d -p 8000:8000 exporter to npm start
I have to be missing something. I have a basic ecosystem.json layout, with maybe the one other post deploy procedure for webpack to build the production set.
I get no errors on pm2 deploy ecosystem.json staging, yet I never get the current ref. The only time I get the latest is when I wipe the directories out and pm2 deploy ecosystem.json staging setup.
I've tried pm2 deploy ecosystem.json staging update with no luck.
Deployment is stuck at the original deploy commit. I confirm this with pm2 deploy ecosystem.json current.
What am I missing?