From 217f742aeddb5725f40520a7749deff0128fc8e0 Mon Sep 17 00:00:00 2001 From: folland87 Date: Fri, 22 Mar 2024 08:35:34 +0100 Subject: [PATCH] setup for topics when deployed --- .github/workflows/production.yml | 105 +++++++++++++++++++ .github/workflows/staging.yml | 7 +- client/.env.production | 3 + client/src/api/localisations.ts | 6 +- client/src/api/patents/autocomplete/index.ts | 1 + client/src/api/topics.ts | 6 ++ client/src/config/api.ts | 4 +- 7 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/production.yml create mode 100644 client/.env.production create mode 100644 client/src/api/topics.ts diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml new file mode 100644 index 00000000..be04075e --- /dev/null +++ b/.github/workflows/production.yml @@ -0,0 +1,105 @@ +name: Build and deploy staging + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +env: + DEPLOYMENT: scanr-next-gen + DEPLOYMENT_NAMESPACE: scanr + DEPLOYMENT_URL: https://scanr.dataesr.ovh + MM_NOTIFICATION_CHANNEL: bots + +jobs: + publish-ghcr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: 🪚 Build app + run: | + cd client + npm ci + npm run build -- --mode production + + - name: 🏷️ Get tag + id: tag + run: echo "tag=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT + + - name: 🔑 Login Docker + run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} + + - name: 🐳 Build Docker image + run: | + cd client + IMAGE_ID=ghcr.io/${{ github.repository }} + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + docker build -f Dockerfile -t $IMAGE_ID:${{ steps.tag.outputs.tag }} -t $IMAGE_ID:latest . + + - name: 📦 Push Docker image + run: | + IMAGE_ID=ghcr.io/${{ github.repository }} + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + docker push --all-tags $IMAGE_ID + + release: + name: Create new Github release + runs-on: ubuntu-latest + needs: publish-ghcr + steps: + - name: 🏁 Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: 🏷️ Get tag + id: tag + run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + - name: Create changelog text + id: changelog + uses: loopwerk/tag-changelog@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + config_file: .github/config/changelog.cjs + + - name: 📦 Create release + uses: actions/create-release@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ steps.tag.outputs.tag }} + body: ${{ steps.changelog.outputs.changes }} + + deploy: + name: 💭 Update staging deployment + runs-on: ubuntu-latest + needs: publish-ghcr + steps: + - name: Deploy to Cluster + id: kubectl-deploy + uses: dataesr/kubectl-deploy@v1.1 + env: + KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_DOAD }} + with: + namespace: ${{ env.DEPLOYMENT_NAMESPACE }} + restart: ${{ env.DEPLOYMENT }} + + + notify: + name: 📢 Notify in mattermost channel + needs: deploy + if: always() + runs-on: ubuntu-latest + steps: + - uses: dataesr/mm-notifier-action@v1.0.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN}} + mattermost_webhook_url: ${{ secrets.MATTERMOST_WEBHOOK_URL }} + mattermost_channel: ${{ env.MM_NOTIFICATION_CHANNEL}} + deployment_url: ${{ env.DEPLOYMENT_URL }} \ No newline at end of file diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 9d227884..6b06dbda 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -20,7 +20,7 @@ jobs: with: node-version: 20 - - name: Build app + - name: 🪚 Build app run: | cd client npm ci @@ -33,7 +33,7 @@ jobs: - name: 🔑 Login Docker run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} - - name: 🐋 Build Docker image + - name: 🐳 Build Docker image run: | cd client IMAGE_ID=ghcr.io/${{ github.repository }} @@ -47,7 +47,7 @@ jobs: docker push --all-tags $IMAGE_ID deploy: - name: Update staging deployment + name: 💭 Update staging deployment runs-on: ubuntu-latest needs: publish-ghcr steps: @@ -62,6 +62,7 @@ jobs: notify: + name: 📢 Notify in mattermost channel needs: deploy if: always() runs-on: ubuntu-latest diff --git a/client/.env.production b/client/.env.production new file mode 100644 index 00000000..e57c381a --- /dev/null +++ b/client/.env.production @@ -0,0 +1,3 @@ +VITE_API_URL="/api" +VITE_APP_MATOMO_BASE_URL="https://piwik.enseignementsup-recherche.pro" +VITE_APP_MATOMO_SITE_ID="36" \ No newline at end of file diff --git a/client/src/api/localisations.ts b/client/src/api/localisations.ts index 689ee3ae..d733490a 100644 --- a/client/src/api/localisations.ts +++ b/client/src/api/localisations.ts @@ -1,12 +1,10 @@ -import { postHeaders } from "../config/api"; +import { localisationIndex, postHeaders } from "../config/api"; import { SearchArgs, SearchResponse, ElasticResult } from "../types/commons"; export type LocalisationAutocomplete = { autocompleted: string[]; } -const index = "https://cluster-production.elasticsearch.dataesr.ovh/scanr-localisations" - export async function autocompleteLocalisations({ query }: SearchArgs): Promise, "data">> { const body: any = { size: 7, @@ -17,7 +15,7 @@ export async function autocompleteLocalisations({ query }: SearchArgs): Promise< } } const res = await fetch( - `${index}/_search`, + `${localisationIndex}/_search`, { method: 'POST', body: JSON.stringify(body), headers: postHeaders }) const data = await res.json() diff --git a/client/src/api/patents/autocomplete/index.ts b/client/src/api/patents/autocomplete/index.ts index fab638c7..011fc0fc 100644 --- a/client/src/api/patents/autocomplete/index.ts +++ b/client/src/api/patents/autocomplete/index.ts @@ -34,6 +34,7 @@ // }, // }; // const res = await fetch( +// TODO: No url inside code use environment variable instead // "https://cluster-production.elasticsearch.dataesr.ovh/scanr-patents-test/_search", // { method: "POST", body: JSON.stringify(body), headers: postHeaders } // ); diff --git a/client/src/api/topics.ts b/client/src/api/topics.ts new file mode 100644 index 00000000..7bc5a07b --- /dev/null +++ b/client/src/api/topics.ts @@ -0,0 +1,6 @@ +import { topicsURL } from "../config/api"; + +export async function getTopics(id) { + const res = await fetch(`${topicsURL}/${id}`); + return res.json(); +} \ No newline at end of file diff --git a/client/src/config/api.ts b/client/src/config/api.ts index 93d9d014..337dcc9e 100644 --- a/client/src/config/api.ts +++ b/client/src/config/api.ts @@ -1,4 +1,4 @@ -const { VITE_API_URL: API_URL, VITE_API_KEY: API_KEY } = import.meta.env; +const { VITE_API_URL: API_URL, VITE_API_KEY: API_KEY, VITE_TOPICS_URL: TOPICS_URL } = import.meta.env; // Headers export const headers = API_KEY ? { Authorization: `Basic ${API_KEY}` } : {}; @@ -10,3 +10,5 @@ export const authorsIndex = `${API_URL}/scanr-persons`; export const organizationsIndex = `${API_URL}/scanr-organizations`; export const projectsIndex = `${API_URL}/scanr-projects`; export const patentsIndex = `${API_URL}/scanr-patents`; +export const localisationIndex = `${API_URL}/scanr-localisations`; +export const topicsURL = `${TOPICS_URL}/topics`;