Run sequelize migrates in docker compose - javascript

I am trying to up two containers with node and postgres (i need to save the content of the database). Follow the code below:
Dockerfile:
FROM node:lts-alpine
RUN mkdir -p /home/node/api/node_modules && chown -R node:node /home
WORKDIR /home/node/api
COPY package.json /
USER node
RUN npm i
COPY --chown=node:node . .
EXPOSE 3000
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
docker-entrypoint.sh:
#!/bin/sh
npx sequelize-cli db:migrate
npm run dev
Well, here I don't know how to run the migrates, because in my computer I only run "sequelize db:migrate", I have a script in package.json too "migrate:dev": "NODE_ENV=development sequelize db:migrate"
for example.
And the docker-compose.yml:
version: '3'
services:
app-app:
container_name: app-app
build: '.'
volumes:
- .:/home/node/api
- /home/node/api/node_modules
depends_on:
- postgres-app
networks:
- app-connect
ports:
- '3000:3000'
postgres-app:
container_name: postgres-app
image: postgres:11
restart: unless-stopped
volumes:
- postgres-app-data:/data
environment:
POSTGRES_DB: ${DATABASE}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
networks:
- app-connect
volumes:
postgres-app-data:
networks:
app-connect:
driver: bridge
But the migration not run yet. I have an error when I try run the docker-entrypoint.sh:
chmod: /docker-entrypoint.sh: Operation not permitted
ERROR: Service 'app-app' failed to build: The command '/bin/sh -c chmod +x /docker-entrypoint.sh' returned a non-zero code: 1
If I remove all these items and only run npm start directly all works but when I try to access the app container to run the migrate show me the error:
docker exec -it 351 npm run migrate:dev
> app#1.0.0 migrate:dev /home/node/api
> NODE_ENV=development sequelize db:migrate
Sequelize CLI [Node: 12.14.0, CLI: 5.5.1, ORM: 5.21.3]
Loaded configuration file "src/config/database.js".
Using environment "development".
ERROR: getaddrinfo ENOTFOUND postgres
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app#1.0.0 migrate:dev: `NODE_ENV=development sequelize db:migrate`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app#1.0.0 migrate:dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/node/.npm/_logs/2020-01-09T12_43_32_377Z-debug.log
How I can do this? Thanks!

So as per the comments above, the problem was that the DB_HOST was set with the wrong value.
The DB_HOST should have the value of the service name in that case: postgres-app.

Related

npx create-react-app causes does not work after I fixed the cmd.exe location

