Skip to content

Commit 5acb833

Browse files
open source sv-socket
0 parents  commit 5acb833

Some content is hidden

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

60 files changed

+16142
-0
lines changed

.env.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
REDIS_URL=
2+
SOCKET_PORT=
3+
HTTP_PORT=
4+
AWS_ACESS_KEY_ID=
5+
AWS_SECRET_ACCESS_KEY=
6+
AWS_REGION=
7+
ADMIN_USERNAME=
8+
ADMIN_PASSWORD=
9+
10+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=
11+
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL=
12+
13+
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=
14+
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL=
15+
16+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=
17+
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=
18+
19+
ENVIRONMENT

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
build
3+
config
4+
/*.js

.eslintrc.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"node": true,
5+
"jest": true
6+
},
7+
"plugins": [
8+
"@typescript-eslint",
9+
"import",
10+
"import-helpers",
11+
"prettier"
12+
],
13+
"extends": [
14+
"airbnb-typescript/base",
15+
"prettier",
16+
"plugin:@typescript-eslint/recommended",
17+
"plugin:import/typescript"
18+
],
19+
"parser": "@typescript-eslint/parser",
20+
"parserOptions": {
21+
"project": "./tsconfig.json"
22+
},
23+
"rules": {
24+
"prettier/prettier": "error",
25+
"@typescript-eslint/naming-convention": [
26+
"error",
27+
{
28+
"selector": "interface",
29+
"format": [
30+
"PascalCase"
31+
]
32+
}
33+
],
34+
"@typescript-eslint/no-unused-vars": [
35+
"error",
36+
{
37+
"argsIgnorePattern": "^_",
38+
"varsIgnorePattern": "^_",
39+
"caughtErrorsIgnorePattern": "^_"
40+
}
41+
],
42+
"import/extensions": [
43+
"error",
44+
"ignorePackages",
45+
{
46+
"ts": "never"
47+
}
48+
],
49+
"import-helpers/order-imports": [
50+
"warn",
51+
{
52+
"newlinesBetween": "always", // new line between groups
53+
"groups": [
54+
"module",
55+
"/^@shared/",
56+
[
57+
"parent",
58+
"sibling",
59+
"index"
60+
]
61+
],
62+
"alphabetize": {
63+
"order": "asc",
64+
"ignoreCase": true
65+
}
66+
}
67+
]
68+
},
69+
"settings": {
70+
"import/resolver": {
71+
"typescript": {}
72+
}
73+
}
74+
}

.github/workflows/deploy.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
production:
11+
name: "Deployment"
12+
runs-on: "ubuntu-latest"
13+
if: github.ref == 'refs/heads/main'
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Configure AWS credentials
20+
uses: aws-actions/configure-aws-credentials@v1
21+
with:
22+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
23+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
24+
aws-region: ${{ secrets.AWS_REGION }}
25+
26+
- name: Login ECR
27+
id: login-ecr
28+
uses: aws-actions/amazon-ecr-login@v1
29+
30+
- name: Build, tag, and push image to Amazon ECR
31+
id: build-image
32+
env:
33+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
34+
ECR_REPOSITORY: dev-sv-socket-repository
35+
IMAGE_TAG: latest
36+
run: |
37+
# Build a docker container and push it to ECR
38+
docker build --build-arg OTEL_SERVICE_NAME=sv-socket -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
39+
echo "Pushing image to ECR..."
40+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
41+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
42+
- name: Download task definition
43+
run: |
44+
aws ecs describe-task-definition --task-definition dev-sv-socket-task \
45+
--query taskDefinition > task-definition.json
46+
- name: Fill in the new image ID in the Amazon ECS task definition
47+
id: task-def
48+
uses: aws-actions/amazon-ecs-render-task-definition@v1
49+
with:
50+
task-definition: task-definition.json
51+
container-name: dev-sv-socket-container
52+
image: ${{ steps.build-image.outputs.image }}
53+
54+
- name: Deploy Amazon ECS task definition
55+
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
56+
with:
57+
task-definition: ${{ steps.task-def.outputs.task-definition }}
58+
service: ${{ secrets.ECS_SERVICE }}
59+
cluster: ${{ secrets.ECS_CLUSTER }}
60+
wait-for-service-stability: true
61+
forceNewDeployment: true
62+
slack:
63+
needs: production
64+
name: Slack Notification
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v3
68+
- name: Slack Notification
69+
uses: rtCamp/action-slack-notify@v2
70+
env:
71+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
72+
SLACK_ICON: https://avatars.slack-edge.com/2020-11-18/1496892993975_af721d1c045bea2d5a46_48.png
73+
MSG_MINIMAL: true
74+
SLACK_USERNAME: Deploy Socket

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.env.swi
2+
.env.swl
3+
.env.swn
4+
.vscode/
5+
node_modules/
6+
build/
7+
covarage/
8+
dist/
9+
temp/
10+
tmp/*
11+
.env
12+
ormconfig.json
13+
yarn-error.log
14+
coverage/
15+
build.zip

.swcrc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"$schema": "https://json.schemastore.org/swcrc",
3+
"sourceMaps": true,
4+
"module": {
5+
"type": "commonjs"
6+
},
7+
"jsc": {
8+
"target": "es2018",
9+
"parser": {
10+
"syntax": "typescript",
11+
"decorators": true,
12+
"dynamicImport": true
13+
},
14+
"transform": {
15+
"legacyDecorator": true,
16+
"decoratorMetadata": true
17+
},
18+
"keepClassNames": true,
19+
"baseUrl": "src",
20+
"paths": {
21+
"@common/*": [
22+
"./common/*"
23+
],
24+
"@lib/*": [
25+
"./lib/*"
26+
],
27+
"@config/*": [
28+
"./config/*"
29+
],
30+
"@modules/*": [
31+
"./modules/*"
32+
],
33+
"@middleware/*": [
34+
"./middleware/*"
35+
]
36+
}
37+
},
38+
"minify": false
39+
}

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:18
2+
RUN mkdir -p /var/www/app
3+
COPY . /var/www/app
4+
WORKDIR /var/www/app
5+
6+
RUN yarn install && yarn build
7+
EXPOSE 3000
8+
EXPOSE 3001
9+
10+
ARG OTEL_SERVICE_NAME
11+
ENV OTEL_RESOURCE_ATTRIBUTES="service.name=${OTEL_SERVICE_NAME}"
12+
13+
CMD ["yarn", "start"]

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: '3.7'
2+
3+
services:
4+
sv-socket:
5+
container_name: sv-socket
6+
image: node:18
7+
command: >
8+
sh -c "yarn && yarn dev"
9+
env_file:
10+
- .env
11+
ports:
12+
- "4000:4000"
13+
- "3042:3042"
14+
volumes:
15+
- .:/var/www/app
16+
working_dir: /var/www/app
17+
redis:
18+
image: redis/redis-stack:latest
19+
container_name: sv-socket-redis
20+
ports:
21+
- "6379:6379"
22+
- "8001:8001"

nodemon.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"watch": ["src/"],
3+
"ext": "js,json,ts",
4+
"inspect": "0.0.0.0",
5+
"ignore": ["src/**/*.spec.ts", "node_modules", "config", "build"],
6+
"execMap": {
7+
"ts": "ts-node --swc -r tsconfig-paths/register --transpileOnly"
8+
}
9+
}

