Staging (#141)
This commit is contained in:
commit
477045f3b3
73
.github/workflows/ppd.yml
vendored
Normal file
73
.github/workflows/ppd.yml
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
name: Preprod - Build & Deploy to Scaleway
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [preprod]
|
||||
|
||||
env:
|
||||
PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4
|
||||
NAMESPACE_ID: a052faf9-a712-41d7-bbfa-8293ee948e70
|
||||
CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffreppdw9e10llz
|
||||
IMAGE_NAME: front
|
||||
CONTAINER_NAME: front
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup SSH
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
- name: Copy SSH
|
||||
run: cp ~/.ssh/id_rsa id_rsa
|
||||
- name: Login to Scaleway Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: nologin
|
||||
password: ${{ secrets.SCW_SECRET_KEY }}
|
||||
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }}
|
||||
- name: Build the Docker Image
|
||||
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
|
||||
- name: Push the Docker Image to Scaleway Container Registry
|
||||
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
|
||||
deploy-to-scaleway:
|
||||
needs: build-and-push-image
|
||||
runs-on: ubuntu-latest
|
||||
environment: preprod
|
||||
steps:
|
||||
- name: Install CLI
|
||||
uses: scaleway/action-scw@v0
|
||||
- name: Get container ID
|
||||
run: |
|
||||
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV
|
||||
env:
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
|
||||
- name: Deploy the container based on the new image
|
||||
run: |
|
||||
env_string=""
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" == *"="* ]]; then
|
||||
key=$(echo "$line" | cut -d '=' -f 1)
|
||||
value=$(echo "$line" | cut -d '=' -f 2-)
|
||||
if [[ -n "$key" ]]; then
|
||||
env_string+="environment-variables.$key=$value "
|
||||
fi
|
||||
fi
|
||||
done <<< "$ENV_VARS"
|
||||
env_string=$(echo $env_string | sed 's/ $//')
|
||||
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
||||
env:
|
||||
ENV_VARS: ${{ secrets.ENV }}
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
|
73
.github/workflows/prd.yml
vendored
Normal file
73
.github/workflows/prd.yml
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
name: Prod - Build & Deploy to Scaleway
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
env:
|
||||
PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4
|
||||
NAMESPACE_ID: 17374437-5428-468c-9f41-d89787ffce0e
|
||||
CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffreprdg7h5bbub
|
||||
IMAGE_NAME: front
|
||||
CONTAINER_NAME: front
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup SSH
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
- name: Copy SSH
|
||||
run: cp ~/.ssh/id_rsa id_rsa
|
||||
- name: Login to Scaleway Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: nologin
|
||||
password: ${{ secrets.SCW_SECRET_KEY }}
|
||||
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }}
|
||||
- name: Build the Docker Image
|
||||
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
|
||||
- name: Push the Docker Image to Scaleway Container Registry
|
||||
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
|
||||
deploy-to-scaleway:
|
||||
needs: build-and-push-image
|
||||
runs-on: ubuntu-latest
|
||||
environment: prod
|
||||
steps:
|
||||
- name: Install CLI
|
||||
uses: scaleway/action-scw@v0
|
||||
- name: Get container ID
|
||||
run: |
|
||||
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV
|
||||
env:
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
|
||||
- name: Deploy the container based on the new image
|
||||
run: |
|
||||
env_string=""
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" == *"="* ]]; then
|
||||
key=$(echo "$line" | cut -d '=' -f 1)
|
||||
value=$(echo "$line" | cut -d '=' -f 2-)
|
||||
if [[ -n "$key" ]]; then
|
||||
env_string+="environment-variables.$key=$value "
|
||||
fi
|
||||
fi
|
||||
done <<< "$ENV_VARS"
|
||||
env_string=$(echo $env_string | sed 's/ $//')
|
||||
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
||||
env:
|
||||
ENV_VARS: ${{ secrets.ENV }}
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
|
73
.github/workflows/stg.yml
vendored
Normal file
73
.github/workflows/stg.yml
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
name: Staging - Build & Deploy to Scaleway
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [staging]
|
||||
|
||||
env:
|
||||
PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4
|
||||
NAMESPACE_ID: 9f949ff2-97bc-4979-ade2-1994dcaabde0
|
||||
CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffrestgqhhn4ixh
|
||||
IMAGE_NAME: front
|
||||
CONTAINER_NAME: front
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup SSH
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
- name: Copy SSH
|
||||
run: cp ~/.ssh/id_rsa id_rsa
|
||||
- name: Login to Scaleway Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: nologin
|
||||
password: ${{ secrets.SCW_SECRET_KEY }}
|
||||
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }}
|
||||
- name: Build the Docker Image
|
||||
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
|
||||
- name: Push the Docker Image to Scaleway Container Registry
|
||||
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }}
|
||||
deploy-to-scaleway:
|
||||
needs: build-and-push-image
|
||||
runs-on: ubuntu-latest
|
||||
environment: staging
|
||||
steps:
|
||||
- name: Install CLI
|
||||
uses: scaleway/action-scw@v0
|
||||
- name: Get container ID
|
||||
run: |
|
||||
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV
|
||||
env:
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
|
||||
- name: Deploy the container based on the new image
|
||||
run: |
|
||||
env_string=""
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" == *"="* ]]; then
|
||||
key=$(echo "$line" | cut -d '=' -f 1)
|
||||
value=$(echo "$line" | cut -d '=' -f 2-)
|
||||
if [[ -n "$key" ]]; then
|
||||
env_string+="environment-variables.$key=$value "
|
||||
fi
|
||||
fi
|
||||
done <<< "$ENV_VARS"
|
||||
env_string=$(echo $env_string | sed 's/ $//')
|
||||
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
||||
env:
|
||||
ENV_VARS: ${{ secrets.ENV }}
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
|
@ -18,10 +18,10 @@ lecoffreFront:
|
||||
limits:
|
||||
memory: 2Gi
|
||||
ingress:
|
||||
host: app.stg.lecoffre.smart-chain.fr
|
||||
host: app-tp.stg.lecoffre.smart-chain.fr
|
||||
tls:
|
||||
hosts:
|
||||
- app.stg.lecoffre.smart-chain.fr
|
||||
- app-tp.stg.lecoffre.smart-chain.fr
|
||||
secretName: front-tls
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: nginx
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { FrontendVariables } from "@Front/Config/VariablesFront";
|
||||
import CookieService from "@Front/Services/CookieService/CookieService";
|
||||
import jwt_decode from "jwt-decode";
|
||||
import JwtService, { ICustomerJwtPayload, IUserJwtPayload } from "@Front/Services/JwtService/JwtService";
|
||||
|
||||
export enum ContentType {
|
||||
JSON = "application/json",
|
||||
@ -44,6 +46,7 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected async getRequest<T>(url: URL, token?: string, contentType?: ContentType, ref?: IRef, fileName?: string) {
|
||||
await this.checkJwtToken();
|
||||
const request = async () =>
|
||||
await fetch(url, {
|
||||
method: "GET",
|
||||
@ -53,6 +56,7 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected async postRequest<T>(url: URL, body: { [key: string]: unknown } = {}, token?: string) {
|
||||
await this.checkJwtToken();
|
||||
return this.sendRequest<T>(
|
||||
async () =>
|
||||
await fetch(url, {
|
||||
@ -64,6 +68,7 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected async postRequestFormData<T>(url: URL, body: FormData) {
|
||||
await this.checkJwtToken();
|
||||
return this.sendRequest<T>(
|
||||
async () =>
|
||||
await fetch(url, {
|
||||
@ -75,6 +80,7 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected async putRequest<T>(url: URL, body: { [key: string]: unknown } = {}, token?: string) {
|
||||
await this.checkJwtToken();
|
||||
const request = async () =>
|
||||
await fetch(url, {
|
||||
method: "PUT",
|
||||
@ -86,6 +92,7 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected async patchRequest<T>(url: URL, body: { [key: string]: unknown } = {}) {
|
||||
await this.checkJwtToken();
|
||||
const request = async () =>
|
||||
await fetch(url, {
|
||||
method: "PATCH",
|
||||
@ -97,6 +104,7 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected async deleteRequest<T>(url: URL, body: { [key: string]: unknown } = {}, token?: string) {
|
||||
await this.checkJwtToken();
|
||||
const request = async () =>
|
||||
await fetch(url, {
|
||||
method: "DELETE",
|
||||
@ -108,6 +116,7 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected async putFormDataRequest<T>(url: URL, body: FormData, token?: string) {
|
||||
await this.checkJwtToken();
|
||||
const request = async () =>
|
||||
await fetch(url, {
|
||||
method: "PUT",
|
||||
@ -124,6 +133,42 @@ export default abstract class BaseApiService {
|
||||
return this.processResponse<T>(response, request, ref, fileName);
|
||||
}
|
||||
|
||||
private async checkJwtToken() {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
if (!accessToken) {
|
||||
return;
|
||||
}
|
||||
const userDecodedToken = jwt_decode(accessToken) as IUserJwtPayload;
|
||||
const customerDecodedToken = jwt_decode(accessToken) as ICustomerJwtPayload;
|
||||
|
||||
if (!userDecodedToken && !customerDecodedToken) return;
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
if (userDecodedToken.userId && userDecodedToken.exp < now) {
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
if (!refreshToken) {
|
||||
return;
|
||||
}
|
||||
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
|
||||
if (decodedRefreshToken.exp < now) {
|
||||
return;
|
||||
}
|
||||
await JwtService.getInstance().refreshToken(refreshToken);
|
||||
}
|
||||
if (customerDecodedToken.customerId && customerDecodedToken.exp < now) {
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
if (!refreshToken) {
|
||||
return;
|
||||
}
|
||||
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
|
||||
if (decodedRefreshToken.exp < now) {
|
||||
return;
|
||||
}
|
||||
await JwtService.getInstance().refreshToken(refreshToken);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
protected async processResponse<T>(response: Response, request: () => Promise<Response>, ref?: IRef, fileName?: string): Promise<T> {
|
||||
let responseContent: T;
|
||||
ref && (ref["response"] = response);
|
||||
|
Loading…
x
Reference in New Issue
Block a user