I have wrote some server side code for handling GraphQL queries for a simple calendar app that I hope to connect to a smart pill dispenser that I am building.
I want to use react to build a front-end that will send these GraphQL queries and receive back data. When I try to run npx create-react-app client --verbose I get the following output:
C:\mitesh\javascriptcode\calendar>npx create-react-app client --verbose
... End of --verbose output.
npm info lifecycle resolve-from#4.0.0~postinstall: resolve-from#4.0.0
npm info lifecycle babel-plugin-syntax-object-rest-spread#6.13.0~postinstall: babel-plugin-syntax-object-rest-spread#6.13.0
npm info lifecycle babel-plugin-transform-react-remove-prop-types#0.4.24~postinstall: babel-plugin-transform-react-remove-prop-types#0.4.24
npm info lifecycle semver#5.7.1~postinstall: semver#5.7.1
npm info lifecycle core-js#2.6.11~postinstall: core-js#2.6.11
> core-js#2.6.11 postinstall C:\mitesh\javascriptcode\calendar\client\node_modules\babel-runtime\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"
which indicates that core-js is not updated. So I try to manually update core-js
with npm install --save core-js#^3 -g and I get the same output:
npm info lifecycle core-js#3.6.4~postuninstall: core-js#3.6.4
npm timing action:unbuild Completed in 6ms
npm timing action:remove Completed in 184ms
npm timing action:finalize Completed in 4ms
npm timing action:refresh-package-json Completed in 14ms
npm info lifecycle core-js#3.6.4~preinstall: core-js#3.6.4
npm timing action:preinstall Completed in 2ms
npm info linkStuff core-js#3.6.4
npm timing action:build Completed in 1ms
npm info lifecycle core-js#3.6.4~install: core-js#3.6.4
npm timing action:install Completed in 1ms
npm info lifecycle core-js#3.6.4~postinstall: core-js#3.6.4
> core-js#3.6.4 postinstall C:\mitesh\javascriptcode\calendar\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"
Microsoft Windows [Version 10.0.18363.720]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\mitesh\javascriptcode\calendar\node_modules\core-js>
And then it just kicks me out of the process and I am in some directory.
If I do npm version core-js, I get this.
C:\mitesh\javascriptcode\calendar>npm version core-js
npm info it worked if it ends with ok
npm verb cli [
npm verb cli 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli 'C:\\Users\\kumarm4\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'version',
npm verb cli 'core-js'
npm verb cli ]
npm info using npm#6.14.2
npm info using node#v12.16.1
npm ERR! version No valid package.json found
npm verb stack Error: Error: ENOENT: no such file or directory, open 'C:\mitesh\javascriptcode\calendar\package.json'
npm verb stack at ReadFileContext.<anonymous> (C:\Users\kumarm4\AppData\Roaming\npm\node_modules\npm\lib\version.js:118:23)
npm verb stack at ReadFileContext.callback (C:\Users\kumarm4\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:115:16)
npm verb stack at FSReqCallback.readFileAfterOpen [as oncomplete] (fs.js:256:13)
npm verb cwd C:\mitesh\javascriptcode\calendar
npm verb Windows_NT 10.0.18363
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\kumarm4\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "version" "core-js"
npm verb node v12.16.1
npm verb npm v6.14.2
npm ERR! code [
npm ERR! code 'Error: ENOENT',
npm ERR! code 'ENOENT',
npm ERR! code index: 0,
npm ERR! code input: "Error: ENOENT: no such file or directory, open 'C:\\mitesh\\javascriptcode\\calendar\\package.json'",
npm ERR! code groups: undefined
npm ERR! code ]
npm ERR! Error: ENOENT: no such file or directory, open 'C:\mitesh\javascriptcode\calendar\package.json'
npm verb exit [ 1, true ]
npm timing npm Completed in 123ms
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\kumarm4\AppData\Roaming\npm-cache\_logs\2020-03-15T19_44_57_443Z-debug.log
C:\mitesh\javascriptcode\calendar>

Can't npm start on my react project after adding babel-cli

Miks#DESKTOP-DOAIF41 MINGW64 ~/Desktop/LYNDA MERN/Exercise Files/Ch02/02_01/start/dist
$ npm start
react-essential#1.0.0 start c:\Users\mctumbaga\Desktop\LYNDA MERN\Exercise Files\Ch02\02_01\start
httpster -d ./dist -p 3000
'httpster' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-essential#1.0.0 start: httpster -d ./dist -p 3000
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-essential#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\mctumbaga\AppData\Roaming\npm-cache_logs\2018-10-18T02_15_26_741Z-debug.log
I see above that your error states:
'httpster' is not recognized as an internal or external command, operable program or batch file.
Have you tried installing the package globally npm -g install httpster so that httpster is accessible from any directory where you want to have an HTTP service running?

Error: Command failed: /bin/sh -c cd mean && npm install

