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/.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.yml b/.github/workflows/test-frontend.yml new file mode 100644 index 0000000..171660a --- /dev/null +++ b/.github/workflows/test-frontend.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: Run lint + run: npm run lint diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1c9ec18 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Étape 1 : Construction avec Vite +FROM node:22.8.0-alpine AS build + +WORKDIR /usr/src/app + +COPY package*.json ./ +RUN npm install + +COPY . . + +RUN npm run build + +# Utiliser nginx pour servir le contenu en production +FROM nginx:alpine +COPY --from=build /usr/src/app/build /usr/share/nginx/html + +# 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; + } +}