Skip to content

Commit

Permalink
setup for topics when deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
folland87 committed Mar 22, 2024
1 parent 304ba3a commit 217f742
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 8 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN}}
mattermost_webhook_url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
mattermost_channel: ${{ env.MM_NOTIFICATION_CHANNEL}}
deployment_url: ${{ env.DEPLOYMENT_URL }}
7 changes: 4 additions & 3 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
node-version: 20

- name: Build app
- name: 🪚 Build app
run: |
cd client
npm ci
Expand All @@ -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 }}
Expand All @@ -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:
Expand All @@ -62,6 +62,7 @@ jobs:


notify:
name: 📢 Notify in mattermost channel
needs: deploy
if: always()
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions client/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_API_URL="/api"
VITE_APP_MATOMO_BASE_URL="https://piwik.enseignementsup-recherche.pro"
VITE_APP_MATOMO_SITE_ID="36"
6 changes: 2 additions & 4 deletions client/src/api/localisations.ts
Original file line number Diff line number Diff line change
@@ -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<Pick<SearchResponse<LocalisationAutocomplete>, "data">> {
const body: any = {
size: 7,
Expand All @@ -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()

Expand Down
1 change: 1 addition & 0 deletions client/src/api/patents/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
// );
Expand Down
6 changes: 6 additions & 0 deletions client/src/api/topics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { topicsURL } from "../config/api";

export async function getTopics(id) {
const res = await fetch(`${topicsURL}/${id}`);
return res.json();
}
4 changes: 3 additions & 1 deletion client/src/config/api.ts
Original file line number Diff line number Diff line change
@@ -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}` } : {};
Expand All @@ -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`;

0 comments on commit 217f742

Please sign in to comment.