From e0b860d7945b479c3e8304a8158594ff1408d68d Mon Sep 17 00:00:00 2001 From: MaximeDan <92440390+MaximeDan@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:00:45 +0200 Subject: [PATCH] Mda cicd accessibility (#43) --- .github/workflows/accessibility-tests.yml | 63 ++++++++++++ .github/workflows/cd.yml | 106 ++++++++++++++++++++ Dockerfile | 8 -- docker-compose.dev.yml | 20 ++++ docker-compose.yml | 1 - docker/next/docker-entrypoint.sh | 12 --- package.json | 4 +- src/components/form/journey/JourneyForm.tsx | 5 +- 8 files changed, 192 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/accessibility-tests.yml create mode 100644 .github/workflows/cd.yml create mode 100644 docker-compose.dev.yml delete mode 100644 docker/next/docker-entrypoint.sh diff --git a/.github/workflows/accessibility-tests.yml b/.github/workflows/accessibility-tests.yml new file mode 100644 index 0000000..e3bd1c7 --- /dev/null +++ b/.github/workflows/accessibility-tests.yml @@ -0,0 +1,63 @@ +name: Accessibility Test +run-name: Checking Accessibility + +on: [push] + +jobs: + accessibility: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install dependencies + run: npm ci + + - name: Set up Docker + uses: docker/setup-buildx-action@v2 + + - name: Install Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + + - name: Build and run Docker Compose for DB + env: + DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} + run: | + docker-compose -f docker-compose.dev.yml up -d + + echo "Waiting for database to be ready..." + sleep 30 + + - name: Run Prisma migrations + env: + DATABASE_URL: postgres://postgres:${{ secrets.DATABASE_PASSWORD }}@localhost:5433/patrigma_db + run: | + npx prisma migrate dev + npx prisma db seed + + - name: Build Next.js application + run: npm run build + + - name: Start Next.js application + env: + DATABASE_URL: postgres://postgres:${{ secrets.DATABASE_PASSWORD }}@localhost:5433/patrigma_db + NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} + NEXTAUTH_URL: http://localhost:3000 + run: | + npm run start & # Start the Next.js application in the background + echo "Waiting for Next.js to be ready..." + sleep 10 + + - name: Install xvfb + run: sudo apt-get install -y xvfb + + - name: Run Lighthouse CI with xvfb + uses: treosh/lighthouse-ci-action@v12 + with: + urls: http://localhost:3000 + uploadArtifacts: true + env: + XVFB_RUN_CMD: xvfb-run --auto-servernum --server-args='-screen 0 1024x768x24' diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..347c919 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,106 @@ +name: Build, Test, Release, and Publish +run-name: Release and Publish Docker image + +on: + push: + branches: + - tesci + +env: + VERSION: "" # Définition initiale de la variable + +jobs: + test-app: + name: Test App + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm test + + create_release: + name: Create Release + runs-on: ubuntu-latest + needs: test-app + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get version from package.json + id: get_version + run: | + VERSION=$(jq -r .version package.json) + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + with: + tag_name: "v${{ env.VERSION }}" + release_name: "Release v${{ env.VERSION }}" + draft: false + prerelease: false + + build-docker-prod: + runs-on: ubuntu-latest + needs: [test-app, create_release] + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ghcr.io/${{ github.repository_owner }}/patrigma:v${{ env.VERSION }} # Utilisation de la variable VERSION globale + labels: "version=${{ env.VERSION }},commit=${{ github.sha }}" + + notify: + runs-on: ubuntu-latest + needs: build-docker-prod + steps: + - name: Notify Discord on failure + if: failure() + uses: containrrr/shoutrrr-action@v1 + with: + url: ${{ secrets.NOTIFICATION_URL }} + title: "Build Failed for Release v${{ env.VERSION }}" + message: | + The build for release v${{ env.VERSION }} has failed. + Commit message: ${{ github.event.head_commit.message }} + Commit SHA: ${{ github.sha }} + - name: Notify Discord on success + if: success() + uses: containrrr/shoutrrr-action@v1 + with: + url: ${{ secrets.NOTIFICATION_URL }} + title: "Build Succeeded for Release v${{ env.VERSION }}" + message: | + The build for release v${{ env.VERSION }} was successful. + Commit message: ${{ github.event.head_commit.message }} + Commit SHA: ${{ github.sha }} + The Docker image has been published. diff --git a/Dockerfile b/Dockerfile index 654d72a..4edeead 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,13 +20,5 @@ COPY --from=build /patrigma/.next ./.next EXPOSE 3000 -COPY docker/next/docker-entrypoint.sh /usr/local/bin/docker-entrypoint - -RUN chmod +x /usr/local/bin/docker-entrypoint - - -ENTRYPOINT [ "docker-entrypoint" ] - - CMD ["npm", "run", "start"] diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..50f99b1 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,20 @@ +services: + patrigma_db: + image: postgres:latest + container_name: patrigma_db + ports: + - "5433:5432" + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: ${DATABASE_PASSWORD} + POSTGRES_DB: patrigma_db + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres -d patrigma_db -h localhost -p 5432"] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + postgres_data: diff --git a/docker-compose.yml b/docker-compose.yml index eda2236..dca6308 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,7 +49,6 @@ services: - NODE_ENV=${NODE_ENV} - DATABASE_PASSWORD=${DATABASE_PASSWORD} - NEXTAUTH_SECRET=${NEXTAUTH_SECRET} - - BASE_URL=${BASE_URL} - NEXT_PUBLIC_BASE_URL=${BASE_URL} ports: - "3000:3000" diff --git a/docker/next/docker-entrypoint.sh b/docker/next/docker-entrypoint.sh deleted file mode 100644 index 492f625..0000000 --- a/docker/next/docker-entrypoint.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -echo "executing docker-entrypoint.sh" - -if [ $NODE_ENV == "development" ]; then - echo "executing npm install" - npm install -fi - -# ici on peut aussi executer automatiquement les migrations des bases de données - -exec "$@" diff --git a/package.json b/package.json index 4c59276..5b244e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "next-patrigma", - "version": "0.1.0", + "name": "patrigma", + "version": "0.1.1", "private": true, "scripts": { "dev": "next dev", diff --git a/src/components/form/journey/JourneyForm.tsx b/src/components/form/journey/JourneyForm.tsx index c330d46..47c034c 100644 --- a/src/components/form/journey/JourneyForm.tsx +++ b/src/components/form/journey/JourneyForm.tsx @@ -84,7 +84,6 @@ const JourneyForm = () => { // @ts-ignore const stepObject: StepWithoutDates[] = parsedSteps.steps.map( (step, index) => { - // to do : get optional additional location fields (city, country, address, postal code) return { puzzle: step.puzzle, hint: step.hint, @@ -98,8 +97,6 @@ const JourneyForm = () => { }, ); - // to do : estimate distance and duration from steps - // get user id from session const journeyObject: JourneyWithoutDates = { authorId: Number(session?.user?.id), @@ -126,7 +123,7 @@ const JourneyForm = () => { const token = session?.accessToken; const res = await fetch( - `${process.env.BASE_URL || "http://localhost:3000"}/api/journeys`, + `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/journeys`, { method: "POST", body: JSON.stringify(body),