Builds for
1 pipeline
failed
in
1 minute 12 seconds
Merge branch 'feature/environment' into develop
Showing
8 changed files
with
50 additions
and
31 deletions
... | @@ -13,20 +13,7 @@ Test Server: | ... | @@ -13,20 +13,7 @@ Test Server: |
13 | - yarn install | 13 | - yarn install |
14 | - yarn test | 14 | - yarn test |
15 | 15 | ||
16 | -Build Server: | 16 | +Build: |
17 | stage: build | 17 | stage: build |
18 | script: | 18 | script: |
19 | - - cd common | 19 | + - HOST=2020105578.oss2021.tk SSL_CERT=/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem SSL_KEY=/etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem SSL_CA=/etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem docker-compose build --no-cache |
20 | - - yarn install | ||
21 | - - cd ../server | ||
22 | - - yarn install | ||
23 | - - yarn build | ||
24 | - | ||
25 | -Build Web: | ||
26 | - stage: build | ||
27 | - script: | ||
28 | - - cd common | ||
29 | - - yarn install | ||
30 | - - cd ../web | ||
31 | - - npm install | ||
32 | - - npm build | ... | ... |
... | @@ -10,11 +10,20 @@ services: | ... | @@ -10,11 +10,20 @@ services: |
10 | - "3000:3000" | 10 | - "3000:3000" |
11 | volumes: | 11 | volumes: |
12 | - /etc/letsencrypt:/etc/letsencrypt | 12 | - /etc/letsencrypt:/etc/letsencrypt |
13 | + environment: | ||
14 | + - SSL_CERT=${SSL_CERT} | ||
15 | + - SSL_KEY=${SSL_KEY} | ||
16 | + - SSL_CA=${SSL_CA} | ||
13 | 17 | ||
14 | web: | 18 | web: |
15 | build: | 19 | build: |
16 | context: . | 20 | context: . |
17 | dockerfile: ./web/Dockerfile | 21 | dockerfile: ./web/Dockerfile |
22 | + args: | ||
23 | + - HOST=${HOST} | ||
24 | + - SSL_CERT=${SSL_CERT} | ||
25 | + - SSL_KEY=${SSL_KEY} | ||
26 | + - SSL_CA=${SSL_CA} | ||
18 | restart: unless-stopped | 27 | restart: unless-stopped |
19 | ports: | 28 | ports: |
20 | - "443:443" | 29 | - "443:443" | ... | ... |
1 | import express from "express"; | 1 | import express from "express"; |
2 | import socketIo, { Server as IoServer } from "socket.io"; | 2 | import socketIo, { Server as IoServer } from "socket.io"; |
3 | -import { createServer } from "https"; | 3 | +import { createServer as createServerHttps } from "https"; |
4 | +import { createServer as createServerHttp } from "http"; | ||
4 | import { RoomManager } from "./room/RoomManager"; | 5 | import { RoomManager } from "./room/RoomManager"; |
5 | import { Connection } from "./connection/Connection"; | 6 | import { Connection } from "./connection/Connection"; |
6 | import { SocketIoWrapper } from "./connection/SocketWrapper"; | 7 | import { SocketIoWrapper } from "./connection/SocketWrapper"; |
... | @@ -13,21 +14,22 @@ export class Server { | ... | @@ -13,21 +14,22 @@ export class Server { |
13 | constructor(port: number) { | 14 | constructor(port: number) { |
14 | this.port = port; | 15 | this.port = port; |
15 | 16 | ||
17 | + console.log(`Running in ${process.env.NODE_ENV} mode.`); | ||
18 | + | ||
16 | const app = express(); | 19 | const app = express(); |
17 | - const server = createServer( | 20 | + let server; |
21 | + if (process.env.NODE_ENV === "development") { | ||
22 | + server = createServerHttp(app); | ||
23 | + } else { | ||
24 | + server = createServerHttps( | ||
18 | { | 25 | { |
19 | - cert: readFileSync( | 26 | + cert: readFileSync(process.env.SSL_CERT as string), |
20 | - "/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem" | 27 | + key: readFileSync(process.env.SSL_KEY as string), |
21 | - ), | 28 | + ca: readFileSync(process.env.SSL_CA as string), |
22 | - key: readFileSync( | ||
23 | - "/etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem" | ||
24 | - ), | ||
25 | - ca: readFileSync( | ||
26 | - "/etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem" | ||
27 | - ), | ||
28 | }, | 29 | }, |
29 | app | 30 | app |
30 | ); | 31 | ); |
32 | + } | ||
31 | this.io = new socketIo.Server(server, { | 33 | this.io = new socketIo.Server(server, { |
32 | cors: { | 34 | cors: { |
33 | origin: "*", | 35 | origin: "*", | ... | ... |
... | @@ -16,7 +16,18 @@ RUN yarn build | ... | @@ -16,7 +16,18 @@ RUN yarn build |
16 | 16 | ||
17 | FROM nginx:latest | 17 | FROM nginx:latest |
18 | 18 | ||
19 | -COPY web/default.conf /etc/nginx/conf.d/default.conf | 19 | +ARG HOST |
20 | +ENV HOST ${HOST} | ||
21 | +ARG SSL_CERT | ||
22 | +ENV SSL_CERT ${SSL_CERT} | ||
23 | +ARG SSL_KEY | ||
24 | +ENV SSL_KEY ${SSL_KEY}} | ||
25 | +ARG SSL_CA | ||
26 | +ENV SSL_CA ${SSL_CA}} | ||
27 | + | ||
28 | +COPY web/default.conf /etc/nginx/conf.d/default_temp | ||
29 | +RUN envsubst < /etc/nginx/conf.d/default_temp > /etc/nginx/conf.d/default.conf | ||
30 | + | ||
20 | COPY --from=build /usr/web/build /usr/web/build | 31 | COPY --from=build /usr/web/build /usr/web/build |
21 | 32 | ||
22 | EXPOSE 443 | 33 | EXPOSE 443 | ... | ... |
... | @@ -5,10 +5,10 @@ server { | ... | @@ -5,10 +5,10 @@ server { |
5 | 5 | ||
6 | server { | 6 | server { |
7 | listen 443 ssl default_server; | 7 | listen 443 ssl default_server; |
8 | - server_name 2020105578.oss2021.tk; | 8 | + server_name $HOST; |
9 | 9 | ||
10 | - ssl_certificate /etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem; | 10 | + ssl_certificate $SSL_CA; |
11 | - ssl_certificate_key /etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem; | 11 | + ssl_certificate_key $SSL_KEY; |
12 | 12 | ||
13 | location / { | 13 | location / { |
14 | root /usr/web/build; | 14 | root /usr/web/build; | ... | ... |
1 | import React from "react"; | 1 | import React from "react"; |
2 | import { io } from "socket.io-client"; | 2 | import { io } from "socket.io-client"; |
3 | 3 | ||
4 | -export const socket = io(`https://${window.location.hostname}:3000/`); | 4 | +export const socket = io( |
5 | + `${window.location.protocol}//${window.location.hostname}:3000/` | ||
6 | +); | ||
5 | const SocketContext = React.createContext(socket); | 7 | const SocketContext = React.createContext(socket); |
6 | 8 | ||
7 | export const SocketProvider = SocketContext.Provider; | 9 | export const SocketProvider = SocketContext.Provider; | ... | ... |
-
Please register or login to post a comment