So I am getting this error:
bash-3.2$ yo meanjs
You're using the official MEAN.JS generator.
? What mean.js version would you like to generate? 0.4.0
0.4.0
? In which folder would you like the project to be generated? This can be changed later. mean
Cloning the MEAN repo.......
? What would you like to call your application? MEAN
? How would you describe your application? Full-Stack JavaScript with MongoDB, Express, AngularJS, and Node.js
? How would you describe your application in comma seperated key words? MongoDB, Express, AngularJS, Node.js
? What is your company/author name?
? Would you like to generate the article example CRUD module? Yes
? Would you like to generate the chat example module? Yes
Running npm install for you....
This may take a couple minutes.
Error: Command failed: /bin/sh -c cd mean && npm install
npm ERR! Darwin 14.5.0
npm ERR! argv "/Users/mona/.nvm/versions/node/v4.0.0/bin/node" "/Users/mona/.nvm/versions/node/v4.0.0/bin/npm" "install"
npm ERR! node v4.0.0
npm ERR! npm v2.14.2
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! syscall connect
npm ERR! network connect ETIMEDOUT 23.235.39.162:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! Please include the following file with any support request:
npm ERR! /Users/mona/interviews/mean/mean/npm-debug.log
at ChildProcess.exithandler (child_process.js:203:12)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:817:16)
at Socket.<anonymous> (internal/child_process.js:319:11)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Pipe._onclose (net.js:469:12)
Please help me fix it.
History of the commands I've entered:
567 git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
569 . ~/.nvm/nvm.sh
570 vim ~/.bashrc
571 source ~/.bashrc
572 nvm install 4.0
573 nvm use 4.0
574 cd ..
578 yo meanjs
579 sudo rm -rf mean/
580 yo meanjs
Also:
bash-3.2$ npm info generator-meanjs version
0.4.4
Additional information just in case:
bash-3.2$ npm install -g generator-meanjs
npm WARN deprecated npmconf#2.1.2: this package has been reintegrated into npm and is now out of date with respect to npm
> spawn-sync#1.0.15 postinstall /Users/mona/.nvm/versions/node/v4.0.0/lib/node_modules/generator-meanjs/node_modules/yeoman-generator/node_modules/cross-spawn/node_modules/spawn-sync
> node postinstall
/
> yo#1.5.1 postinstall /Users/mona/.nvm/versions/node/v4.0.0/lib/node_modules/generator-meanjs/node_modules/yo
> yodoctor
Yeoman Doctor
Running sanity checks on your system
✔ Global configuration file is valid
✔ NODE_PATH matches the npm root
✖ Node.js version
Your Node.js version is outdated.
Upgrade to the latest version: https://nodejs.org
✔ No .bowerrc file in home directory
✔ No .yo-rc.json file in home directory
✖ npm version
Your npm version is outdated.
Upgrade to the latest version by running:
npm install -g npm
Found potential issues on your machine :(
generator-meanjs#0.4.4 /Users/mona/.nvm/versions/node/v4.0.0/lib/node_modules/generator-meanjs
├── mkdirp#0.5.1 (minimist#0.0.8)
├── chalk#1.1.1 (escape-string-regexp#1.0.5, supports-color#2.0.0, strip-ansi#3.0.1, has-ansi#2.0.0, ansi-styles#2.2.0)
├── ejs#2.3.4
├── underscore.string#3.2.3
├── bluebird#3.0.6
├── underscore.inflections#0.2.1 (underscore#1.8.3)
├── rimraf#2.5.2 (glob#7.0.3)
├── lodash#4.0.1
├── html-wiring#1.2.0 (detect-newline#1.0.3, cheerio#0.19.0)
├── yeoman-generator#0.21.1 (read-chunk#1.0.1, detect-conflict#1.0.0, yeoman-welcome#1.0.1, path-is-absolute#1.0.0, text-table#0.2.0, user-home#2.0.0, xdg-basedir#2.0.0, dargs#4.1.0, class-extend#0.1.2, yeoman-assert#2.1.1, debug#2.2.0, istextorbinary#1.0.2, find-up#1.1.2, path-exists#2.1.0, async#1.5.2, nopt#3.0.6, shelljs#0.5.3, cli-table#0.3.1, glob#5.0.15, through2#2.0.1, mem-fs-editor#2.2.0, yeoman-environment#1.5.2, read-pkg-up#1.0.1, pretty-bytes#2.0.1, github-username#2.1.0, cross-spawn#2.1.5, inquirer#0.11.4, dateformat#1.0.12, download#4.4.3, gruntfile-editor#1.1.0, lodash#3.10.1, sinon#1.17.3)
└── yo#1.5.1 (titleize#1.0.0, figures#1.4.0, humanize-string#1.0.1, user-home#2.0.0, string-length#1.0.1, async#1.5.2, opn#3.0.3, repeating#2.0.0, sort-on#1.2.2, configstore#1.4.0, root-check#1.0.0, yeoman-character#1.1.0, yosay#1.1.0, npm-keyword#4.2.0, package-json#2.3.1, cross-spawn-async#2.1.9, got#5.5.0, yeoman-environment#1.5.2, fullname#2.1.0, inquirer#0.11.4, meow#3.7.0, read-pkg-up#1.0.1, update-notifier#0.5.0, insight#0.7.0, lodash#3.10.1, yeoman-doctor#2.1.0)
bash-3.2$ npm ls
# /Users/mona/interviews/mean
└── (empty)
I am confused which version of node I should eventually go with!!? As I switched back to node 4.0 to solve the problem but now yo is complaining about the version not being the latest.

Cannot find module on grunt when deploying to Heroku

This really puzzles me. Basically I set up a Go app that uses Grunt for the webapp.
I've use https://github.com/ddollar/heroku-buildpack-multi for my buildpack to combine nodejs and go buildpack and I couldn't get the nodejs buildpack to work.
I managed to install grunt and while executing my grunt task it just fails to get the module. Output from Heroku below:
Fetching repository, done.
Counting objects: 14, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 1.23 KiB | 0 bytes/s, done.
Total 10 (delta 6), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
=====> Detected Framework: Node.js
-----> Requested node range: 0.10.x
-----> Resolved node version: 0.10.30
-----> Downloading and installing node
-----> Exporting config vars to environment
-----> Installing dependencies
npm WARN optional dep failed, continuing fsevents#0.2.0
> blat#0.0.0 postinstall /tmp/build_7d4b99cb-602b-42ee-9a85-8b929a54646d
> echo postinstall time ls react; ls ./node_modules/react; echo AAA; ./node_modules/grunt-cli/bin/grunt heroku:deploy
postinstall time ls react
README.md
addons.js
dist
lib
node_modules
package.json
react.js
AAA
Loading "Gruntfile.js" tasks...ERROR
>> Error: Cannot find module 'React'
Warning: Task "heroku:deploy" not found. Use --force to continue.
Aborted due to warnings.
npm ERR! blat#0.0.0 postinstall: `echo postinstall time ls react; ls ./node_modules/react; echo AAA; ./node_modules/grunt-cli/bin/grunt heroku:deploy`
npm ERR! Exit status 3
npm ERR!
npm ERR! Failed at the blat#0.0.0 postinstall script.
npm ERR! This is most likely a problem with the blat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! echo postinstall time ls react; ls ./node_modules/react; echo AAA; ./node_modules/grunt-cli/bin/grunt heroku:deploy
npm ERR! You can get their info via:
npm ERR! npm owner ls blat
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.8.11-ec2
npm ERR! command "/tmp/build_7d4b99cb-602b-42ee-9a85-8b929a54646d/vendor/node/bin/node" "/tmp/build_7d4b99cb-602b-42ee-9a85-8b929a54646d/vendor/node/bin/npm" "install" "--userconfig" "/tmp/build_7d4b99cb-602b-42ee-9
a85-8b929a54646d/.npmrc" "--production"
npm ERR! cwd /tmp/build_7d4b99cb-602b-42ee-9a85-8b929a54646d
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/build_7d4b99cb-602b-42ee-9a85-8b929a54646d/npm-debug.log
npm ERR! not ok code 0
Note that I purposely call ls ./node_modules/react to see if it's installed and it is. But for some reason it can't find it on my node file.
My Gruntfile:
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-react')
grunt.loadNpmTasks('grunt-browserify')
// doing this for testing - fails on heroku
var react= require('React')
grunt.initConfig({
browserify: {
options: {
transform: [require('grunt-react').browserify]
},
app: {
src: 'src/app.react.js',
dest: 'public/index.js'
}
},
})
grunt.registerTask('heroku:deploy', [
'browserify:app'
])
}
And package.json file:
{
"name": "blat",
"version": "0.0.0",
"description": "",
"engines": {
"node": "0.10.x",
"npm": "1.4.x"
},
"dependencies": {
"director": "^1.2.3",
"es6-promise": "^1.0.0",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-react": "^0.9.0",
"react": "^0.11.1",
"react-router": "^0.5.2",
"superagent": "^0.18.2",
"superagent-prefix": "0.0.2"
},
"devDependencies": {},
"scripts": {
"postinstall": "echo postinstall time; ./node_modules/grunt-cli/bin/grunt heroku:deploy"
}
}
.buildpacks
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/kr/heroku-buildpack-go.git
Heroku config:
BUILDPACK_URL = https://github.com/ddollar/heroku-buildpack-multi.git
NODE_ENV = production
Does anyone know what the problem is? I can't reproduce it locally and it's so frustrating. I've tried https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt buildpack but it gives me the same result..
Ok turns out it was case sensitive issue. Apparently I was using HFS+ case insensitive format which explains why my code was working locally..

