Browse Source

Add container for web

ghorsington 4 years ago
parent
commit
4cca234d1d
11 changed files with 106 additions and 116 deletions
  1. 3 1
      .dockerignore
  2. 11 0
      .vscode/launch.json
  3. 8 2
      Makefile
  4. 28 0
      db/src/entities.ts
  5. 19 0
      docker-compose.yml
  6. 27 0
      web/Dockerfile
  7. 0 88
      web/README.md
  8. 0 18
      web/appveyor.yml
  9. 4 1
      web/rollup.config.js
  10. 5 5
      web/src/server.ts
  11. 1 1
      web/tsconfig.json

+ 3 - 1
.dockerignore

@@ -12,4 +12,6 @@ docker-compose*
 */obj
 README.md
 LICENSE
-.vscode
+.vscode
+__sapper__/
+.rpt2_cache/

+ 11 - 0
.vscode/launch.json

@@ -17,6 +17,17 @@
             "env": {
                 "NODE_ENV": "dev"
             }
+        },
+        {
+            "type": "node",
+            "request": "launch",
+            "name": "Launch WebServer",
+            "program": "${workspaceFolder}/web/node_modules/sapper/dist/cli.js",
+            "args": [
+                "dev"
+            ],
+            "cwd": "${workspaceFolder}/web",
+            "autoAttachChildProcesses": true
         }
     ]
 }

+ 8 - 2
Makefile

@@ -5,6 +5,9 @@ build_db:
 build_bot: build_db
 	cd bot && npm run build
 
+build_web: build_db
+	cd web && npm run build
+
 build:
 	docker-compose build
 
@@ -12,7 +15,10 @@ start_db: build
 	docker-compose up db adminer
 
 start: build
-	docker-compose up db adminer noctbot
+	docker-compose up db adminer noctbot web
 
 start_bot: build
-	docker-compose up db adminer noctbot
+	docker-compose up db adminer noctbot
+
+start_web: build
+	docker-compose up db adminer web

+ 28 - 0
db/src/entities.ts

@@ -0,0 +1,28 @@
+import { AggroNewsItem } from "./entity/AggroNewsItem";
+import { DeadChatReply } from "./entity/DeadChatReply";
+import { FaceCaptionMessage } from "./entity/FaceCaptionMessage";
+import { Guide, GuideKeyword } from "./entity/Guide";
+import { KnownChannel } from "./entity/KnownChannel";
+import { KnownUser, User, UserRole } from "./entity/KnownUser";
+import { MessageReaction } from "./entity/MessageReaction";
+import { PostedForumNewsItem } from "./entity/PostedForumsNewsItem";
+import { PostVerifyMessage } from "./entity/PostVerifyMessage";
+import { Quote } from "./entity/Quote";
+import { ReactionEmote } from "./entity/ReactionEmote";
+
+export const DB_ENTITIES = [
+    AggroNewsItem,
+    DeadChatReply,
+    FaceCaptionMessage,
+    Guide,
+    GuideKeyword,
+    KnownChannel,
+    KnownUser,
+    User,
+    UserRole,
+    MessageReaction,
+    PostedForumNewsItem,
+    PostVerifyMessage,
+    Quote,
+    ReactionEmote
+];

+ 19 - 0
docker-compose.yml

@@ -27,6 +27,25 @@ services:
     ports:
       - 3000:3000
 
+  web:
+    image: noctbot_web
+    build:
+      context: ./
+      dockerfile: ./web/Dockerfile
+    restart: on-failure
+    depends_on:
+      - db
+    env_file:
+      - .env
+      - db.env
+    environment:
+      NODE_ENV: production
+      TYPEORM_USERNAME: ${DB_USERNAME}
+      TYPEORM_PASSWORD: ${DB_PASSWORD}
+      TYPEORM_DATABASE: ${DB_NAME}
+    ports:
+      - 8181:3000
+
   db:
     image: postgres
     restart: always

