question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to expose graphql oasgraph in Docker image?

See original GitHub issue

I am creating an application in loopback 4, using graphql.

The problem I have is that I can not expose graphql oasgraph in Docker image

I have two options: 1 - Create a new dockerfile to expose graphql. 2 - Use the same loopback dockerfile to expose port 3000 (Explorer API at http://127.0.0.1:3000/explorer), and 3001 for graphql (http://127.0.0.1:3001/graphql).

How can I configure my dockerfile, in order to expose the graphql server?

https://loopback.io/doc/en/lb4/exposing-graphql-apis.html

This is my dockerfile

FIRST OPTION

# Check out https://hub.docker.com/_/node to select a new base image
FROM hasura/graphql-engine

# Create app directory (with user `node`)
RUN mkdir -p /home/node/app

WORKDIR /home/node/app

RUN npm i -g openapi-to-graphql-cli

RUN npx oasgraph http://localhost:3000/openapi.json/

# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3001

EXPOSE ${PORT}

CMD [ "npx", "oasgraph", "http://localhost:3000/openapi.json/" ]

SECOND OPTION:

# Check out https://hub.docker.com/_/node to select a new base image
##FROM node:10-slim
## node con oracle instant client
FROM collinestes/docker-node-oracle

# Set to a non-root built-in user `node`
USER node

# Create app directory (with user `node`)
RUN mkdir -p /home/node/app

WORKDIR /home/node/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=node package*.json ./

RUN npm install
# Install openapi-to-graphql-cli 
RUN npm i openapi-to-graphql-cli


# Bundle app source code
COPY --chown=node . .

RUN npm run build

# RUN oasgraph 
RUN npx oasgraph http://localhost:3000/openapi.json/

# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3000

EXPOSE ${PORT}

CMD [ "node", "." ]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dhmlaucommented, Jul 26, 2019

Cross posting from: https://github.com/strongloop/loopback-next/issues/3346#issuecomment-515555994

@fga8, I might have a working Dockerfile for you:

# Check out https://hub.docker.com/_/node to select a new base image
FROM node:10-slim

# Set to a non-root built-in user `node`
USER node

# Create app directory (with user `node`)
RUN mkdir -p /home/node/app

WORKDIR /home/node/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY --chown=node package*.json ./

RUN npm install
RUN npm install openapi-to-graphql-cli

# Bundle app source code
COPY --chown=node . .

RUN npm run build

# Bind to all network interfaces so that it can be mapped to the host OS
ENV HOST=0.0.0.0 PORT=3000 PORT2=3001 .  <--- Change this line to add PORT2 here

EXPOSE ${PORT}
EXPOSE ${PORT2} <----- Add this line


CMD (npm start &) ; (sleep 5) ; (npx openapi-to-graphql http://0.0.0.0:3000/openapi.json -p 3001) <--- Change this line

I’ve indicated 3 places that you need to make changes if you’re using the Dockerfile generated by the LoopBack cli. Please note that I’m not a docker expert, so what I have above is something that works, you might be able to find a better solution.

For the sake of posterity, let me mention a few challenges:

  1. oasgraph has been deprecated and the new module is openapi-to-graphql
  2. In order to make sure openapi-to-graphql is not using the same port as LB, I’ve used -p option to specify the port number. (Thanks @ErikWittern)
  3. I find the sleep in the CMD is needed, otherwise openapi-to-graphql will get started before the openapi is ready from LB.

Hope it helps!

0reactions
Alan-Chacommented, Jul 16, 2019

Unfortunately, we currently do not have any example Dockerfiles. With the changes that Erik suggested, were you able to make any improvements?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A better way to develop your GraphQL API using Docker + ...
A the end of this tutorial, you will have a GraphQL API exposing data from a PostgreSQL database, both running locally on your...
Read more >
Containerizing the Apollo Router - Apollo GraphQL Docs
Here's a basic example of running a router image with Docker (make sure to replace <image version> with whichever version you want to...
Read more >
How to Deploy a GraphQL API in a Contained Environment ...
You create a YAML file to configure a set of services, based either on existing images (from public sources such as Docker Hub...
Read more >
Generating GraphQL-Wrappers for REST(-like) APIs
OASGraph takes as input an OpenAPI Specification (OAS) describing an existing REST(-like) web API and generates a GraphQL wrapper for it.
Read more >
Announcing LoopBack 4 GA is Now Ready for Production Use!
You can use this tool to expose GraphQL endpoints from your application's REST ... Introducing an Inversion of Control (IoC) container and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found