package.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "sv-socket",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"dev": "nodemon src/server.ts | pino-pretty --colorize",
9+
"start": "node build/src/server.js",
10+
"build": "npx swc src --out-dir build --copy-files"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"devDependencies": {
16+
"@swc/cli": "^0.3.5",
17+
"@swc/core": "^1.3.107",
18+
"@types/node": "^20.11.9",
19+
"@types/uuid": "^9.0.8",
20+
"@typescript-eslint/eslint-plugin": "^6.19.1",
21+
"@typescript-eslint/parser": "^6.19.1",
22+
"cz-conventional-changelog": "^3.3.0",
23+
"eslint": "^8.56.0",
24+
"eslint-config-airbnb-base": "15.0.0",
25+
"eslint-config-airbnb-typescript": "^17.1.0",
26+
"eslint-config-prettier": "^9.1.0",
27+
"eslint-import-resolver-typescript": "^3.6.1",
28+
"eslint-plugin-import": "^2.29.1",
29+
"eslint-plugin-import-helpers": "^1.3.1",
30+
"eslint-plugin-n": "^16.6.2",
31+
"eslint-plugin-prettier": "^5.1.3",
32+
"eslint-plugin-promise": "^6.1.1",
33+
"nodemon": "^3.0.3",
34+
"pino-pretty": "^10.3.1",
35+
"prettier": "^3.2.4",
36+
"prettier-eslint": "^16.3.0",
37+
"ts-node": "^10.9.2",
38+
"tsconfig-paths": "^4.2.0",
39+
"typescript": "^5.3.3"
40+
},
41+
"dependencies": {
42+
"@fastify/cors": "^9.0.1",
43+
"@fastify/redis": "^6.1.1",
44+
"@opentelemetry/api": "^1.9.0",
45+
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.53.0",
46+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.53.0",
47+
"@opentelemetry/instrumentation-fastify": "^0.39.0",
48+
"@opentelemetry/instrumentation-http": "^0.53.0",
49+
"@opentelemetry/instrumentation-pino": "^0.42.0",
50+
"@opentelemetry/propagator-b3": "^1.26.0",
51+
"@opentelemetry/resources": "^1.26.0",
52+
"@opentelemetry/sdk-metrics": "^1.26.0",
53+
"@opentelemetry/sdk-node": "^0.53.0",
54+
"@opentelemetry/sdk-trace-base": "^1.26.0",
55+
"@opentelemetry/semantic-conventions": "^1.27.0",
56+
"@socket.io/admin-ui": "^0.5.1",
57+
"@socket.io/redis-streams-adapter": "^0.2.0",
58+
"dotenv": "^16.4.1",
59+
"dynamoose": "^4.0.0",
60+
"fastify": "^4.25.2",
61+
"fastify-plugin": "^4.5.1",
62+
"pino": "^9.4.0",
63+
"pino-opentelemetry-transport": "^1.0.1",
64+
"redis": "^4.6.12",
65+
"socket.io": "^4.7.4",
66+
"uuid": "^9.0.1",
67+
"zod": "^3.22.4"
68+
}
69+
}

0 commit comments

Comments
 (0)