Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
강동현
2021-06-11 00:41:10 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
d3953a89079b0e06ff01fc0c651540527ef934c6
d3953a89
2 parents
4d493af3
69834b7c
Builds for 1 pipeline
failed
in 1 minute 12 seconds
Merge branch 'feature/environment' into develop
Changes
8
Builds
2
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
31 deletions
.gitlab-ci.yml
docker-compose.yml
server/Dockerfile
server/Server.ts
server/index.ts
web/Dockerfile
web/default.conf
web/src/contexts/SocketContext.ts
.gitlab-ci.yml
View file @
d3953a8
...
...
@@ -13,20 +13,7 @@ Test Server:
-
yarn install
-
yarn test
Build
Server
:
Build
:
stage
:
build
script
:
-
cd common
-
yarn install
-
cd ../server
-
yarn install
-
yarn build
Build Web
:
stage
:
build
script
:
-
cd common
-
yarn install
-
cd ../web
-
npm install
-
npm build
-
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
...
...
docker-compose.yml
View file @
d3953a8
...
...
@@ -10,11 +10,20 @@ services:
-
"
3000:3000"
volumes
:
-
/etc/letsencrypt:/etc/letsencrypt
environment
:
-
SSL_CERT=${SSL_CERT}
-
SSL_KEY=${SSL_KEY}
-
SSL_CA=${SSL_CA}
web
:
build
:
context
:
.
dockerfile
:
./web/Dockerfile
args
:
-
HOST=${HOST}
-
SSL_CERT=${SSL_CERT}
-
SSL_KEY=${SSL_KEY}
-
SSL_CA=${SSL_CA}
restart
:
unless-stopped
ports
:
-
"
443:443"
...
...
server/Dockerfile
View file @
d3953a8
...
...
@@ -18,4 +18,6 @@ RUN yarn build
EXPOSE
3000
ENV
NODE_ENV production
CMD
[ "node", "dist/server/index.js" ]
...
...
server/Server.ts
View file @
d3953a8
import
express
from
"express"
;
import
socketIo
,
{
Server
as
IoServer
}
from
"socket.io"
;
import
{
createServer
}
from
"https"
;
import
{
createServer
as
createServerHttps
}
from
"https"
;
import
{
createServer
as
createServerHttp
}
from
"http"
;
import
{
RoomManager
}
from
"./room/RoomManager"
;
import
{
Connection
}
from
"./connection/Connection"
;
import
{
SocketIoWrapper
}
from
"./connection/SocketWrapper"
;
...
...
@@ -13,21 +14,22 @@ export class Server {
constructor
(
port
:
number
)
{
this
.
port
=
port
;
console
.
log
(
`Running in
${
process
.
env
.
NODE_ENV
}
mode.`
);
const
app
=
express
();
const
server
=
createServer
(
let
server
;
if
(
process
.
env
.
NODE_ENV
===
"development"
)
{
server
=
createServerHttp
(
app
);
}
else
{
server
=
createServerHttps
(
{
cert
:
readFileSync
(
"/etc/letsencrypt/live/2020105578.oss2021.tk/cert.pem"
),
key
:
readFileSync
(
"/etc/letsencrypt/live/2020105578.oss2021.tk/privkey.pem"
),
ca
:
readFileSync
(
"/etc/letsencrypt/live/2020105578.oss2021.tk/fullchain.pem"
),
cert
:
readFileSync
(
process
.
env
.
SSL_CERT
as
string
),
key
:
readFileSync
(
process
.
env
.
SSL_KEY
as
string
),
ca
:
readFileSync
(
process
.
env
.
SSL_CA
as
string
),
},
app
);
}
this
.
io
=
new
socketIo
.
Server
(
server
,
{
cors
:
{
origin
:
"*"
,
...
...
server/index.ts
View file @
d3953a8
import
{
Server
}
from
"./Server"
;
process
.
env
.
NODE_ENV
=
process
.
env
.
NODE_ENV
&&
process
.
env
.
NODE_ENV
.
trim
().
toLowerCase
()
==
"production"
?
"production"
:
"development"
;
new
Server
(
3000
);
...
...
web/Dockerfile
View file @
d3953a8
...
...
@@ -16,7 +16,18 @@ RUN yarn build
FROM
nginx:latest
COPY web/default.conf /etc/nginx/conf.d/default.conf
ARG HOST
ENV
HOST ${HOST}
ARG SSL_CERT
ENV
SSL_CERT ${SSL_CERT}
ARG SSL_KEY
ENV
SSL_KEY ${SSL_KEY}}
ARG SSL_CA
ENV
SSL_CA ${SSL_CA}}
COPY web/default.conf /etc/nginx/conf.d/default_temp
RUN
envsubst < /etc/nginx/conf.d/default_temp > /etc/nginx/conf.d/default.conf
COPY --from=build /usr/web/build /usr/web/build
EXPOSE
443
...
...
web/default.conf
View file @
d3953a8
...
...
@@ -5,10 +5,10 @@ server {
server
{
listen
443
ssl
default_server
;
server_name
2020105578
.
oss2021
.
tk
;
server_name
$
HOST
;
ssl_certificate
/
etc
/
letsencrypt
/
live
/
2020105578
.
oss2021
.
tk
/
fullchain
.
pem
;
ssl_certificate_key
/
etc
/
letsencrypt
/
live
/
2020105578
.
oss2021
.
tk
/
privkey
.
pem
;
ssl_certificate
$
SSL_CA
;
ssl_certificate_key
$
SSL_KEY
;
location
/ {
root
/
usr
/
web
/
build
;
...
...
web/src/contexts/SocketContext.ts
View file @
d3953a8
import
React
from
"react"
;
import
{
io
}
from
"socket.io-client"
;
export
const
socket
=
io
(
`https://
${
window
.
location
.
hostname
}
:3000/`
);
export
const
socket
=
io
(
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
:3000/`
);
const
SocketContext
=
React
.
createContext
(
socket
);
export
const
SocketProvider
=
SocketContext
.
Provider
;
...
...
Please
register
or
login
to post a comment