fastify / fastify-example-twitter

Fastify example - clone twitter
MIT License
270 stars 49 forks source link

Running 'docker-compose up' gives 'microservice' script missing error #29

Open manisuec opened 5 years ago

manisuec commented 5 years ago

Running 'docker-compose up' gives 'microservice' script missing error. Seems the 'CMD' command in docker file needs update.

interactivenyc commented 5 years ago

I'm having this problem too. @manisuec - did you ever solve this problem?

manisuec commented 5 years ago

I will work on this today or tomorrow, was occupied with other tasks.

interactivenyc commented 5 years ago

This is a SUPER SWEET repo, by the way. I love how it's Dockerized and like your project setup with the React front end inside the Node back end, both with their own package.json files. Big props!

interactivenyc commented 5 years ago

@manisuec - I happen to be studying these technologies right now for my job, particularly Docker and Fastify. I've never used NGINX, though I've set up Apache and other types of servers. Can you tell me where I should be digging around to try to solve this problem?

I dug into the bash shell of the nginx container and saw this structure:

[stevewarren] docker run -t -i nginx /bin/bash
root@7f412211dbe5:/# ls -la
total 72
drwxr-xr-x   1 root root 4096 Mar 16 14:42 .
drwxr-xr-x   1 root root 4096 Mar 16 14:42 ..
-rwxr-xr-x   1 root root    0 Mar 16 14:42 .dockerenv
drwxr-xr-x   2 root root 4096 Feb 28 00:00 bin
drwxr-xr-x   2 root root 4096 Feb  3 13:01 boot
drwxr-xr-x   5 root root  360 Mar 16 14:42 dev
drwxr-xr-x   1 root root 4096 Mar 16 14:42 etc
drwxr-xr-x   2 root root 4096 Feb  3 13:01 home
drwxr-xr-x   1 root root 4096 Feb 28 00:00 lib
drwxr-xr-x   2 root root 4096 Feb 28 00:00 lib64
drwxr-xr-x   2 root root 4096 Feb 28 00:00 media
drwxr-xr-x   2 root root 4096 Feb 28 00:00 mnt
drwxr-xr-x   2 root root 4096 Feb 28 00:00 opt
dr-xr-xr-x 189 root root    0 Mar 16 14:42 proc
drwx------   2 root root 4096 Feb 28 00:00 root
drwxr-xr-x   3 root root 4096 Feb 28 00:00 run
drwxr-xr-x   2 root root 4096 Feb 28 00:00 sbin
drwxr-xr-x   2 root root 4096 Feb 28 00:00 srv
dr-xr-xr-x  13 root root    0 Mar 16 02:15 sys
drwxrwxrwt   1 root root 4096 Mar  5 04:34 tmp
drwxr-xr-x   1 root root 4096 Feb 28 00:00 usr
drwxr-xr-x   1 root root 4096 Feb 28 00:00 var

I did a find on nginx.* and found this:

root@fc48784d84d3:/# find . -name nginx.*
./var/lib/systemd/deb-systemd-helper-enabled/nginx.service.dsh-also
./var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/nginx.service
./var/lib/dpkg/info/nginx.postinst
./var/lib/dpkg/info/nginx.list
./var/lib/dpkg/info/nginx.prerm
./var/lib/dpkg/info/nginx.postrm
./var/lib/dpkg/info/nginx.md5sums
./var/lib/dpkg/info/nginx.preinst
./var/lib/dpkg/info/nginx.conffiles
./etc/systemd/system/multi-user.target.wants/nginx.service
./etc/nginx/nginx.conf
./lib/systemd/system/nginx.service

I tried doing a ps and a top to see if I could identify the running processes on the container, and both commands didn't work.

root@7f412211dbe5:/# ps -fe
bash: ps: command not found
root@7f412211dbe5:/# top
bash: top: command not found

If you would be so kind as to enlighten me about how this part works, I'll help you bang on it further.

Thanks!

manisuec commented 5 years ago

@interactivenyc My apologies, I went on a sudden vacation and also due to bad health, couldn't work on it. Your findings on nginx container looks interesting. I will dig upon these this week for sure.

Regarding your comment that frontend lying inside backend project server, I prefer to keep them at the same level of the project. Also, use 'concurrently' npm module. It helps run both backend and frontend from the same terminal.

manisuec commented 5 years ago

@interactivenyc Added "scripts": { "microservice": "fastify" } in package.json file. The above error is gone, however, the services are not coming up.

Getting below logs, will dig more further. e.g.

> server@1.0.0 microservice /usr/src/app
user_1_82dc56d611b9 | > fastify "--port" "80" "--log-level" "debug" "--prefix" "/api/user" "user/index.js"
user_1_82dc56d611b9 | 
user_1_82dc56d611b9 | no such help file
user_1_82dc56d611b9 | 
user_1_82dc56d611b9 | Fastify command line interface available commands are:
user_1_82dc56d611b9 | 
user_1_82dc56d611b9 |   * start         start a server
user_1_82dc56d611b9 |   * generate      generate a new project
user_1_82dc56d611b9 |   * readme        generate a README.md for the plugin
user_1_82dc56d611b9 |   * version       the current fastify-cli version
user_1_82dc56d611b9 |   * help          help about commands
user_1_82dc56d611b9 | 
user_1_82dc56d611b9 | Launch 'fastify help [command]' to learn more about each command.
user_1_82dc56d611b9 | npm info lifecycle server@1.0.0~postmicroservice: server@1.0.0
user_1_82dc56d611b9 | npm info ok 
docker_user_1_82dc56d611b9 exited with code 0
alayo commented 5 years ago

Same issue. Looks like your missing the microservice script in pacakage.json