From 6968b12c21f2d089669847c5fe65030e5b5e3560 Mon Sep 17 00:00:00 2001 From: Arthur Dodin Date: Tue, 22 Apr 2025 13:06:38 +0200 Subject: [PATCH 1/8] feta: add ci --- .github/workflows/ci.yaml | 101 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..83311de --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,101 @@ +name: CI +on: + push: + branches: [feat/test-ci] + pull_request: + branches: [feat/test-ci] + +jobs: + lint: + runs-on: self-hosted + strategy: + matrix: + node-version: [18] + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v4 + with: + version: 9 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - run: pnpm install --frozen-lockfile + - run: pnpm lint + + build: + runs-on: self-hosted + strategy: + matrix: + node-version: [18] + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v4 + with: + version: 9 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + - run: pnpm install --frozen-lockfile + - run: pnpm build + + deploy-dev: + if: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/dev') }} + runs-on: self-hosted + needs: + - lint + - build + steps: + - uses: actions/checkout@v4 + - name: Install docker + uses: docker/setup-buildx-action@v3 + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: ${{ secrets.REGISTRY_URL }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + build-args: | + NODE_ENV=production + NEXT_PUBLIC_API_URL=https://etu.dev.uttnetgroup.fr/api + NEXT_PUBLIC_API_VERSION=v1 + NEXT_PUBLIC_API_REQUEST_TIMEOUT=10000 + NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.dev.uttnetgroup.fr/login + tags: | + ${{ secrets.REGISTRY_URL }}/etuutt/front:dev + + deploy-prod: + if: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/master') }} + runs-on: self-hosted + needs: + - lint + - build + steps: + - uses: actions/checkout@v4 + - name: Install docker + uses: docker/setup-buildx-action@v3 + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: ${{ secrets.REGISTRY_URL }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + build-args: | + NODE_ENV=production + NEXT_PUBLIC_API_URL=https://etu.utt.fr/api + NEXT_PUBLIC_API_VERSION=v1 + NEXT_PUBLIC_API_REQUEST_TIMEOUT=10000 + NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.utt.fr/login + tags: | + ${{ secrets.REGISTRY_URL }}/etuutt/front:prod \ No newline at end of file From b405c86286389019e490527e57f6f3cb3004e32b Mon Sep 17 00:00:00 2001 From: Arthur Dodin Date: Tue, 22 Apr 2025 13:11:24 +0200 Subject: [PATCH 2/8] feat: add .env.dist copy to .end.prod --- .github/workflows/ci.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 83311de..19c4ab7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -58,6 +58,7 @@ jobs: registry: ${{ secrets.REGISTRY_URL }} username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_TOKEN }} + - run: cp .env.dist .env.prod - name: Build and push uses: docker/build-push-action@v6 with: @@ -65,8 +66,6 @@ jobs: build-args: | NODE_ENV=production NEXT_PUBLIC_API_URL=https://etu.dev.uttnetgroup.fr/api - NEXT_PUBLIC_API_VERSION=v1 - NEXT_PUBLIC_API_REQUEST_TIMEOUT=10000 NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.dev.uttnetgroup.fr/login tags: | ${{ secrets.REGISTRY_URL }}/etuutt/front:dev @@ -87,6 +86,7 @@ jobs: registry: ${{ secrets.REGISTRY_URL }} username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_TOKEN }} + - run: cp .env.dist .env.prod - name: Build and push uses: docker/build-push-action@v6 with: @@ -94,8 +94,6 @@ jobs: build-args: | NODE_ENV=production NEXT_PUBLIC_API_URL=https://etu.utt.fr/api - NEXT_PUBLIC_API_VERSION=v1 - NEXT_PUBLIC_API_REQUEST_TIMEOUT=10000 NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.utt.fr/login tags: | ${{ secrets.REGISTRY_URL }}/etuutt/front:prod \ No newline at end of file From d1b4ad1f863703dd39d4f5d2ba31239831ae8821 Mon Sep 17 00:00:00 2001 From: Arthur Dodin Date: Tue, 22 Apr 2025 13:24:55 +0200 Subject: [PATCH 3/8] feat: add .env copy on build --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 19c4ab7..f50a7af 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,6 +40,7 @@ jobs: node-version: ${{ matrix.node-version }} cache: 'pnpm' - run: pnpm install --frozen-lockfile + - run: cp .env.dist .env.prod - run: pnpm build deploy-dev: From d1cccdf50a00d9b6112af11fba5d5a3733f67baa Mon Sep 17 00:00:00 2001 From: Arthur Dodin Date: Tue, 22 Apr 2025 13:34:38 +0200 Subject: [PATCH 4/8] fix: build from next --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f50a7af..fc38443 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -41,7 +41,7 @@ jobs: cache: 'pnpm' - run: pnpm install --frozen-lockfile - run: cp .env.dist .env.prod - - run: pnpm build + - run: pnpm next build deploy-dev: if: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/dev') }} From 0c5915e3e0cd93c584a7fd7c0f38660aed17fac7 Mon Sep 17 00:00:00 2001 From: Arthur Dodin Date: Tue, 22 Apr 2025 13:40:00 +0200 Subject: [PATCH 5/8] test: deploy on test branch --- .github/workflows/ci.yaml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fc38443..9e051d3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -97,4 +97,32 @@ jobs: NEXT_PUBLIC_API_URL=https://etu.utt.fr/api NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.utt.fr/login tags: | - ${{ secrets.REGISTRY_URL }}/etuutt/front:prod \ No newline at end of file + ${{ secrets.REGISTRY_URL }}/etuutt/front:prod + + deploy-test: + if: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/feat/test-ci') }} + runs-on: self-hosted + needs: + - lint + - build + steps: + - uses: actions/checkout@v4 + - name: Install docker + uses: docker/setup-buildx-action@v3 + - name: Login to registry + uses: docker/login-action@v3 + with: + registry: ${{ secrets.REGISTRY_URL }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + - run: cp .env.dist .env.prod + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: true + build-args: | + NODE_ENV=production + NEXT_PUBLIC_API_URL=https://etu.utt.fr/api + NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.utt.fr/login + tags: | + ${{ secrets.REGISTRY_URL }}/etuutt/front:test \ No newline at end of file From a4de888472d457a260c6d10f317b12466701f114 Mon Sep 17 00:00:00 2001 From: Arthur Dodin Date: Tue, 22 Apr 2025 14:00:57 +0200 Subject: [PATCH 6/8] update: remove useless first build --- .github/workflows/ci.yaml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9e051d3..9ad0cc8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,31 +24,11 @@ jobs: - run: pnpm install --frozen-lockfile - run: pnpm lint - build: - runs-on: self-hosted - strategy: - matrix: - node-version: [18] - steps: - - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v4 - with: - version: 9 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'pnpm' - - run: pnpm install --frozen-lockfile - - run: cp .env.dist .env.prod - - run: pnpm next build - deploy-dev: if: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/dev') }} runs-on: self-hosted needs: - lint - - build steps: - uses: actions/checkout@v4 - name: Install docker @@ -76,7 +56,6 @@ jobs: runs-on: self-hosted needs: - lint - - build steps: - uses: actions/checkout@v4 - name: Install docker @@ -104,7 +83,6 @@ jobs: runs-on: self-hosted needs: - lint - - build steps: - uses: actions/checkout@v4 - name: Install docker From 7d31c15ce8c3fd6e9c5824845d372a182fc57e65 Mon Sep 17 00:00:00 2001 From: AlbanSdl Date: Tue, 22 Apr 2025 16:12:28 +0200 Subject: [PATCH 7/8] fix(ci): fix build for alpine --- Dockerfile | 5 ++++- package.json | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3ff2b8d..80ae925 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,12 @@ -ARG NODE_VERSION=19-alpine +ARG NODE_VERSION=22-alpine FROM node:${NODE_VERSION} WORKDIR /usr/src/app +# Add alpine dependencies for 'sharp' +RUN apk add --upgrade --no-cache vips-dev build-base + COPY --chown=node:node package.json pnpm-lock.yaml ./ RUN npm i -g pnpm && pnpm install --frozen-lockfile --prod=false diff --git a/package.json b/package.json index 4bea9cc..fc14de6 100644 --- a/package.json +++ b/package.json @@ -47,5 +47,10 @@ "eslint-plugin-react": "^7.34.2", "sass": "^1.77.4", "typescript": "^5.4.5" + }, + "pnpm": { + "onlyBuiltDependencies": [ + "sharp" + ] } } From 5cbca3a331dca926810963b12ea6919de94451c0 Mon Sep 17 00:00:00 2001 From: Arthur Dodin Date: Tue, 22 Apr 2025 16:20:57 +0200 Subject: [PATCH 8/8] feat: ready for prod & dev --- .github/workflows/ci.yaml | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ad0cc8..a04481a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,9 +1,9 @@ name: CI on: push: - branches: [feat/test-ci] + branches: [master, dev] pull_request: - branches: [feat/test-ci] + branches: [master, dev] jobs: lint: @@ -48,6 +48,8 @@ jobs: NODE_ENV=production NEXT_PUBLIC_API_URL=https://etu.dev.uttnetgroup.fr/api NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.dev.uttnetgroup.fr/login + NEXT_PUBLIC_API_VERSION=v1 + NEXT_PUBLIC_API_REQUEST_TIMEOUT=5000 tags: | ${{ secrets.REGISTRY_URL }}/etuutt/front:dev @@ -75,32 +77,7 @@ jobs: NODE_ENV=production NEXT_PUBLIC_API_URL=https://etu.utt.fr/api NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.utt.fr/login + NEXT_PUBLIC_API_VERSION=v1 + NEXT_PUBLIC_API_REQUEST_TIMEOUT=5000 tags: | ${{ secrets.REGISTRY_URL }}/etuutt/front:prod - - deploy-test: - if: ${{ github.event_name != 'pull_request' && (github.ref == 'refs/heads/feat/test-ci') }} - runs-on: self-hosted - needs: - - lint - steps: - - uses: actions/checkout@v4 - - name: Install docker - uses: docker/setup-buildx-action@v3 - - name: Login to registry - uses: docker/login-action@v3 - with: - registry: ${{ secrets.REGISTRY_URL }} - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_TOKEN }} - - run: cp .env.dist .env.prod - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: true - build-args: | - NODE_ENV=production - NEXT_PUBLIC_API_URL=https://etu.utt.fr/api - NEXT_PUBLIC_CAS_SERVICE_URL=https://etu.utt.fr/login - tags: | - ${{ secrets.REGISTRY_URL }}/etuutt/front:test \ No newline at end of file