From 623809a5e9fdd9c4a5f82a35de465bb47fd98069 Mon Sep 17 00:00:00 2001 From: Yanis JEDRZEJCZAK Date: Thu, 28 Mar 2024 15:40:29 +0100 Subject: [PATCH 1/6] Staging CICD yml --- .github/workflows/stg.yml | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/stg.yml diff --git a/.github/workflows/stg.yml b/.github/workflows/stg.yml new file mode 100644 index 00000000..265c12c0 --- /dev/null +++ b/.github/workflows/stg.yml @@ -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 }} From 5624dcff698678b3193d730315daa2224b1ef189 Mon Sep 17 00:00:00 2001 From: Yanis JEDRZEJCZAK Date: Thu, 28 Mar 2024 15:40:35 +0100 Subject: [PATCH 2/6] Preprod CICD yml --- .github/workflows/ppd.yml | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/ppd.yml diff --git a/.github/workflows/ppd.yml b/.github/workflows/ppd.yml new file mode 100644 index 00000000..b0abf069 --- /dev/null +++ b/.github/workflows/ppd.yml @@ -0,0 +1,73 @@ +name: Preprod - Build & Deploy to Scaleway + +on: + push: + branches: [preprod] + +env: + PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4 + NAMESPACE_ID: 2f2a5040-b5d9-40dc-8a80-f8d5653edd6f + 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 }} From 03101253b5bb42a919026bcde8fefb8c6a27030e Mon Sep 17 00:00:00 2001 From: Yanis JEDRZEJCZAK Date: Thu, 28 Mar 2024 15:40:41 +0100 Subject: [PATCH 3/6] Prod CICD yml --- .github/workflows/prd.yml | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/prd.yml diff --git a/.github/workflows/prd.yml b/.github/workflows/prd.yml new file mode 100644 index 00000000..b984ec5e --- /dev/null +++ b/.github/workflows/prd.yml @@ -0,0 +1,73 @@ +name: Prod - Build & Deploy to Scaleway + +on: + push: + branches: [main] + +env: + PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4 + NAMESPACE_ID: 7a009438-0af3-4824-8112-a8b9a91f292a + 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 }} From 922ef89757141bf9538654b63af5986435d2b989 Mon Sep 17 00:00:00 2001 From: Yanis JEDRZEJCZAK Date: Fri, 29 Mar 2024 09:57:02 +0100 Subject: [PATCH 4/6] Change ingress value --- devops/stg.values.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devops/stg.values.yaml b/devops/stg.values.yaml index c7c97ccc..17942c29 100644 --- a/devops/stg.values.yaml +++ b/devops/stg.values.yaml @@ -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 From ffbac6675fb294da28f4bd41da17ea6614860f4e Mon Sep 17 00:00:00 2001 From: Yanis JEDRZEJCZAK Date: Tue, 2 Apr 2024 15:34:28 +0200 Subject: [PATCH 5/6] Update env namespaces --- .github/workflows/ppd.yml | 2 +- .github/workflows/prd.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ppd.yml b/.github/workflows/ppd.yml index b0abf069..996389af 100644 --- a/.github/workflows/ppd.yml +++ b/.github/workflows/ppd.yml @@ -6,7 +6,7 @@ on: env: PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4 - NAMESPACE_ID: 2f2a5040-b5d9-40dc-8a80-f8d5653edd6f + NAMESPACE_ID: a052faf9-a712-41d7-bbfa-8293ee948e70 CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffreppdw9e10llz IMAGE_NAME: front CONTAINER_NAME: front diff --git a/.github/workflows/prd.yml b/.github/workflows/prd.yml index b984ec5e..1473339a 100644 --- a/.github/workflows/prd.yml +++ b/.github/workflows/prd.yml @@ -6,7 +6,7 @@ on: env: PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4 - NAMESPACE_ID: 7a009438-0af3-4824-8112-a8b9a91f292a + NAMESPACE_ID: 17374437-5428-468c-9f41-d89787ffce0e CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffreprdg7h5bbub IMAGE_NAME: front CONTAINER_NAME: front From d8be0fc45684d52a31ff5a9af436bce567f72940 Mon Sep 17 00:00:00 2001 From: Vins Date: Thu, 4 Apr 2024 16:03:11 +0200 Subject: [PATCH 6/6] fixed manage billing --- src/front/Api/LeCoffreApi/Admin/Stripe/Stripe.ts | 2 ++ .../Api/LeCoffreApi/Admin/Subscriptions/Subscriptions.ts | 2 +- .../Layouts/Subscription/SubscriptionFacturation/index.tsx | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/front/Api/LeCoffreApi/Admin/Stripe/Stripe.ts b/src/front/Api/LeCoffreApi/Admin/Stripe/Stripe.ts index 382e8666..365bc894 100644 --- a/src/front/Api/LeCoffreApi/Admin/Stripe/Stripe.ts +++ b/src/front/Api/LeCoffreApi/Admin/Stripe/Stripe.ts @@ -43,6 +43,8 @@ export default class Stripe extends BaseAdmin { } public async getClientPortalSession(stripe_subscription_id: string) { + console.log(stripe_subscription_id); + const url = new URL(this.baseURl.concat(`/${stripe_subscription_id}`)); try { return await this.getRequest(url); diff --git a/src/front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions.ts b/src/front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions.ts index c49d43e2..f6f89005 100644 --- a/src/front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions.ts +++ b/src/front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions.ts @@ -26,7 +26,7 @@ export default class Subscriptions extends BaseAdmin { const query = { q }; if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); try { - return await this.getRequest(url); + return await this.getRequest(url); } catch (err) { this.onError(err); return Promise.reject(err); diff --git a/src/front/Components/Layouts/Subscription/SubscriptionFacturation/index.tsx b/src/front/Components/Layouts/Subscription/SubscriptionFacturation/index.tsx index 6cba1cac..a4485188 100644 --- a/src/front/Components/Layouts/Subscription/SubscriptionFacturation/index.tsx +++ b/src/front/Components/Layouts/Subscription/SubscriptionFacturation/index.tsx @@ -32,8 +32,9 @@ export default function SubscriptionFacturation() { const manageBilling = async () => { try { const jwt = JwtService.getInstance().decodeJwt(); - const subscription = await Subscriptions.getInstance().get({ officeId: jwt?.office_Id }); - const stripe_client_portal = await Stripe.getInstance().getClientPortalSession(subscription.stripe_subscription_id!); + const subscription = await Subscriptions.getInstance().get({ where: { office: { uid: jwt?.office_Id } } }); + if (!subscription[0]) return; + const stripe_client_portal = await Stripe.getInstance().getClientPortalSession(subscription[0].stripe_subscription_id!); router.push(stripe_client_portal.url); } catch (error) {} };