If anyone have any tips/ guidance I would be super...
# prisma-whats-new
m
If anyone have any tips/ guidance I would be super happy!
n
hiho, nice to meet you again 😄 check https://www.prismagraphql.com/docs/quickstart/ for getting started!
m
Thanks! I’m trying to accomplish this with docker. Have you tried that?
a
This, for example, is the guide that describes how to deploy the Prisma service via Docker.
m
I see @andre . Im currently trying to figure out how I can deploy it with KnexJS.
a
You mean the SQL query builder?
m
Yes, Im having trouble with connecting docker to my postgres db. @andre
Btw are you swedish?
a
Ah okay, so your question targets nothing Graphcool / Prisma specific?
m
Actually no 😅 . I want to deploy this project first and then start testing Prisma.
a
No, I’m not swedish. Sorry 🙂
No worries 🙂
m
Its alright. Just noticed the letter “ö” in your lastname.
a
haha .. Ah good point. It is the German Umlaut
ö
.
So, I’m from Germany 🙂
Are you running both of your applications in containers? I mean the actual app on one and the database in the other?
m
Well my frontend is react with the Apollo client. So I just started that with
npm start
. And I’m trying to run my whole server inside of a docker container.
a
I see. So the best practice in container land is to put each of your components into separate containers and link them together.
m
I believe that my Dockerfile and my docker-compose file are correct. And the problem lays here:
connection: '<postgres://localhost/devblog>'
. How I establish my connection.
a
In general: Docker spans an own network for your containers so that you can reach each of them my it’s name. Can you provide your
docker-compose.yml
file here?
m
Yes ofc!
Copy code
version: "3"
services:
  redis:
    image: redis
    networks:
      - webnet
  db:
    image: postgres
    networks:
      - webnet
    environment:
      POSTGRES_PASSWORD: password
      POSTGRES_USER: martinnord
      POSTGRES_DB: devblog
  web:
    image: devblog-server
    ports:
      - 3010:3010
    networks:
      - webnet
    environment:
      DB_HOST: db
      REDIS_HOST: redis
    command: ["./wait-for-it.sh", "db:5432", "--", "node", "index.js"]
networks:
  webnet:
a
Okay, cool. Thanks. So that looks pretty good. You passed the correct names as environment variables.
db
is actually the hostname with which you can reach the database from other containers.
Everything is configured correctly. In your application, you have to read the
DB_HOST
environment variable and pass it to your database connector.
m
So you can say that a container is an environment?
a
No, not exactly.
m
okey
a
In the
environment
section you define
environment variables
which can be used by the actual application that runs within the container.
m
So I have to grab the
db
and then pass it into my knexfile
a
exactly
m
so isn’t it like
connection: '<postgres://db/devblog>'
?
a
You can access environment variables in Node.js via
process.env.<VAR>
So in your case:
process.env.DB_HOST
The actual connection string would then look like:
postgres://${process.env.DB_HOST}/devblog
m
and then the
DB_HOST
variables value will be
db
?
a
Yap
m
I’m still getting
Knex: Timeout acquiring a connection. The pool is probably full.
. :S
I tried to rebuild it and ran
docker-compose up
a
Please note that my example above should be an ES2015 template string.
A string with backticks.
m
Yes I know.
a
Can you post the full stack trace?
m
What I get when I run
docker-compose up
?
a
Yeah
m
Copy code
Recreating backend_web_1 ...
Starting backend_db_1 ...
Starting backend_db_1 ... done
Attaching to backend_web_1, backend_redis_1, backend_db_1
web_1    | wait-for-it.sh: waiting 15 seconds for db:5432
redis_1  | 1:C 12 Feb 14:35:54.163 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1  | 1:C 12 Feb 14:35:54.170 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 12 Feb 14:35:54.171 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1  | 1:M 12 Feb 14:35:54.174 * Running mode=standalone, port=6379.
redis_1  | 1:M 12 Feb 14:35:54.175 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 12 Feb 14:35:54.175 # Server initialized
redis_1  | 1:M 12 Feb 14:35:54.179 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1  | 1:M 12 Feb 14:35:54.187 * DB loaded from disk: 0.008 seconds
redis_1  | 1:M 12 Feb 14:35:54.188 * Ready to accept connections
db_1     | 2018-02-12 14:35:54.299 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1     | 2018-02-12 14:35:54.300 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1     | 2018-02-12 14:35:54.310 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1     | 2018-02-12 14:35:54.358 UTC [20] LOG:  database system was interrupted; last known up at 2018-02-12 14:04:32 UTC
web_1    | wait-for-it.sh: db:5432 is available after 2 seconds
db_1     | 2018-02-12 14:35:54.929 UTC [21] LOG:  incomplete startup packet
db_1     | 2018-02-12 14:35:55.090 UTC [20] LOG:  database system was not properly shut down; automatic recovery in progress
db_1     | 2018-02-12 14:35:55.103 UTC [20] LOG:  redo starts at 0/1634B00
db_1     | 2018-02-12 14:35:55.104 UTC [20] LOG:  invalid record length at 0/1634B38: wanted 24, got 0
db_1     | 2018-02-12 14:35:55.105 UTC [20] LOG:  redo done at 0/1634B00
db_1     | 2018-02-12 14:35:55.190 UTC [1] LOG:  database system is ready to accept connections
web_1    |
web_1    |       App listening on 3010
web_1    |       Env: undefined
Thanks for taking your time btw
a
You’re welcome 🙂 Hm, could you put a
console.log(process.env.DB_HOST)
in the section where you start your application? Your application entry point.
m
yes
1sec
hmm sorry if I might be super stupid. But I added that console.log in my
index.js
file and when I run
docker-compose up
I got no output, but when I just
npm run dev
I can see it saying
db
there
a
Ah now, I see the problem.
No worries, all good 🙂
So:
When you change your application, you also have to create a new Docker image out of it.
m
you mean i have to build it again? Like
docker build -t devblog-server .
a
So in your case, I would suggest changing your
web
as follows:
Sec
Copy code
web:
    image: node:8-alpine
    command: “node /app/index.js”
    volumes:
      - “.:/app”
    working_dir: “/app”
    ports:
      - 3010:3010
    environment:
      DB_HOST: db
      REDIS_HOST: redis