+ 27 - 0
web/Dockerfile

@@ -0,0 +1,27 @@
+FROM node:10-alpine
+
+RUN apk --no-cache add make
+
+WORKDIR /app
+
+COPY ./db/package.json ./db/package.json
+WORKDIR /app/db
+RUN npm install
+
+WORKDIR /app
+
+COPY ./web/package.json ./web/package.json
+WORKDIR /app/web
+RUN npm install
+
+WORKDIR /app
+
+COPY ./db ./db
+COPY ./web ./web
+COPY ./Makefile ./Makefile
+
+RUN make build_web
+
+WORKDIR /app/web
+EXPOSE 3000
+CMD npm start

+ 0 - 88
web/README.md

@@ -1,88 +0,0 @@
-# sapper-template
-
-The default [Sapper](https://github.com/sveltejs/sapper) template, with branches for Rollup and webpack. To clone it and get started:
-
-```bash
-# for Rollup
-npx degit "sveltejs/sapper-template#rollup" my-app
-# for webpack
-npx degit "sveltejs/sapper-template#webpack" my-app
-cd my-app
-npm install # or yarn!
-npm run dev
-```
-
-Open up [localhost:3000](http://localhost:3000) and start clicking around.
-
-Consult [sapper.svelte.dev](https://sapper.svelte.dev) for help getting started.
-
-
-## Structure
-
-Sapper expects to find two directories in the root of your project —  `src` and `static`.
-
-
-### src
-
-The [src](src) directory contains the entry points for your app — `client.js`, `server.js` and (optionally) a `service-worker.js` — along with a `template.html` file and a `routes` directory.
-
-
-#### src/routes
-
-This is the heart of your Sapper app. There are two kinds of routes — *pages*, and *server routes*.
-
-**Pages** are Svelte components written in `.svelte` files. When a user first visits the application, they will be served a server-rendered version of the route in question, plus some JavaScript that 'hydrates' the page and initialises a client-side router. From that point forward, navigating to other pages is handled entirely on the client for a fast, app-like feel. (Sapper will preload and cache the code for these subsequent pages, so that navigation is instantaneous.)
-
-**Server routes** are modules written in `.js` files, that export functions corresponding to HTTP methods. Each function receives Express `request` and `response` objects as arguments, plus a `next` function. This is useful for creating a JSON API, for example.
-
-There are three simple rules for naming the files that define your routes:
-
-* A file called `src/routes/about.svelte` corresponds to the `/about` route. A file called `src/routes/blog/[slug].svelte` corresponds to the `/blog/:slug` route, in which case `params.slug` is available to the route
-* The file `src/routes/index.svelte` (or `src/routes/index.js`) corresponds to the root of your app. `src/routes/about/index.svelte` is treated the same as `src/routes/about.svelte`.
-* Files and directories with a leading underscore do *not* create routes. This allows you to colocate helper modules and components with the routes that depend on them — for example you could have a file called `src/routes/_helpers/datetime.js` and it would *not* create a `/_helpers/datetime` route
-
-
-### static
-
-The [static](static) directory contains any static assets that should be available. These are served using [sirv](https://github.com/lukeed/sirv).
-
-In your [service-worker.js](app/service-worker.js) file, you can import these as `files` from the generated manifest...
-
-```js
-import { files } from '@sapper/service-worker';
-```
-
-...so that you can cache them (though you can choose not to, for example if you don't want to cache very large files).
-
-
-## Bundler config
-
-Sapper uses Rollup or webpack to provide code-splitting and dynamic imports, as well as compiling your Svelte components. With webpack, it also provides hot module reloading. As long as you don't do anything daft, you can edit the configuration files to add whatever plugins you'd like.
-
-
-## Production mode and deployment
-
-To start a production version of your app, run `npm run build && npm start`. This will disable live reloading, and activate the appropriate bundler plugins.
-
-You can deploy your application to any environment that supports Node 8 or above. As an example, to deploy to [Now](https://zeit.co/now), run these commands:
-
-```bash
-npm install -g now
-now
-```
-
-
-## Using external components
-
-When using Svelte components installed from npm, such as [@sveltejs/svelte-virtual-list](https://github.com/sveltejs/svelte-virtual-list), Svelte needs the original component source (rather than any precompiled JavaScript that ships with the component). This allows the component to be rendered server-side, and also keeps your client-side app smaller.
-
-Because of that, it's essential that the bundler doesn't treat the package as an *external dependency*. You can either modify the `external` option under `server` in [rollup.config.js](rollup.config.js) or the `externals` option in [webpack.config.js](webpack.config.js), or simply install the package to `devDependencies` rather than `dependencies`, which will cause it to get bundled (and therefore compiled) with your app:
-
-```bash
-npm install -D @sveltejs/svelte-virtual-list
-```
-
-
-## Bugs and feedback
-
-Sapper is in early development, and may have the odd rough edge here and there. Please be vocal over on the [Sapper issue tracker](https://github.com/sveltejs/sapper/issues).

+ 0 - 18
web/appveyor.yml

@@ -1,18 +0,0 @@
-version: "{build}"
-
-shallow_clone: true
-
-init:
-  - git config --global core.autocrlf false
-
-build: off
-
-environment:
-  matrix:
-    # node.js
-    - nodejs_version: stable
-
-install:
-  - ps: Install-Product node $env:nodejs_version
-  - npm install cypress
-  - npm install

+ 4 - 1
web/rollup.config.js

@@ -62,7 +62,10 @@ export default {
 
 	server: {
 		input: { server: config.server.input().server.replace(/\.js$/, '.ts') },
-		output: config.server.output(),
+		output: {
+			...config.server.output(),
+			sourcemap: process.env.NODE_ENV == "development"
+		},
 		plugins: [
 			replace({
 				'process.browser': false,

+ 5 - 5
web/src/server.ts

@@ -4,6 +4,7 @@ import { createConnection, getRepository, getConnectionOptions } from "typeorm";
 import express from "express";
 import dotenv from "dotenv";
 import { KnownUser } from "@db/entity/KnownUser";
+import { DB_ENTITIES } from "@db/entities";
 
 if(process.env.NODE_ENV == "development") {
 	console.log(process.cwd());
@@ -16,16 +17,15 @@ if(process.env.NODE_ENV == "development") {
     process.env.TYPEORM_HOST = "localhost";
     process.env.TYPEORM_USERNAME = process.env.DB_USERNAME;
     process.env.TYPEORM_PASSWORD = process.env.DB_PASSWORD;
-    process.env.TYPEORM_DATABASE = process.env.DB_NAME;
+	process.env.TYPEORM_DATABASE = process.env.DB_NAME;
 }
 
 
 const PORT = +(process.env.PORT as string);
 async function main() {
-	let opts = await getConnectionOptions();
 	await createConnection({
-		...opts,
-		entities: [ KnownUser ]
+		...await getConnectionOptions(),
+		entities: DB_ENTITIES
 	});
 
 	let repo = getRepository(KnownUser);
@@ -37,7 +37,7 @@ async function main() {
 	else
 		console.log(`No user found!`);
 
-	express() // You can also use Express
+	express()
 		.use(
 			compression({ threshold: 0 }),
 			express.static("static"),

+ 1 - 1
web/tsconfig.json

@@ -6,10 +6,10 @@
         "removeComments": true,
         "preserveConstEnums": true,
         "moduleResolution": "node",
-        "sourceMap": true,
         "outDir": "build",
         "lib": ["es2018", "dom"],
         "esModuleInterop": true,
+        "sourceMap": true,
         "target": "es2018",
         "emitDecoratorMetadata": true,
         "experimentalDecorators": true,