From 2d7ddd8db9da0b12667ab18048bda0e0f727a7bc Mon Sep 17 00:00:00 2001 From: OualidZejli Date: Fri, 11 Oct 2024 17:32:11 +0200 Subject: [PATCH 1/4] DevOps/CI : Front test Workflow --- .github/workflows/test-frontend.yml | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/test-frontend.yml diff --git a/.github/workflows/test-frontend.yml b/.github/workflows/test-frontend.yml new file mode 100644 index 0000000..475102b --- /dev/null +++ b/.github/workflows/test-frontend.yml @@ -0,0 +1,36 @@ +name: Test Frontend + +on: + push: + branches: + - develop + - staging + - main + pull_request: + branches: + - develop + - staging + - main + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test From f73e1774cb4acbbd4fc83bc730a9ce0c153af3b3 Mon Sep 17 00:00:00 2001 From: OualidZejli Date: Fri, 11 Oct 2024 17:54:12 +0200 Subject: [PATCH 2/4] DevOps/CI : Dockerfile created --- .dockerignore | 5 +++++ Dockerfile | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..34ede95 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +dist +.git +Dockerfile +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2519ee4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:22.8.0-alpine + +WORKDIR /usr/src/app + +COPY package*.json ./ +RUN npm install + +COPY . . + +RUN npm run build + +EXPOSE 8080 + +CMD ["npm", "start"] From f5262223cb10d52c58c0194a0537f18f41f91def Mon Sep 17 00:00:00 2001 From: OualidZejli Date: Thu, 7 Nov 2024 17:11:34 +0100 Subject: [PATCH 3/4] cicd: test with lint or build --- .github/workflows/deploy-front.yml | 34 +++++++++++++++++ .github/workflows/test-frontend-build.yml | 37 +++++++++++++++++++ ...st-frontend.yml => test-frontend-lint.yml} | 5 ++- Dockerfile | 15 ++++++-- nginx.conf | 19 ++++++++++ 5 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/deploy-front.yml create mode 100644 .github/workflows/test-frontend-build.yml rename .github/workflows/{test-frontend.yml => test-frontend-lint.yml} (87%) create mode 100644 nginx.conf diff --git a/.github/workflows/deploy-front.yml b/.github/workflows/deploy-front.yml new file mode 100644 index 0000000..acedb66 --- /dev/null +++ b/.github/workflows/deploy-front.yml @@ -0,0 +1,34 @@ +name: Deploy Frontend to Staging or Prod + +on: + push: + branches: + # - staging + # - main + # - devops/ci # FOR TESTS + - no_branch + # pull_request: + # branches: + # - staging + # - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build and Push Docker Image for Frontend + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_APP }}:${{ github.sha }} -f ./Dockerfile . + docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_APP }}:${{ github.sha }} + docker tag ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_APP }}:${{ github.sha }} ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_APP }}:latest + docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_APP }}:latest diff --git a/.github/workflows/test-frontend-build.yml b/.github/workflows/test-frontend-build.yml new file mode 100644 index 0000000..ba5b9fa --- /dev/null +++ b/.github/workflows/test-frontend-build.yml @@ -0,0 +1,37 @@ +name: Test Frontend + +on: + push: + branches: + - develop + - staging + - main + - devops/ci # FOR TESTS + pull_request: + branches: + - develop + - staging + - main + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Build project + run: npm run build diff --git a/.github/workflows/test-frontend.yml b/.github/workflows/test-frontend-lint.yml similarity index 87% rename from .github/workflows/test-frontend.yml rename to .github/workflows/test-frontend-lint.yml index 475102b..171660a 100644 --- a/.github/workflows/test-frontend.yml +++ b/.github/workflows/test-frontend-lint.yml @@ -6,6 +6,7 @@ on: - develop - staging - main + - devops/ci # FOR TESTS pull_request: branches: - develop @@ -32,5 +33,5 @@ jobs: - name: Install dependencies run: npm install - - name: Run tests - run: npm test + - name: Run lint + run: npm run lint diff --git a/Dockerfile b/Dockerfile index 2519ee4..1c9ec18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM node:22.8.0-alpine +# Étape 1 : Construction avec Vite +FROM node:22.8.0-alpine AS build WORKDIR /usr/src/app @@ -9,6 +10,14 @@ COPY . . RUN npm run build -EXPOSE 8080 +# Utiliser nginx pour servir le contenu en production +FROM nginx:alpine +COPY --from=build /usr/src/app/build /usr/share/nginx/html -CMD ["npm", "start"] +# Copier la configuration par défaut de Nginx +COPY nginx.conf /etc/nginx/nginx.conf + +EXPOSE 80 + +# Démarrage de Nginx en mode "daemon off" +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..9fd9107 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,19 @@ +server { + listen 80; + + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri /index.html; + } + + error_page 404 /index.html; + + location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|woff2|ttf|svg)$ { + expires 30d; + access_log off; + } +} From 010d62ec417f93ccd2b8196a7bd9f9858e8f04c9 Mon Sep 17 00:00:00 2001 From: OualidZejli Date: Thu, 7 Nov 2024 17:30:39 +0100 Subject: [PATCH 4/4] cicd: test with lint or build --- .github/workflows/test-frontend-build.yml | 37 ------------------- ...st-frontend-lint.yml => test-frontend.yml} | 0 2 files changed, 37 deletions(-) delete mode 100644 .github/workflows/test-frontend-build.yml rename .github/workflows/{test-frontend-lint.yml => test-frontend.yml} (100%) diff --git a/.github/workflows/test-frontend-build.yml b/.github/workflows/test-frontend-build.yml deleted file mode 100644 index ba5b9fa..0000000 --- a/.github/workflows/test-frontend-build.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Test Frontend - -on: - push: - branches: - - develop - - staging - - main - - devops/ci # FOR TESTS - pull_request: - branches: - - develop - - staging - - main - -jobs: - test: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x] - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Setup Node.js - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - - name: Install dependencies - run: npm install - - - name: Build project - run: npm run build diff --git a/.github/workflows/test-frontend-lint.yml b/.github/workflows/test-frontend.yml similarity index 100% rename from .github/workflows/test-frontend-lint.yml rename to .github/workflows/test-frontend.yml