graphql-faker icon indicating copy to clipboard operation
graphql-faker copied to clipboard

Deploying on Heroku

Open mschipperheyn opened this issue 6 years ago • 5 comments

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 avatar Feb 14 '20 21:02 mschipperheyn

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.

mschipperheyn avatar Feb 16 '20 12:02 mschipperheyn

@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.

IvanGoncharov avatar Feb 16 '20 14:02 IvanGoncharov

@IvanGoncharov Sure

mschipperheyn avatar Feb 17 '20 11:02 mschipperheyn

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

mschipperheyn avatar Feb 17 '20 16:02 mschipperheyn

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)

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

clintgossett avatar Nov 19 '20 15:11 clintgossett