npm fails to build socket.io with Error "Not compatible with your version of node/npm: commander#0.5.0"

I cloned socket.io from https://github.com/LearnBoost/socket.io.git bit it fails with the following Message
npm http GET https://registry.npmjs.org/socket.io-client/0.9.2
npm http 304 https://registry.npmjs.org/socket.io-client/0.9.2
npm http GET https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/xmlhttprequest/1.2.2
npm http GET https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/uglify-js/1.2.5
npm http 304 https://registry.npmjs.org/xmlhttprequest/1.2.2
npm http 304 https://registry.npmjs.org/ws
npm http 304 https://registry.npmjs.org/active-x-obfuscator/0.0.1
> ws#0.4.9 preinstall /usr/src/socket.io/node_modules/socket.io-client/node_modules/ws
> make
npm http GET https://registry.npmjs.org/zeparser/0.0.5
node-waf configure build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
'configure' finished successfully (0.105s)
Waf: Entering directory `/usr/src/socket.io/node_modules/socket.io-client/node_modules/ws/build'
[1/4] cxx: src/validation.cc -> build/Release/src/validation_1.o
[2/4] cxx: src/bufferutil.cc -> build/Release/src/bufferutil_2.o
[3/4] cxx_link: build/Release/src/validation_1.o -> build/Release/validation.node
[4/4] cxx_link: build/Release/src/bufferutil_2.o -> build/Release/bufferutil.node
Waf: Leaving directory `/usr/src/socket.io/node_modules/socket.io-client/node_modules/ws/build'
'build' finished successfully (1.634s)
npm http GET https://registry.npmjs.org/commander/0.5.0
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
npm http GET https://registry.npmjs.org/zeparser/-/zeparser-0.0.5.tgz
npm http 304 https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/commander/0.5.0
npm ERR! error rolling back ws#0.4.9 Error: ENOTEMPTY, rmdir '/usr/src/socket.io/node_modules/socket.io-client/node_modules/ws'
npm ERR! error rolling back socket.io-client#0.9.2 Error: ENOTEMPTY, rmdir '/usr/src/socket.io/node_modules/socket.io-client/node_modules/ws/node_modules/options/test'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: commander#0.5.0
npm ERR! Required: {"node":">= 0.4.x < 0.7.0"}
npm ERR! Actual: {"npm":"1.1.10","node":"0.7.7-pre"}
npm ERR!
npm ERR! System Linux 2.6.38-11-generic
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /usr/src/socket.io
npm ERR! node -v v0.7.7-pre
npm ERR! npm -v 1.1.10
npm ERR! code ENOTSUP
npm ERR! message Unsupported
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /usr/src/socket.io/npm-debug.log
npm not ok
My current version of node and npm is as follows
root#abhibhat-VirtualBox:/usr/src/socket.io# node -v
v0.7.7-pre
root#abhibhat-VirtualBox:/usr/src/socket.io# npm -v
1.1.10
root#abhibhat-VirtualBox:/usr/src/socket.io#
root#abhibhat-VirtualBox:/usr/src/socket.io# uname -a
Linux abhibhat-VirtualBox 2.6.38-11-generic #50-Ubuntu SMP Mon Sep 12 21:18:14 UTC 2011 i686 i686 i386 GNU/Linux
root#abhibhat-VirtualBox:/usr/src/socket.io#
Is it that my node version is higher than the supported upper limit? If so what is the solution?
I am clueless as to how to proceed from here. Please !!HELP!!
npm -f install socket.io just solved the issue. I also checked package.json and there seems to be no upper limit "engines": { "node": ">= 0.4.0" }. Strangely I also had to issue npm -g list prior to issuing npm -f install, but how it solved the problem I am clueless.

Categories

Resources