diff --git a/Dockerfile b/Dockerfile index ed107656..6a0d0829 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,29 +3,21 @@ ################################## FROM node:14 as build -RUN mkdir -p /opt/build; +RUN mkdir -p /opt/build WORKDIR /opt/build -# Would be a bit simpler if the code was inside a top-level src folder -COPY ./backend ./backend -COPY ./components ./components -COPY ./pages ./pages -COPY ./public ./public -COPY ./shims ./shims -COPY ./transforms ./transforms +COPY ./src ./src COPY [ \ "babel.config.js", \ - "frontend.js", \ "next.config.js", \ "package.json", \ - "theme.js", \ "yarn.lock", \ "./" \ ] -RUN yarn install \ - && yarn build +RUN yarn install && \ + yarn build ################################## # Dependencies @@ -40,15 +32,21 @@ RUN DEBIAN_FRONTEND=noninteractive \ libpango1.0-dev \ libjpeg-dev \ libgif-dev \ - librsvg2-dev + librsvg2-dev && \ + \ + rm -rf /var/lib/apt/lists/* ENV NODE_ENV='production' -RUN mkdir -p /opt/build; +RUN mkdir -p /opt/build WORKDIR /opt/build -COPY --from=build [ "/opt/build/package.json", "/opt/build/yarn.lock", "./" ] +COPY --from=build [ \ + "/opt/build/package.json", \ + "/opt/build/yarn.lock", \ + "./" \ +] RUN yarn install --production=true @@ -64,12 +62,11 @@ RUN chmod +x /tini ENV NODE_ENV='production' -RUN mkdir -p /opt/app; +RUN mkdir -p /opt/app WORKDIR /opt/app COPY --from=build /opt/build/.next /opt/app/.next -COPY --from=build /opt/build/frontend.js /opt/app/ COPY --from=build /opt/build/lib /opt/app/lib COPY --from=build /opt/build/public /opt/app/public COPY --from=dependencies /opt/build/node_modules /opt/app/node_modules diff --git a/package.json b/package.json index f0f97330..99f98661 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,16 @@ "start": "NODE_ENV=production node lib/index.js", "build": "npm run build:all", "build:frontend-for-production": "next build", - "build:server": "babel backend -d lib", + "build:server": "babel src -d lib", "build:all": "npm run build:server && npm run build:frontend-for-production", "prepublishOnly": "npm run build:all", "test": "jest" }, "bin": { - "commuter": "bin.js" + "commuter": "lib/bin.js" + }, + "jest": { + "testRegex": "tests" }, "repository": "nteract/nteract", "keywords": [ diff --git a/backend/config.js b/src/backend/config.js similarity index 100% rename from backend/config.js rename to src/backend/config.js diff --git a/backend/content-providers/gcs/contents.js b/src/backend/content-providers/gcs/contents.js similarity index 100% rename from backend/content-providers/gcs/contents.js rename to src/backend/content-providers/gcs/contents.js diff --git a/backend/content-providers/gcs/files.js b/src/backend/content-providers/gcs/files.js similarity index 100% rename from backend/content-providers/gcs/files.js rename to src/backend/content-providers/gcs/files.js diff --git a/backend/content-providers/gcs/gcs.js b/src/backend/content-providers/gcs/gcs.js similarity index 100% rename from backend/content-providers/gcs/gcs.js rename to src/backend/content-providers/gcs/gcs.js diff --git a/backend/content-providers/gcs/index.js b/src/backend/content-providers/gcs/index.js similarity index 100% rename from backend/content-providers/gcs/index.js rename to src/backend/content-providers/gcs/index.js diff --git a/backend/content-providers/local/contents.js b/src/backend/content-providers/local/contents.js similarity index 100% rename from backend/content-providers/local/contents.js rename to src/backend/content-providers/local/contents.js diff --git a/backend/content-providers/local/files.js b/src/backend/content-providers/local/files.js similarity index 100% rename from backend/content-providers/local/files.js rename to src/backend/content-providers/local/files.js diff --git a/backend/content-providers/local/fs.js b/src/backend/content-providers/local/fs.js similarity index 100% rename from backend/content-providers/local/fs.js rename to src/backend/content-providers/local/fs.js diff --git a/backend/content-providers/local/index.js b/src/backend/content-providers/local/index.js similarity index 100% rename from backend/content-providers/local/index.js rename to src/backend/content-providers/local/index.js diff --git a/backend/content-providers/s3/contents.js b/src/backend/content-providers/s3/contents.js similarity index 100% rename from backend/content-providers/s3/contents.js rename to src/backend/content-providers/s3/contents.js diff --git a/backend/content-providers/s3/files.js b/src/backend/content-providers/s3/files.js similarity index 100% rename from backend/content-providers/s3/files.js rename to src/backend/content-providers/s3/files.js diff --git a/backend/content-providers/s3/index.js b/src/backend/content-providers/s3/index.js similarity index 100% rename from backend/content-providers/s3/index.js rename to src/backend/content-providers/s3/index.js diff --git a/backend/content-providers/s3/s3.js b/src/backend/content-providers/s3/s3.js similarity index 100% rename from backend/content-providers/s3/s3.js rename to src/backend/content-providers/s3/s3.js diff --git a/backend/discovery-providers/elasticsearch/elasticSearch.js b/src/backend/discovery-providers/elasticsearch/elasticSearch.js similarity index 100% rename from backend/discovery-providers/elasticsearch/elasticSearch.js rename to src/backend/discovery-providers/elasticsearch/elasticSearch.js diff --git a/backend/discovery-providers/elasticsearch/index.js b/src/backend/discovery-providers/elasticsearch/index.js similarity index 100% rename from backend/discovery-providers/elasticsearch/index.js rename to src/backend/discovery-providers/elasticsearch/index.js diff --git a/backend/discovery-providers/none/index.js b/src/backend/discovery-providers/none/index.js similarity index 100% rename from backend/discovery-providers/none/index.js rename to src/backend/discovery-providers/none/index.js diff --git a/backend/resources/commuter.es.mapping.json b/src/backend/resources/commuter.es.mapping.json similarity index 100% rename from backend/resources/commuter.es.mapping.json rename to src/backend/resources/commuter.es.mapping.json diff --git a/backend/resources/generateMapping.js b/src/backend/resources/generateMapping.js similarity index 100% rename from backend/resources/generateMapping.js rename to src/backend/resources/generateMapping.js diff --git a/backend/resources/nteract.metadata.schema.json b/src/backend/resources/nteract.metadata.schema.json similarity index 100% rename from backend/resources/nteract.metadata.schema.json rename to src/backend/resources/nteract.metadata.schema.json diff --git a/backend/routes/api/index.js b/src/backend/routes/api/index.js similarity index 100% rename from backend/routes/api/index.js rename to src/backend/routes/api/index.js diff --git a/backend/routes/index.js b/src/backend/routes/index.js similarity index 100% rename from backend/routes/index.js rename to src/backend/routes/index.js diff --git a/backend/server.js b/src/backend/server.js similarity index 100% rename from backend/server.js rename to src/backend/server.js diff --git a/bin.js b/src/bin.js similarity index 68% rename from bin.js rename to src/bin.js index 052112c2..2f1e4e71 100755 --- a/bin.js +++ b/src/bin.js @@ -2,4 +2,4 @@ process.env.NODE_ENV = "production"; -require("./lib/index.js"); +require("./index.js"); diff --git a/components/body.js b/src/components/body.js similarity index 100% rename from components/body.js rename to src/components/body.js diff --git a/components/browse-header.js b/src/components/browse-header.js similarity index 100% rename from components/browse-header.js rename to src/components/browse-header.js diff --git a/components/contents/csv.js b/src/components/contents/csv.js similarity index 100% rename from components/contents/csv.js rename to src/components/contents/csv.js diff --git a/components/contents/directory-listing.js b/src/components/contents/directory-listing.js similarity index 100% rename from components/contents/directory-listing.js rename to src/components/contents/directory-listing.js diff --git a/components/contents/html.js b/src/components/contents/html.js similarity index 100% rename from components/contents/html.js rename to src/components/contents/html.js diff --git a/components/contents/index.js b/src/components/contents/index.js similarity index 100% rename from components/contents/index.js rename to src/components/contents/index.js diff --git a/components/contents/json.js b/src/components/contents/json.js similarity index 100% rename from components/contents/json.js rename to src/components/contents/json.js diff --git a/components/contents/zeppelin.js b/src/components/contents/zeppelin.js similarity index 100% rename from components/contents/zeppelin.js rename to src/components/contents/zeppelin.js diff --git a/components/header.js b/src/components/header.js similarity index 100% rename from components/header.js rename to src/components/header.js diff --git a/frontend.js b/src/frontend.js similarity index 80% rename from frontend.js rename to src/frontend.js index bb6f0081..7b21c769 100644 --- a/frontend.js +++ b/src/frontend.js @@ -1,11 +1,12 @@ // Note: this module must remain compatible with the ECMAScript version of the // Server as it does _not_ get transpiled const next = require("next"); +const path = require("path"); const dev = process.env.NODE_ENV !== "production" && !process.env.NOW; function createNextApp() { - const app = next({ dev, dir: __dirname }); + const app = next({ dev, dir: path.join(__dirname, "..") }); const handle = app.getRequestHandler(); return { diff --git a/backend/index.js b/src/index.js similarity index 85% rename from backend/index.js rename to src/index.js index e23fe060..b4b8b634 100644 --- a/backend/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ // @flow const log = require("log"); -const createServer = require("./server"); +const createServer = require("./backend/server"); createServer() .then(server => { diff --git a/pages/_document.js b/src/pages/_document.js similarity index 100% rename from pages/_document.js rename to src/pages/_document.js diff --git a/pages/discover.js b/src/pages/discover.js similarity index 100% rename from pages/discover.js rename to src/pages/discover.js diff --git a/pages/index.js b/src/pages/index.js similarity index 100% rename from pages/index.js rename to src/pages/index.js diff --git a/pages/view.js b/src/pages/view.js similarity index 100% rename from pages/view.js rename to src/pages/view.js diff --git a/shims/ajax.js b/src/shims/ajax.js similarity index 100% rename from shims/ajax.js rename to src/shims/ajax.js diff --git a/theme.js b/src/theme.js similarity index 100% rename from theme.js rename to src/theme.js diff --git a/transforms/PlotlyTransform.js b/src/transforms/PlotlyTransform.js similarity index 100% rename from transforms/PlotlyTransform.js rename to src/transforms/PlotlyTransform.js diff --git a/transforms/index.js b/src/transforms/index.js similarity index 100% rename from transforms/index.js rename to src/transforms/index.js diff --git a/__tests__/routesUtil-spec.js b/tests/routesUtil-spec.js similarity index 84% rename from __tests__/routesUtil-spec.js rename to tests/routesUtil-spec.js index a2833633..479b37f9 100644 --- a/__tests__/routesUtil-spec.js +++ b/tests/routesUtil-spec.js @@ -1,5 +1,5 @@ // @flow -const isDir = require("./../backend/content-providers/s3/contents").isDir; +const isDir = require("./../src/backend/content-providers/s3/contents").isDir; describe("Routes util tests", () => { test("returns isDir true", () => { diff --git a/__tests__/s3test.js b/tests/s3test.js similarity index 98% rename from __tests__/s3test.js rename to tests/s3test.js index 44f515f9..0434af66 100644 --- a/__tests__/s3test.js +++ b/tests/s3test.js @@ -2,7 +2,7 @@ jest.mock("aws-sdk/clients/s3"); const awsMock = require("aws-sdk/clients/s3"); -const s3Service = require("./../backend/content-providers/s3/s3"); +const s3Service = require("./../src/backend/content-providers/s3/s3"); describe("Test S3 service", () => { test("getObject returns notebook content", done => {