Browse Source

Added docker

master
Rei 11 months ago
parent
commit
df91021476
10 changed files with 108 additions and 1580 deletions
  1. 6
    0
      .dockerignore
  2. 48
    0
      Dockerfile
  3. 13
    0
      README.md
  4. 14
    0
      docker-compose.yml
  5. 0
    1555
      package-lock.json
  6. 16
    15
      package.json
  7. 1
    5
      server/dev.ts
  8. 6
    2
      server/index.ts
  9. 3
    3
      server/routes/api/meme.ts
  10. 1
    0
      src/router.ts

+ 6
- 0
.dockerignore View File

@@ -0,0 +1,6 @@
1
+node_modules
2
+.git
3
+dist
4
+*.sqlite
5
+Dockerfile
6
+.dockerignore

+ 48
- 0
Dockerfile View File

@@ -0,0 +1,48 @@
1
+FROM node:8-alpine
2
+
3
+RUN apk add \
4
+  --repository http://dl-3.alpinelinux.org/alpine/edge/testing \
5
+  python \
6
+  make \
7
+  g++ \
8
+  vips-dev \
9
+  fftw-dev
10
+
11
+ADD . /opt/build
12
+WORKDIR /opt/build
13
+
14
+RUN yarn && yarn buildServer && yarn build
15
+
16
+
17
+FROM node:8-alpine
18
+
19
+RUN apk add \
20
+  --repository http://dl-3.alpinelinux.org/alpine/edge/testing \
21
+  python \
22
+  make \
23
+  g++ \
24
+  vips-dev \
25
+  fftw-dev
26
+
27
+COPY --from=0 /opt/build/dist /opt/app/dist
28
+COPY --from=0 /opt/build/package.json /opt/build/yarn.lock  /opt/app/
29
+
30
+WORKDIR /opt/app
31
+
32
+RUN yarn install --prod
33
+
34
+# Remove dev libraries and build tools
35
+RUN apk del \
36
+  python \
37
+  make \
38
+  g++ \
39
+  vips-dev \
40
+  fftw-dev && \
41
+  apk add \
42
+  --repository http://dl-3.alpinelinux.org/alpine/edge/testing \
43
+  vips \
44
+  fftw
45
+
46
+EXPOSE 3000
47
+
48
+ENTRYPOINT [ "yarn",  "start" ]

+ 13
- 0
README.md View File

@@ -0,0 +1,13 @@
1
+# Running
2
+
3
+## Docker
4
+
5
+You can use Docker to build and run this project.
6
+
7
+Building and running:
8
+
9
+```bash
10
+docker-compose up -d --build
11
+```
12
+
13
+after that, simply go to localhost:3000 and have fun.

+ 14
- 0
docker-compose.yml View File

@@ -0,0 +1,14 @@
1
+version: "3"
2
+
3
+services:
4
+  memes:
5
+    build: .
6
+    volumes:
7
+      - images:/opt/images
8
+      - database:/opt/db
9
+    ports:
10
+      - 3000:3000
11
+
12
+volumes:
13
+  ? images
14
+  ? database

+ 0
- 1555
package-lock.json
File diff suppressed because it is too large
View File


+ 16
- 15
package.json View File

@@ -3,35 +3,29 @@
3 3
   "version": "0.1.0",
4 4
   "private": true,
5 5
   "scripts": {
6
-    "start": "tsc -p server/tsconfig.json && node ./dist/index.js",
6
+    "start": "node ./dist/index.js",
7 7
     "serve": "vue-cli-service serve",
8 8
     "build": "vue-cli-service build",
9
+    "buildServer": "tsc -p server/tsconfig.json",
9 10
     "lint": "vue-cli-service lint"
10 11
   },
11 12
   "dependencies": {
12
-    "@types/async": "^2.0.49",
13
-    "@types/bcryptjs": "^2.4.1",
14
-    "@types/express": "^4.16.0",
15
-    "@types/js-md5": "^0.4.2",
16
-    "@types/sharp": "^0.17.10",
17 13
     "async": "^2.6.1",
18 14
     "bcryptjs": "^2.4.3",
19 15
     "express": "^4.16.3",
20 16
     "js-logger": "^1.4.1",
21 17
     "js-md5": "^0.7.3",
22
-    "reflect-metadata": "^0.1.12",
23
-    "register-service-worker": "^1.0.0",
24 18
     "sequelize": "^4.38.0",
25 19
     "sequelize-typescript": "^0.6.5",
26 20
     "sharp": "^0.20.8",
27
-    "sqlite3": "^4.0.1",
28
-    "vue": "^2.5.17",
29
-    "vue-class-component": "^6.0.0",
30
-    "vue-property-decorator": "^7.0.0",
31
-    "vue-router": "^3.0.1",
32
-    "vuex": "^3.0.1"
21
+    "sqlite3": "^4.0.1"
33 22
   },
