Skip to content

Commit b29efad

Browse files
authored
Feat workflows (#2)
* Add CI workflows for frontend and backend, and update Dockerfile for multi-stage builds * Comment out test execution in CI workflows for frontend and backend * update Node.js version in CI workflow from 20 to 22 * Update CI workflow triggers to include workflow files for frontend and backend * Update CI workflows to specify context and Dockerfile paths for frontend and backend * Refine .dockerignore to include README.md and exclude unnecessary files * Remove production flag from npm ci command in Dockerfile * Update Dockerfile to copy from 'dist' directory and serve from 'dist' * Update Dockerfile to remove production flag from npm ci command and adjust base image * Update Dockerfile to clean npm cache after installation and add additional development dependencies * Implement graceful shutdown for the server and enhance shutdown logging * Update Dockerfile and package.json for improved build and configuration management * Refactor API URL configuration to use centralized config file * Fix indentation in App.test.tsx for improved readability --------- Co-authored-by: Alexis DEVLEESCHAUWER <a.devleeschauwer@pyres.com>
1 parent 558ca57 commit b29efad

19 files changed

Lines changed: 237 additions & 71 deletions

.github/workflows/back.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Backend CI
2+
3+
on:
4+
push:
5+
paths:
6+
- 'back/**'
7+
- '.github/workflows/back.yml'
8+
pull_request:
9+
paths:
10+
- 'back/**'
11+
- '.github/workflows/back.yml'
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
working-directory: back
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
- name: Use Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '22'
26+
- name: Install dependencies
27+
run: npm ci
28+
- name: Build
29+
run: npm run build
30+
31+
docker-build:
32+
runs-on: ubuntu-latest
33+
needs: build
34+
defaults:
35+
run:
36+
working-directory: back
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
- name: Log in to GHCR
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
- name: Build and push production
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: ./back
50+
file: ./back/Dockerfile
51+
target: production
52+
push: true
53+
tags: |
54+
ghcr.io/${{ github.repository }}/api:latest
55+
ghcr.io/${{ github.repository }}/api:${{ github.sha }}

.github/workflows/front.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Frontend CI
2+
3+
on:
4+
push:
5+
paths:
6+
- 'front/**'
7+
- '.github/workflows/front.yml'
8+
pull_request:
9+
paths:
10+
- 'front/**'
11+
- '.github/workflows/front.yml'
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
working-directory: front
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
- name: Use Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '22'
26+
- name: Install dependencies
27+
run: npm ci
28+
- name: Build
29+
run: npm run build
30+
31+
docker-build:
32+
runs-on: ubuntu-latest
33+
needs: build
34+
defaults:
35+
run:
36+
working-directory: front
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
- name: Log in to GHCR
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
- name: Build and push production
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: ./front
50+
file: ./front/Dockerfile
51+
target: production
52+
push: true
53+
tags: |
54+
ghcr.io/${{ github.repository }}/front:latest
55+
ghcr.io/${{ github.repository }}/front:${{ github.sha }}

back/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
*.log
3+
.env
4+
README.md

back/Dockerfile

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
ARG NODE_VERSION=18
2-
ARG NPM_VERSION=8.6.0
1+
# Étape 1 : build
2+
FROM node:22 AS builder
33

4-
FROM node:${NODE_VERSION}
5-
6-
WORKDIR /usr/src/app
7-
ENV PATH /usr/src/app/node_modules/.bin:$PATH
4+
WORKDIR /app
85

96
COPY package*.json ./
107

11-
ENV NODE_ENV=production
12-
13-
RUN npm install -g npm@${NPM_VERSION}
14-
RUN npm install -g serve
15-
RUN npm ci --only=production
8+
RUN npm ci
169

17-
COPY . ./
10+
COPY src ./src
11+
COPY tsconfig.json ./
1812

1913
RUN npm run build
2014

15+
# Étape 2 : image finale
16+
FROM node:22 AS production
17+
18+
WORKDIR /app
19+
20+
COPY --from=builder /app/dist ./dist
21+
COPY package*.json ./
22+
23+
RUN npm ci --only=production && npm cache clean --force
24+
25+
ENV NODE_ENV=production
26+
2127
EXPOSE 80
2228

23-
CMD npm run start
29+
CMD ["node", "dist/index.js"]

back/package.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@
2121
"@typescript-eslint/eslint-plugin": "^5.59.1",
2222
"@typescript-eslint/parser": "^5.59.1",
2323
"@types/swagger-jsdoc": "^6.0.1",
24-
"@types/swagger-ui-express": "^4.1.3"
24+
"@types/swagger-ui-express": "^4.1.3",
25+
"eslint": "^8.39.0",
26+
"eslint-config-google": "^0.14.0",
27+
"eslint-config-prettier": "^8.8.0",
28+
"eslint-plugin-prettier": "^4.2.1",
29+
"nodemon": "^2.0.22",
30+
"prettier": "2.8.8",
31+
"ts-node": "^10.9.1",
32+
"tsconfig-paths": "^4.2.0",
33+
"tsup": "^6.7.0",
34+
"typescript": "^5.0.4"
2535
},
2636
"dependencies": {
27-
"@typescript-eslint/experimental-utils": "^5.59.1",
2837
"swagger-jsdoc": "^6.2.8",
2938
"swagger-ui-express": "^4.6.2",
3039
"axios": "^1.4.0",
@@ -36,16 +45,6 @@
3645
"jsonwebtoken": "^9.0.0",
3746
"lodash": "^4.17.21",
3847
"mongoose": "^7.1.0",
39-
"redis": "^4.6.6",
40-
"eslint": "^8.39.0",
41-
"eslint-config-google": "^0.14.0",
42-
"eslint-config-prettier": "^8.8.0",
43-
"eslint-plugin-prettier": "^4.2.1",
44-
"nodemon": "^2.0.22",
45-
"prettier": "2.8.8",
46-
"ts-node": "^10.9.1",
47-
"tsconfig-paths": "^4.2.0",
48-
"tsup": "^6.7.0",
49-
"typescript": "^5.0.4"
48+
"redis": "^4.6.6"
5049
}
5150
}

