graphql-kit / graphql-faker

🎲 Mock or extend your GraphQL API with faked data. No coding required.
MIT License
2.69k stars 225 forks source link

Deploying on Heroku #94

Open mschipperheyn opened 4 years ago

mschipperheyn commented 4 years ago

Not an expert on Docker.

I managed to deploy graphql-faker to Heroku

heroku container:login
docker tag <IMAGEID> registry.heroku.com/ <APPNAME>/web
docker push registry.heroku.com/ <APPNAME>/web
heroku container:release web --app <APPNAME>
heroku ps:scale web=1

where APPNAME is the heroku app name and IMAGEID is the local graphql-faker Docker image you created with docker-compose up -d.

docker-compose.yml

version: '3.2'

services:
  graphql-faker:
    image: apisguru/graphql-faker
    ports:
      - '9002:9002'
    container_name: graphql_faker
    command: ./my-sdl-schema.sdl
    volumes:
      - ./src/apollo/remote:/workdir

However, my issue is deploying the sdl schema along with the image. Bc it's currently referenced locally for development but the image deploy doesn't include the schema and hence I get the default schema on Heroku.

mschipperheyn commented 4 years ago

Ok, I figured it out. Here's what you do.

Create a Dockerfile

FROM mhart/alpine-node:12

WORKDIR /usr/src/app

COPY ./src/apollo/remote/my-schema.sdl /usr/src/app

RUN npm install -g graphql-faker

EXPOSE 9002

CMD graphql-faker ./my-schema.sdl

Login to heroku on the command line

heroku container:login

We are now going to run the image locally and push it to heroku.

docker build .
# run locally and test that it works
docker run -d -p 9002:9002 <IMAGEID>
docker tag <IMAGEID> registry.heroku.com/<HEROKU PROJECT NAME>/web
docker push registry.heroku.com/<HEROKU PROJECT NAME>/web
heroku ps:scale web=1

And you're live at HEROKU PROJECT NAME.herokuapp.com/graphql

@IvanGoncharov recommend adding this to the docs.

IvanGoncharov commented 4 years ago

@mschipperheyn Thanks for investigation, we should definitely include this into README 👍 Do you want to work on PR to add it?

FROM mhart/alpine-node:12

Can you use our official docker image as a base: https://hub.docker.com/r/apisguru/graphql-faker

That way you can cut a couple lines from your Dockerfile and have a faster build.

mschipperheyn commented 4 years ago

@IvanGoncharov Sure

mschipperheyn commented 4 years ago

https://github.com/APIs-guru/graphql-faker/pull/95

clintgossett commented 3 years ago

Hello All, I tried the "docker" route and did not have much luck. Mainly because I'm not up-to-speed with docker.

What did work for me was simply deploying an NPM project to my Heroku application and Heroku detects that it's an NPM app, performs the install of graphql-faker and runs the graphql-faker run command.

Here are the steps: 1) create a directory to store your graphql-faker-deployment project 2) create package.json file with these contents.

{
    "name": "graphql-faker-deploy",
    "version": "0.0.1",
    "description": "",
    "dependencies": {
        "graphql-faker": "^2.0.0-rc.23"
     },
    "devDependencies": {},
    "scripts": {
        "start": "graphql-faker -p ${PORT:=9002} --forward-headers Authorization --extend {URL_TO_YOUR_GRAPHQ_ ENDPOINT} ./temp.faker.graphql"
     },
    "author": "",
    "license": "ISC"
}

-- Now follow the standard Heroku deployment flow (re: https://devcenter.heroku.com/articles/deploying-nodejs)

3) Git init the project directory 4) Commit the files 4) Set remote named 'heroku' to git URI of your Heroku app 5) Git push to Heroku remote