From db1590f485e997b3226a87afd98f0562fddb3acc Mon Sep 17 00:00:00 2001 From: Mike Allanson Date: Mon, 12 Feb 2018 19:29:32 +0000 Subject: [PATCH] Add Dockerfile to start GraphiQL using www's data (#3992) --- .dockerignore | 5 ++++ Dockerfile | 27 +++++++++++++++++++ packages/gatsby/src/commands/data-explorer.js | 6 ----- scripts/www-data-explorer.js | 26 ++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 scripts/www-data-explorer.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000..dfa967bce0359 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +**/node_modules +**/public +npm-debug.log +.git \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000..b5e28c88503e2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Create a standalone instance of GraphiQL populated with gatsbyjs.org's data +# --- +# libvips needed for image manipulation +FROM marcbachmann/libvips:8.4.1 as build + +# Node.js version 8 and build tools for sharp +RUN apt-get update && apt-get install -y build-essential g++ curl +RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* + +RUN npm install -g yarn@1.3.2 + +WORKDIR /usr/src/app + +COPY . . +RUN yarn && cd www && yarn +RUN cd www && yarn run build + +# Start again and just copy across the built files (+ node_modules) +# TODO: Can we do this all on Alpine for a much smaller image? This node:8 image is ~600MB +FROM node:8 as dist + +COPY --from=build /usr/src/app /usr/src/app +WORKDIR /usr/src/app + +# To run this image, set the port as an env var with `-e PORT=xxxx` e.g. +# docker run -p 8080:8080 --rm -it -e PORT=8080 / +CMD [ "node","./scripts/www-data-explorer.js" ] \ No newline at end of file diff --git a/packages/gatsby/src/commands/data-explorer.js b/packages/gatsby/src/commands/data-explorer.js index cb85d8b33932a..7ceba053dc904 100644 --- a/packages/gatsby/src/commands/data-explorer.js +++ b/packages/gatsby/src/commands/data-explorer.js @@ -4,7 +4,6 @@ const express = require(`express`) const graphqlHTTP = require(`express-graphql`) const { store } = require(`../redux`) const bootstrap = require(`../bootstrap`) -const { GraphQLSchema } = require(`graphql`) module.exports = async (program: any) => { let { port, host } = program @@ -15,11 +14,6 @@ module.exports = async (program: any) => { const schema = store.getState().schema - console.log( - `Schema is instance of GraphQLSchema?`, - schema instanceof GraphQLSchema - ) - const app = express() app.use( `/`, diff --git a/scripts/www-data-explorer.js b/scripts/www-data-explorer.js new file mode 100644 index 0000000000000..a75d251691ee9 --- /dev/null +++ b/scripts/www-data-explorer.js @@ -0,0 +1,26 @@ +const path = require(`path`) +const gatsbyPath = path.resolve( + __dirname, + `..`, + `www`, + `node_modules`, + `gatsby`, + `dist` +) +const explorer = require(path.resolve( + gatsbyPath, + `commands`, + `data-explorer.js` +)) + +const port = process.env.PORT || 8080 +const host = `0.0.0.0` +const directory = path.join(__dirname, `..`, `www`) +const sitePackageJson = require(path.join(directory, `package.json`)) + +explorer({ + port, + host, + directory, + sitePackageJson, +})