How to push graph to Apollo Graph Manager with travis and docker
Ok, while I was typing my own question in stackoverflow, I came up with the solution. Since, I already finished typing my question, I decided to share the solution.
It turns out an easy solution is simply adding 5 lines of code in after_deploy
in .travis.yml
file. npm run dev &
: this runs the node server in backgroundAfterwards sleep 3
gives the server some time to turn on.Finally the last code pushes the new graphql schema to Apollo Graph Manager. Note that in your travis-ci.com's settings, you have to add apollo's ENGINE_API_KEY
as environment variable. Also note that your node server can print out some connection errors. In my case I did not provide, redis and mongodb connection related environment variables. But as long as the server itself is running for introspection, apollo service:push
will work fine.
sudo: requiredservices: - dockerenv: global: - SHA=$(git rev-parse HEAD) - CLOUDSDK_CORE_DISABLE_PROMPTS=1language: node_jsnode_js: - 10before_install: - openssl aes-256-cbc -K $encrypted_9f3b5599b056_key -iv $encrypted_9f3b5599b056_iv -in service-account.json.enc -out service-account.json -d - curl https://sdk.cloud.google.com | bash > /dev/null; - source $HOME/google-cloud-sdk/path.bash.inc - gcloud components update kubectl - gcloud auth activate-service-account --key-file service-account.json - gcloud config set project salading-production - gcloud config set compute/zone asia-northeast3-a - gcloud container clusters get-credentials salading-cluster - echo "$SHA" - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdinscript: - echo "skipping tests"deploy: provider: script script: bash ./deploy.sh on: branch: masterafter_deploy: - npm install - npm i -g apollo - npm run dev & - sleep 3 - apollo service:push --serviceURL=http://auth-cluster-ip-service --serviceName=auth --endpoint=http://localhost:3051