Skip to content

Commit db1590f

Browse files
m-allansonKyleAMathews
authored andcommitted
Add Dockerfile to start GraphiQL using www's data (gatsbyjs#3992)
1 parent a12677e commit db1590f

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
**/node_modules
3+
**/public
4+
npm-debug.log
5+
.git

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Create a standalone instance of GraphiQL populated with gatsbyjs.org's data
2+
# ---
3+
# libvips needed for image manipulation
4+
FROM marcbachmann/libvips:8.4.1 as build
5+
6+
# Node.js version 8 and build tools for sharp
7+
RUN apt-get update && apt-get install -y build-essential g++ curl
8+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/*
9+
10+
RUN npm install -g [email protected]
11+
12+
WORKDIR /usr/src/app
13+
14+
COPY . .
15+
RUN yarn && cd www && yarn
16+
RUN cd www && yarn run build
17+
18+
# Start again and just copy across the built files (+ node_modules)
19+
# TODO: Can we do this all on Alpine for a much smaller image? This node:8 image is ~600MB
20+
FROM node:8 as dist
21+
22+
COPY --from=build /usr/src/app /usr/src/app
23+
WORKDIR /usr/src/app
24+
25+
# To run this image, set the port as an env var with `-e PORT=xxxx` e.g.
26+
# docker run -p 8080:8080 --rm -it -e PORT=8080 <registryUsername>/<imageName>
27+
CMD [ "node","./scripts/www-data-explorer.js" ]

packages/gatsby/src/commands/data-explorer.js

-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const express = require(`express`)
44
const graphqlHTTP = require(`express-graphql`)
55
const { store } = require(`../redux`)
66
const bootstrap = require(`../bootstrap`)
7-
const { GraphQLSchema } = require(`graphql`)
87

98
module.exports = async (program: any) => {
109
let { port, host } = program
@@ -15,11 +14,6 @@ module.exports = async (program: any) => {
1514

1615
const schema = store.getState().schema
1716

18-
console.log(
19-
`Schema is instance of GraphQLSchema?`,
20-
schema instanceof GraphQLSchema
21-
)
22-
2317
const app = express()
2418
app.use(
2519
`/`,

scripts/www-data-explorer.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const path = require(`path`)
2+
const gatsbyPath = path.resolve(
3+
__dirname,
4+
`..`,
5+
`www`,
6+
`node_modules`,
7+
`gatsby`,
8+
`dist`
9+
)
10+
const explorer = require(path.resolve(
11+
gatsbyPath,
12+
`commands`,
13+
`data-explorer.js`
14+
))
15+
16+
const port = process.env.PORT || 8080
17+
const host = `0.0.0.0`
18+
const directory = path.join(__dirname, `..`, `www`)
19+
const sitePackageJson = require(path.join(directory, `package.json`))
20+
21+
explorer({
22+
port,
23+
host,
24+
directory,
25+
sitePackageJson,
26+
})

0 commit comments

Comments
 (0)