This mounts the directory (where the
docker-compose.yml
lives) into the container at
/app
it will execute node within the container then.
Please note that you might adjust the
volume
mounting
.:/app
to match your needs.
m
Well I cant see no
map
dir here 😅
well
a
Sorry, can’t follow. What do you mean?
m
This is what I get now
Copy code
Pulling web (node:8-alpine)...
8-alpine: Pulling from library/node
605ce1bd3f31: Already exists
d6ade540dd0b: Pull complete
7608b7ec7a5f: Pull complete
Digest: sha256:b1e1f024dccf7058d2f55b21d6bf65c9cb932ba7bee2a24eca08ddb7c654312b
Status: Downloaded newer image for node:8-alpine
Recreating backend_web_1 ...
Starting backend_db_1 ...
Recreating backend_web_1 ... done
Attaching to backend_db_1, backend_redis_1, backend_web_1
db_1     | 2018-02-12 14:57:16.427 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1     | 2018-02-12 14:57:16.427 UTC [1] LOG:  listening on IPv6 address "::", port 5432
redis_1  | 1:C 12 Feb 14:57:16.400 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
db_1     | 2018-02-12 14:57:16.430 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
redis_1  | 1:C 12 Feb 14:57:16.400 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 12 Feb 14:57:16.400 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
db_1     | 2018-02-12 14:57:16.444 UTC [21] LOG:  database system was interrupted; last known up at 2018-02-12 14:48:43 UTC
redis_1  | 1:M 12 Feb 14:57:16.401 * Running mode=standalone, port=6379.
web_1    | env: can't execute 'bash': No such file or directory
db_1     | 2018-02-12 14:57:16.580 UTC [21] LOG:  database system was not properly shut down; automatic recovery in progress
redis_1  | 1:M 12 Feb 14:57:16.401 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 12 Feb 14:57:16.401 # Server initialized
redis_1  | 1:M 12 Feb 14:57:16.401 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
db_1     | 2018-02-12 14:57:16.582 UTC [21] LOG:  invalid record length at 0/1634CC0: wanted 24, got 0
redis_1  | 1:M 12 Feb 14:57:16.401 * DB loaded from disk: 0.000 seconds
redis_1  | 1:M 12 Feb 14:57:16.401 * Ready to accept connections
db_1     | 2018-02-12 14:57:16.583 UTC [21] LOG:  redo is not required
db_1     | 2018-02-12 14:57:16.596 UTC [1] LOG:  database system is ready to accept connections
backend_web_1 exited with code 127
a
What does
docker logs backend_web_1
gives you?
m
is that a command I can run in the terminal?
a
yes
m
env: can't execute 'bash': No such file or directory
a
Do you have a
shebang
in the first line of the
index.js
?
m
I only have a bunch of imports
a
Do you have the repo online? Hard to debug in that way 🙂
m
yes! I can push the latest changes
a
👍
Thanks a lot mister!
a
Sure 🙂
I will create PR. Give me sec.
m
alright
a
Afterwards, the application runs in a container. You have to restart the containers whenever you make a change in your application.
So
npm run build && docker-compose up
This can be optimized by using tools like `nodemon`: https://github.com/remy/nodemon
But in fact the application runs.
In order to interact with your GraphQL API, you have to use tools like https://github.com/skevy/graphiql-app
m
So I have to use that and not the one you get?
a
What do you mean?
So, you can merge my PR and start your setup.
m
yeah I merged it and pulled it
a
In order to interact with your application, you have to use tools like
GraphQL Playground
or
GraphiQL
.
m
I used
npm run build && docker-compose up
oh yeah I understand what you mean
a
👍
m
Well I tried to run it but it keeps loading… Did it work out for you?
a
Yeah, it works on my machine.
m
And you sawed
Copy code
App listening on 3010
Env: undefined
and then you got data?
when you did a simple query?
a
I didn’t perform a query. I just made sure that the setups works in a containerized fashion.
m
I see. It still timesout when I try something
a
Which query do you perform?
m
just getAllPosts
a
Give me a sec.
m
thanks
a
Puh, don’t see any problem to be honest. Database information gets passed correctly.
m
Its weird. Probably something really dumb is missing. I tried just to run it with
npm run dev
and it also times out
a
Hm, yeah, strange.
m
This is really driving me nuts 😅
a
Ya 😞
m
@andre it’s the
host
in the
connection
object who’s messing it up
a
Oh really? How comes?
m
I dont know! I just tried putting
localhost
there instead of
process.env.DB_HOST
and it worked when I tried
npm run dev
again
a
Ah okay, sure, when you are running it via
npm run dev
. Yes, in this case the application runs on your machine instead of in a container on your machine.
m
yes, it still wont work with docker