Skip to content

Commit d206308

Browse files
authored
th-8: + add cd scripts (#144)
1 parent cd3bc59 commit d206308

File tree

12 files changed

+148
-114
lines changed

12 files changed

+148
-114
lines changed

.github/workflows/cd.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Continuous Delivery
2+
3+
env:
4+
AWS_REGION: eu-central-1
5+
EBS_APPLICATION_NAME: towhub-app
6+
EBS_ENVIRONMENT_NAME: towhub-dev
7+
8+
on:
9+
push:
10+
branches:
11+
- development
12+
- production
13+
paths:
14+
- frontend/**/*.*
15+
- backend/**/*.*
16+
- shared/**/*.*
17+
- .github/workflows/cd.yml
18+
workflow_dispatch:
19+
20+
concurrency:
21+
group: ${{ github.ref_name }}
22+
cancel-in-progress: false
23+
24+
jobs:
25+
cd:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout Source Code
30+
uses: actions/checkout@v3
31+
32+
- name: Install NodeJS
33+
uses: actions/setup-node@v3
34+
with:
35+
node-version-file: .nvmrc
36+
37+
- name: Prepare deployment pkg
38+
run: |
39+
zip -r build.zip ./*
40+
41+
- name: Deploy to EBS
42+
uses: einaregilsson/beanstalk-deploy@v20
43+
with:
44+
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
45+
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46+
region: ${{ env.AWS_REGION }}
47+
application_name: ${{ env.EBS_APPLICATION_NAME }}
48+
environment_name: ${{ env.EBS_ENVIRONMENT_NAME }}
49+
version_label: ${{ github.sha }}
50+
deployment_package: ./build.zip

.github/workflows/ci-pr.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
run: |
4343
npm install
4444
45+
- name: Build Shared Folder
46+
run: |
47+
npm run build:shared
48+
4549
- name: Lint Commits
4650
run: |
4751
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
run: |
2828
npm install
2929
30+
- name: Build Shared Folder
31+
run: |
32+
npm run build:shared
33+
3034
- name: Code Linting
3135
run: |
3236
npm run lint

.ls-lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ls:
1717

1818
ignore:
1919
- .git
20+
- .idea
2021
- node_modules
2122
- build
2223
- shared/build

backend/package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@
77
"npm": "9.x.x"
88
},
99
"scripts": {
10+
"prebuild": "npm install",
1011
"lint:type": "npx tsc --noEmit",
1112
"lint:js": "npx eslint \"src/**/*.ts\"",
1213
"start:dev": "nodemon --exec \"node --loader ts-paths-esm-loader\" src/index.ts",
1314
"migrate:generate": "drizzle-kit generate:pg --schema=./src/libs/packages/database/schema/tables-schema.ts --out=./src/libs/packages/database/generated-schema",
1415
"migrate:dev": "node --loader ts-paths-esm-loader ./src/libs/packages/database/migrate-up.ts",
15-
"build": "tsc && tsc-alias"
16+
"migrate:prod": "node ./libs/packages/database/migrate-up.js",
17+
"build:ts": "npx tsc && tsc-alias -p tsconfig.json",
18+
"build:copy": "cp -r package.json build && cp -r ./src/libs/packages/database/generated-schema ./build/libs/packages/database/",
19+
"build": "npm run build:ts && npm run build:copy",
20+
"prestart": "npm run migrate:prod",
21+
"start": "node index.js"
1622
},
1723
"devDependencies": {
18-
"@types/bcryptjs": "2.4.2",
19-
"@types/convict": "6.1.3",
20-
"@types/swagger-jsdoc": "6.0.1",
2124
"nodemon": "3.0.1",
2225
"ts-node": "10.9.1",
2326
"ts-paths-esm-loader": "1.4.3",
2427
"tsconfig-paths": "4.2.0"
2528
},
2629
"dependencies": {
2730
"@fastify/auth": "4.3.0",
31+
"@fastify/static": "6.10.2",
2832
"@fastify/swagger": "8.9.0",
2933
"@fastify/swagger-ui": "1.9.3",
34+
"@types/bcryptjs": "2.4.3",
35+
"@types/convict": "6.1.3",
36+
"@types/swagger-jsdoc": "6.0.1",
3037
"bcryptjs": "2.4.3",
3138
"convict": "6.2.4",
3239
"dotenv": "16.3.1",

backend/src/libs/packages/server-application/server-app.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import { dirname, join } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
14
import fastifyAuth from '@fastify/auth';
5+
import fastifyStatic from '@fastify/static';
26
import swagger, { type StaticDocumentSpec } from '@fastify/swagger';
37
import swaggerUi from '@fastify/swagger-ui';
48
import Fastify, {
@@ -130,6 +134,22 @@ class ServerApp implements IServerApp {
130134
});
131135
}
132136

137+
private async initServe(): Promise<void> {
138+
const staticPath = join(
139+
dirname(fileURLToPath(import.meta.url)),
140+
'../../../public',
141+
);
142+
143+
await this.app.register(fastifyStatic, {
144+
root: staticPath,
145+
prefix: '/',
146+
});
147+
148+
this.app.setNotFoundHandler(async (_request, response) => {
149+
await response.sendFile('index.html', staticPath);
150+
});
151+
}
152+
133153
private initErrorHandler(): void {
134154
this.app.setErrorHandler(
135155
(error: FastifyError | ValidationError, _request, replay) => {
@@ -189,6 +209,8 @@ class ServerApp implements IServerApp {
189209
public async init(): Promise<void> {
190210
this.logger.info('Application initialization…');
191211

212+
await this.initServe();
213+
192214
socketService.initializeIo(this.app);
193215

194216
await this.initMiddlewares();

frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
"npm": "9.x.x"
88
},
99
"scripts": {
10+
"prebuild": "npm install",
1011
"lint:css": "npx stylelint \"src/**/*.scss\"",
1112
"lint:js": "npx eslint \"src/**/*.{ts,tsx}\"",
1213
"lint:type": "npx tsc --noEmit",
1314
"stylelint:fix": "npx stylelint \"src/**/*.scss\" --fix",
1415
"start:dev": "vite",
15-
"build": "tsc && vite build",
16+
"build": "npx tsc --build --clean && npx vite build",
1617
"preview": "vite preview"
1718
},
1819
"dependencies": {
20+
"@vitejs/plugin-react": "4.0.4",
1921
"@fortawesome/fontawesome-svg-core": "6.4.2",
2022
"@fortawesome/free-solid-svg-icons": "6.4.2",
2123
"@fortawesome/react-fontawesome": "0.2.0",
@@ -37,7 +39,6 @@
3739
"@types/google.maps": "3.54.0",
3840
"@types/react": "18.2.0",
3941
"@types/react-dom": "18.2.0",
40-
"@vitejs/plugin-react": "4.0.4",
4142
"eslint-plugin-jsx-a11y": "6.7.1",
4243
"eslint-plugin-react": "7.32.0",
4344
"eslint-plugin-react-hooks": "4.6.0",

0 commit comments

Comments
 (0)