34 23
   "devDependencies": {
24
+    "@types/async": "^2.0.49",
25
+    "@types/bcryptjs": "^2.4.1",
26
+    "@types/express": "^4.16.0",
27
+    "@types/js-md5": "^0.4.2",
28
+    "@types/sharp": "^0.17.10",
35 29
     "@vue/cli-plugin-babel": "^3.0.1",
36 30
     "@vue/cli-plugin-eslint": "^3.0.1",
37 31
     "@vue/cli-plugin-pwa": "^3.0.1",
@@ -42,6 +36,13 @@
42 36
     "stylus": "^0.54.5",
43 37
     "stylus-loader": "^3.0.2",
44 38
     "typescript": "^3.0.0",
45
-    "vue-template-compiler": "^2.5.17"
39
+    "vue-template-compiler": "^2.5.17",
40
+    "vue": "^2.5.17",
41
+    "vue-class-component": "^6.0.0",
42
+    "vue-property-decorator": "^7.0.0",
43
+    "vue-router": "^3.0.1",
44
+    "vuex": "^3.0.1",
45
+    "reflect-metadata": "^0.1.12",
46
+    "register-service-worker": "^1.0.0"
46 47
   }
47 48
 }

+ 1
- 5
server/dev.ts View File

@@ -1,9 +1,5 @@
1 1
 import { Sequelize } from 'sequelize-typescript'
2 2
 
3
-import { User } from './models/User'
4
-
5 3
 export const createDevDB = async (sequelize: Sequelize) => {
6
-  await sequelize.sync({ force: true })
7
-
8
-  await new User({ username: 'rei', password: 'testpass' }).save()
4
+  await sequelize.sync()
9 5
 }

+ 6
- 2
server/index.ts View File

@@ -18,7 +18,11 @@ app.use(appendFullURL)
18 18
 app.use('/', routes)
19 19
 app.use('/', express.static(path.join(__dirname, 'public')))
20 20
 
21
-app.use('/img', express.static('/tmp'))
21
+app.use('/img', express.static('/opt/images'))
22
+
23
+app.get('*', (req, res) =>
24
+  res.sendFile(path.join(__dirname, 'public', 'index.html'))
25
+)
22 26
 
23 27
 app.use(logErrors)
24 28
 app.use(sendErrors)
@@ -28,7 +32,7 @@ const sequelize = new Sequelize({
28 32
   dialect: 'sqlite',
29 33
   username: 'root',
30 34
   password: '',
31
-  storage: path.join(__dirname, '..', 'test.sqlite'),
35
+  storage: path.join('/', 'opt', 'db', 'memes.sqlite'),
32 36
   modelPaths: [__dirname + '/models']
33 37
 })
34 38
 

+ 3
- 3
server/routes/api/meme.ts View File

@@ -20,14 +20,14 @@ const create = async (req: express.Request, res: express.Response) => {
20 20
 
21 21
   await sharp(buffer)
22 22
     .jpeg()
23
-    .toFile(`/tmp/${name}.jpg`)
24
-  console.log("TEST")
23
+    .toFile(`/opt/images/${name}.jpg`)
24
+  console.log('TEST')
25 25
 
26 26
   // Create thumbnail
27 27
   await sharp(buffer)
28 28
     .jpeg({ quality: 25 })
29 29
     .resize(128, 128)
30
-    .toFile(`/tmp/${name}-thumb.jpg`)
30
+    .toFile(`/opt/images/${name}-thumb.jpg`)
31 31
 
32 32
   res.send(
33 33
     await new Meme({

+ 1
- 0
src/router.ts View File

@@ -8,6 +8,7 @@ import Upload from './views/Upload.vue'
8 8
 Vue.use(Router)
9 9
 
10 10
 export default new Router({
11
+  mode: 'history',
11 12
   routes: [
12 13
     { path: '/', name: 'home', component: Home },
13 14
     { path: '/upload', name: 'upload', component: Upload },

Loading…
Cancel
Save