Skip to content

Commit 03591d7

Browse files
initial commit
0 parents  commit 03591d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+21225
-0
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 * * 0'
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test-server:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 10
16+
17+
strategy:
18+
matrix:
19+
node-version:
20+
- 20
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
26+
- name: Use Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
31+
- name: Install dependencies
32+
working-directory: ./server
33+
run: npm ci
34+
35+
- name: Run tests
36+
working-directory: ./server
37+
run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2023 The Socket.IO team
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Socket.IO chat platform
2+
3+
A basic chat platform based on [Socket.IO](https://socket.io/).
4+
5+
Table of contents:
6+
7+
<!-- TOC -->
8+
* [How to use](#how-to-use)
9+
* [Development](#development)
10+
* [Server](#server)
11+
* [Client](#client)
12+
* [Licence](#licence)
13+
<!-- TOC -->
14+
15+
## How to use
16+
17+
```shell
18+
$ docker compose up -d
19+
```
20+
21+
Then go to http://localhost:8080
22+
23+
## Development
24+
25+
### Server
26+
27+
```shell
28+
$ cd server
29+
30+
# start the PostgreSQL database
31+
$ docker compose up -d
32+
33+
# start the server
34+
$ npm run dev
35+
```
36+
37+
### Client
38+
39+
```shell
40+
$ cd vue-client
41+
42+
# start the client
43+
$ npm run dev
44+
```
45+
46+
Then go to http://localhost:5173
47+
48+
## Licence
49+
50+
[MIT](./LICENSE)

compose.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
services:
2+
nginx:
3+
build:
4+
context: .
5+
dockerfile: nginx/Dockerfile
6+
ports:
7+
- "8080:80"
8+
depends_on:
9+
- backend01
10+
- backend02
11+
- backend03
12+
13+
backend01:
14+
build:
15+
context: ./server
16+
depends_on:
17+
db:
18+
condition: service_healthy
19+
20+
backend02:
21+
build:
22+
context: ./server
23+
depends_on:
24+
db:
25+
condition: service_healthy
26+
27+
backend03:
28+
build:
29+
context: ./server
30+
depends_on:
31+
db:
32+
condition: service_healthy
33+
34+
db:
35+
image: postgres:14
36+
environment:
37+
POSTGRES_PASSWORD: "changeit"
38+
healthcheck:
39+
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
40+
interval: 5s
41+
timeout: 5s
42+
retries: 5

nginx/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### BUILD ###
2+
FROM node:20-alpine AS builder
3+
4+
WORKDIR /tmp
5+
6+
COPY ../vue-client/package*.json .
7+
8+
RUN npm ci
9+
10+
COPY ../vue-client/ .
11+
12+
RUN npm run build
13+
14+
### RUN ###
15+
FROM nginx:1.25
16+
17+
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
18+
19+
COPY --from=builder /tmp/dist/ /usr/share/nginx/html/

nginx/nginx.conf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
upstream socket_io_nodes {
2+
hash $remote_addr consistent;
3+
4+
server backend01:3000;
5+
server backend02:3000;
6+
server backend03:3000;
7+
}
8+
9+
server {
10+
listen 80;
11+
12+
root /usr/share/nginx/html;
13+
index index.html;
14+
15+
location / {
16+
try_files $uri $uri/ /index.html;
17+
18+
expires 0;
19+
add_header Cache-Control "no-cache, no-store, must-revalidate";
20+
}
21+
22+
location ~* \.(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot)$ {
23+
expires 1y;
24+
add_header Pragma public;
25+
add_header Cache-Control public;
26+
}
27+
28+
location /api/ {
29+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
30+
proxy_set_header Host $host;
31+
32+
proxy_pass http://socket_io_nodes/;
33+
34+
proxy_http_version 1.1;
35+
proxy_set_header Upgrade $http_upgrade;
36+
proxy_set_header Connection upgrade;
37+
}
38+
}

server/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
test/
3+
index.js

server/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM node:20-alpine
2+
3+
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
4+
5+
WORKDIR /home/node/app
6+
7+
COPY package*.json ./
8+
9+
USER node
10+
11+
RUN npm ci --omit=dev
12+
13+
COPY --chown=node:node . .
14+
15+
EXPOSE 3000
16+
17+
CMD [ "node", "entrypoint.js" ]

server/compose.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
postgres:
3+
image: postgres:14
4+
ports:
5+
- "5432:5432"
6+
environment:
7+
POSTGRES_PASSWORD: "changeit"

0 commit comments

Comments
 (0)