back/src/index.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ app.get('/', (req: Request, res: Response) => {
3131

3232
app.use('/api', ApiIndex);
3333

34-
app.listen(port, () => {
34+
const server = app.listen(port, () => {
3535
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
3636
});
37+
38+
// Graceful shutdown
39+
const shutdown = async () => {
40+
console.log('INFO Gracefully shutting down. Please wait...');
41+
server.close(async (err) => {
42+
if (err) {
43+
console.error('Error closing HTTP server:', err);
44+
process.exit(1);
45+
}
46+
try {
47+
await MangoDBService.close?.();
48+
} catch (e) {
49+
console.error('Error closing MongoDB:', e);
50+
}
51+
try {
52+
await RedisService.close?.();
53+
} catch (e) {
54+
console.error('Error closing Redis:', e);
55+
}
56+
process.exit(0);
57+
});
58+
};
59+
60+
process.on('SIGINT', shutdown);
61+
process.on('SIGTERM', shutdown);

front/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
*.log
3+
.env
4+
README.md
5+
.git

front/Dockerfile

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
ARG NODE_VERSION=18
2-
ARG NPM_VERSION=8.6.0
1+
# Étape 1 : build
2+
FROM node:22-alpine AS builder
33

4-
FROM node:${NODE_VERSION}
5-
6-
WORKDIR /usr/src/app
7-
ENV PATH /usr/src/app/node_modules/.bin:$PATH
4+
WORKDIR /app
85

96
COPY package*.json ./
107

11-
ENV NODE_ENV=production
12-
13-
RUN npm install -g npm@${NPM_VERSION}
14-
RUN npm install -g serve
15-
RUN npm ci --only=production
8+
RUN npm ci
169

1710
COPY . ./
1811

1912
RUN npm run build
2013

14+
# Étape 2 : image finale pour servir le build
15+
FROM node:22-alpine AS production
16+
17+
WORKDIR /app
18+
19+
RUN npm install -g serve
20+
21+
COPY --from=builder /app/dist .
22+
2123
EXPOSE 80
2224

23-
CMD serve -s build -l 80
25+
CMD ["serve", "-s", "/app", "-l", "80"]

front/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#000000" />
88
<meta name="description" content="L2ADG Best Weather App" />
9+
<script src="/config/app-config.js" blocking="render" fetchpriority="high"></script>
910
<link rel="apple-touch-icon" href="/logo192.png" />
1011
<title>Weather L2ADG</title>
1112
</head>

0 commit comments

Comments
 (0)