From 03c4155c4854bc4452a5a3448b8a58210b87c66c Mon Sep 17 00:00:00 2001 From: Maxence Date: Mon, 1 Apr 2024 11:47:06 +0200 Subject: [PATCH 1/3] add comment et modif import dotenv --- server/config/db.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/config/db.js b/server/config/db.js index ed98b2ed..a34bb99c 100644 --- a/server/config/db.js +++ b/server/config/db.js @@ -1,15 +1,15 @@ -const { config } = require("dotenv"); -const mongoose = require("mongoose"); +require("dotenv").config(); // this reads the .env file and sets the environment variables. +const mongoose = require("mongoose"); // this is the ODM for MongoDB -mongoose - .connect( +mongoose // this connects to the MongoDB database + .connect( // the connection string is stored in the .env file "mongodb+srv://" + process.env.DB_USER_PASS + - "@cluster0.v8rv1aj.mongodb.net/khagu-dev?retryWrites=true&w=majority", + "@cluster0.v8rv1aj.mongodb.net/khagu-dev?retryWrites=true&w=majority", // this is the connection string { - useNewUrlParser: true, - useUnifiedTopology: true, + useNewUrlParser: true, // these are some options to avoid deprecation warnings + useUnifiedTopology: true, // these are some options to avoid deprecation warnings } ) - .then(() => console.log("connected to MongoDB")) - .catch((err) => console.log("Failed to connect to MongoDB :", err)); + .then(() => console.log("connected to MongoDB")) // if the connection is successful, this message is printed + .catch((err) => console.log("Failed to connect to MongoDB :", err)); // if the connection fails, this message is printed From 5dd78e28d81b596cad720dc29a627caf3dff66bf Mon Sep 17 00:00:00 2001 From: Maxence Date: Sat, 13 Apr 2024 15:26:25 +0200 Subject: [PATCH 2/3] first try deploiement raspberry pi --- .github/workflows/ci.yml | 80 +---- .github/workflows/logging.yml | 59 ---- .github/workflows/prod.yml | 506 ++++++++++++++++---------------- .github/workflows/raspberry.yml | 107 +++++++ client/Dockerfile | 2 +- docker-compose.yml | 10 + server/Dockerfile | 4 +- 7 files changed, 378 insertions(+), 390 deletions(-) delete mode 100644 .github/workflows/logging.yml create mode 100644 .github/workflows/raspberry.yml create mode 100644 docker-compose.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 879f9e54..3941c039 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,12 +47,7 @@ jobs: # Jobs de l'action npm test mv ./test-report.html ./back-jest-report.html - # - name: run back server # execution du serveur backend afin de pouvoir executer l'ensemble des tests du front - # run: | - # cd server - # npm run watch & - - - name: Run front Jest tests # execution des tests Jest du frontend + - name: Run front Jest tests # execution des tests Jest du frontendD run: | cd client npm test @@ -66,73 +61,8 @@ jobs: # Jobs de l'action ./client/front-jest-report.html ./server/back-jest-report.html - Eslint-test: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Use Node.js - uses: actions/setup-node@v2 - with: - node-version: 20 - - - name: Install front dependencies - run: | - npm ci - working-directory: client - - - name: Install back dependencies - run: | - npm ci - working-directory: server - - - name: Where am i - run: | - pwd - ls - - - name: Where am i server - run: | - pwd - ls -la - working-directory: server - - - name: Where am i client - run: | - pwd - ls -la - working-directory: client - - - name: Create eslint directory if not exists - run: mkdir -p eslint - working-directory: server - - - name: Create eslint directory if not exists - run: mkdir -p eslint - working-directory: client - - - name: Run front Eslint test - run: | - npm run lint || true - working-directory: client - - - name: Run back Eslint test - run: | - npm run lint || true - working-directory: server - - - name: Eslint reports - uses: actions/upload-artifact@v3 - with: - name: eslint reports - path: | - client/eslint-report.html - server/eslint-report.html - build-and-push: - needs: [Jest-tests, Eslint-test] + needs: [Jest-tests] runs-on: ubuntu-latest steps: @@ -165,13 +95,13 @@ jobs: # Jobs de l'action run: | echo "DB_USER_PASS=${{ secrets.DB_USER_PASS }}" > ./server/config/.env cat ./server/config/.env - echo "REACT_APP_URL_API=${{ secrets.REACT_APP_URL_API }}" > ./client/.env + echo "REACT_APP_URL_API=${{ secrets.REACT_APP_URL_API_RASPBERRY }}" > ./client/.env cat ./client/.env - name: Build front if: ${{ success() }} env: - REACT_APP_URL_API: ${{ secrets.REACT_APP_URL_API }} + REACT_APP_URL_API: ${{ secrets.REACT_APP_URL_API_RASPBERRY }} run: | cd client npm run build @@ -179,7 +109,7 @@ jobs: # Jobs de l'action - name: Build and push front uses: docker/build-push-action@v2 env: - REACT_APP_URL_API: ${{ secrets.REACT_APP_URL_API }} + REACT_APP_URL_API: ${{ secrets.REACT_APP_URL_API_RASPBERRY }} with: context: ./client/ file: ./client/Dockerfile diff --git a/.github/workflows/logging.yml b/.github/workflows/logging.yml deleted file mode 100644 index 613905e5..00000000 --- a/.github/workflows/logging.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Pipeline Logging - -on: - push: - branches: - - logging - pull_request: - branches: - - logging - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: "Google auth" - id: "auth" - uses: "google-github-actions/auth@v1" - with: - credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" - - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@v1 - with: - project_id: ${{ secrets.GCP_PROJECT }} - install_components: "gke-gcloud-auth-plugin" - - - name: Configure gcloud - run: gcloud config set compute/region europe-west2 - - - name: Get cluster credential - uses: google-github-actions/get-gke-credentials@v1 - with: - cluster_name: khagu-dev-cluster - location: europe-west2 - - - name: Set up ECK - run: | - # Liste des CRDs ECK - crds=("agents.agent.k8s.elastic.co" "apmservers.apm.k8s.elastic.co" "beats.beat.k8s.elastic.co" "elasticmapsservers.maps.k8s.elastic.co" "elasticsearchautoscalers.autoscaling.k8s.elastic.co" "elasticsearches.elasticsearch.k8s.elastic.co" "enterprisesearches.enterprisesearch.k8s.elastic.co" "kibanas.kibana.k8s.elastic.co" "logstashes.logstash.k8s.elastic.co" "stackconfigpolicies.stackconfigpolicy.k8s.elastic.co") - - # Vérifiez chaque CRD - for crd in "${crds[@]}" - do - if ! kubectl get crd $crd > /dev/null 2>&1; then - # Si le CRD n'existe pas, créez les CRDs - kubectl create -f https://download.elastic.co/downloads/eck/2.11.1/crds.yaml - break - fi - done - - # Appliquez l'opérateur ECK - kubectl apply -f https://download.elastic.co/downloads/eck/2.11.1/operator.yaml - - - name: Deploy to GKE - run: | - kubectl apply -f ./logging/fleet.yml diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index d19bbefc..4bee72ae 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -1,253 +1,253 @@ -name: Pipeline Prod - -on: # Triggers the workflow - pull_request: # This workflow will run only for pull requests - branches: # This workflow will run only for the main branch - - main - -permissions: - pull-requests: write - -env: - # Use docker.io for Docker Hub if empty - SHA: ${{ github.event.pull_request.head.sha || github.event.after }} - REACT_APP_URL_API: ${{ secrets.REACT_APP_URL_API }} - -jobs: - ##### Check de l'image Front ###### - ################################### - check-front-image: - runs-on: ubuntu-latest # OS - steps: - - name: Checkout # Checkout the repository - uses: actions/checkout@v3 # Checkout the repository - - - name: Login to Docker Hub # Login to Docker Hub - uses: docker/login-action@v2 # Docker login action - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} # Docker Hub username - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} # Docker Hub access token - - - name: Extract Docker Front metadata # Extract Docker Front metadata - id: meta # Step ID - uses: docker/metadata-action@v4.4.0 # Docker metadata action - with: - images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }} # Docker Front image - labels: | - org.opencontainers.image.revision=${{ env.SHA }} - tags: | - type=edge,branch=$repo.default_branch - type=semver,pattern=v{{version}} - type=sha,prefix=,suffix=,format=short - - - name: Check Front image # Check Front image - uses: docker/scout-action@v0.18.1 # Docker scout action - with: - command: cves # Command to run on the image - image: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} # Docker Front image version to check - exit-code: true # Exit code - - ##### Check de l'image Back ###### - ################################### - check-back-image: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Extract Docker Back metadata - id: meta - uses: docker/metadata-action@v4.4.0 - with: - images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }} - labels: | - org.opencontainers.image.revision=${{ env.SHA }} - tags: | - type=edge,branch=$repo.default_branch - type=semver,pattern=v{{version}} - type=sha,prefix=,suffix=,format=short - - - name: Check Back image - uses: docker/scout-action@v0.18.1 - with: - command: cves - image: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} - exit-code: true - - ##### Push front image to GAR ###### - #################################### - push-front-image-to-GAR: - needs: [check-front-image] - runs-on: ubuntu-latest - permissions: - contents: "read" - id-token: "write" - - steps: - - uses: actions/checkout@v3 - - - name: "Google auth" - id: "auth" - uses: "google-github-actions/auth@v1" - with: - credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" - - - name: "Pull image from Docker Hub" - run: docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} - - - name: "Tag image" - run: docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} - - - name: "config docker" - run: gcloud auth configure-docker "europe-west1-docker.pkg.dev" - - - name: "Push image to GAR" - run: docker push europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} - - ##### Push back image to GAR ###### - ################################### - push-back-image-to-GAR: - needs: [check-back-image] - runs-on: ubuntu-latest - permissions: - contents: "read" - id-token: "write" - - steps: - - uses: actions/checkout@v3 - - - name: "Google auth" - id: "auth" - uses: "google-github-actions/auth@v1" - with: - credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" - - - name: "Pull image from Docker Hub" - run: docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} - - - name: "Tag image" - run: docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} - - - name: "config docker" - run: gcloud auth configure-docker "europe-west1-docker.pkg.dev" - - - name: "Push image to GAR" - run: docker push europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} - # - name: "Build and push" - # uses: RafikFarhad/push-to-gcr-github-action@v5-beta - # with: - # registry: europe-west1-docker.pkg.dev - # project_id: ${{ secrets.GCP_PROJECT }} - # image_name: ${{ vars.DOCKER_BACK }} - # image_tag: ${{ vars.DOCKER_BACK_VERSION }} - # dockerfile: ./server/Dockerfile - # context: ./server - - ##### Deploiement Terraform ###### - ################################## - deploy-terraform: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Terraform - uses: hashicorp/setup-terraform@v2 - - - name: Terraform Init - run: | - cd terraform - terraform init - env: - GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} - - - name: Terraform Plan - run: | - cd terraform - terraform plan - env: - GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} - - - name: Terraform Apply - run: | - cd terraform - terraform apply -auto-approve - env: - GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} - - ##### Deploy front to GKE ###### - ################################ - deploy-front-to-gke: - needs: [push-front-image-to-GAR, deploy-terraform] - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: "Google auth" - id: "auth" - uses: "google-github-actions/auth@v1" - with: - credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" - - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@v1 - with: - project_id: ${{ secrets.GCP_PROJECT }} - install_components: "gke-gcloud-auth-plugin" - - - name: Configure gcloud - run: gcloud config set compute/region europe-west2 - - - name: Get cluster credential - uses: google-github-actions/get-gke-credentials@v1 - with: - cluster_name: khagu-dev-cluster - location: europe-west2 - - - name: Deploy to GKE - run: | - gcloud auth configure-docker europe-west1-docker.pkg.dev - kubectl apply -f ./client/prod-front.yml - - - ##### Deploy back to GKE ###### - ############################### - deploy-back-to-gke: - needs: [push-back-image-to-GAR, deploy-terraform] - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: "Google auth" - id: "auth" - uses: "google-github-actions/auth@v1" - with: - credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" - - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@v1 - with: - project_id: ${{ secrets.GCP_PROJECT }} - install_components: "gke-gcloud-auth-plugin" - - - name: Configure gcloud - run: gcloud config set compute/region europe-west2 - - - name: Get cluster credential - uses: google-github-actions/get-gke-credentials@v1 - with: - cluster_name: khagu-dev-cluster - location: europe-west2 - - - name: Deploy to GKE - run: | - gcloud auth configure-docker europe-west1-docker.pkg.dev - kubectl apply -f ./server/prod-back.yml +# name: Pipeline Prod + +# on: # Triggers the workflow +# # pull_request: # This workflow will run only for pull requests +# # branches: # This workflow will run only for the main branch +# # # - main + +# permissions: +# pull-requests: write + +# env: +# # Use docker.io for Docker Hub if empty +# SHA: ${{ github.event.pull_request.head.sha || github.event.after }} +# REACT_APP_URL_API: ${{ secrets.REACT_APP_URL_API }} + +# jobs: +# ##### Check de l'image Front ###### +# ################################### +# check-front-image: +# runs-on: ubuntu-latest # OS +# steps: +# - name: Checkout # Checkout the repository +# uses: actions/checkout@v3 # Checkout the repository + +# - name: Login to Docker Hub # Login to Docker Hub +# uses: docker/login-action@v2 # Docker login action +# with: +# username: ${{ secrets.DOCKER_HUB_USERNAME }} # Docker Hub username +# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} # Docker Hub access token + +# - name: Extract Docker Front metadata # Extract Docker Front metadata +# id: meta # Step ID +# uses: docker/metadata-action@v4.4.0 # Docker metadata action +# with: +# images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }} # Docker Front image +# labels: | +# org.opencontainers.image.revision=${{ env.SHA }} +# tags: | +# type=edge,branch=$repo.default_branch +# type=semver,pattern=v{{version}} +# type=sha,prefix=,suffix=,format=short + +# - name: Check Front image # Check Front image +# uses: docker/scout-action@v0.18.1 # Docker scout action +# with: +# command: cves # Command to run on the image +# image: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} # Docker Front image version to check +# exit-code: true # Exit code + +# ##### Check de l'image Back ###### +# ################################### +# check-back-image: +# runs-on: ubuntu-latest +# steps: +# - name: Checkout +# uses: actions/checkout@v3 + +# - name: Login to Docker Hub +# uses: docker/login-action@v2 +# with: +# username: ${{ secrets.DOCKER_HUB_USERNAME }} +# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + +# - name: Extract Docker Back metadata +# id: meta +# uses: docker/metadata-action@v4.4.0 +# with: +# images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }} +# labels: | +# org.opencontainers.image.revision=${{ env.SHA }} +# tags: | +# type=edge,branch=$repo.default_branch +# type=semver,pattern=v{{version}} +# type=sha,prefix=,suffix=,format=short + +# - name: Check Back image +# uses: docker/scout-action@v0.18.1 +# with: +# command: cves +# image: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} +# exit-code: true + +# ##### Push front image to GAR ###### +# #################################### +# push-front-image-to-GAR: +# needs: [check-front-image] +# runs-on: ubuntu-latest +# permissions: +# contents: "read" +# id-token: "write" + +# steps: +# - uses: actions/checkout@v3 + +# - name: "Google auth" +# id: "auth" +# uses: "google-github-actions/auth@v1" +# with: +# credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" + +# - name: "Pull image from Docker Hub" +# run: docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} + +# - name: "Tag image" +# run: docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} + +# - name: "config docker" +# run: gcloud auth configure-docker "europe-west1-docker.pkg.dev" + +# - name: "Push image to GAR" +# run: docker push europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} + +# ##### Push back image to GAR ###### +# ################################### +# push-back-image-to-GAR: +# needs: [check-back-image] +# runs-on: ubuntu-latest +# permissions: +# contents: "read" +# id-token: "write" + +# steps: +# - uses: actions/checkout@v3 + +# - name: "Google auth" +# id: "auth" +# uses: "google-github-actions/auth@v1" +# with: +# credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" + +# - name: "Pull image from Docker Hub" +# run: docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} + +# - name: "Tag image" +# run: docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} + +# - name: "config docker" +# run: gcloud auth configure-docker "europe-west1-docker.pkg.dev" + +# - name: "Push image to GAR" +# run: docker push europe-west1-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GAR }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} +# # - name: "Build and push" +# # uses: RafikFarhad/push-to-gcr-github-action@v5-beta +# # with: +# # registry: europe-west1-docker.pkg.dev +# # project_id: ${{ secrets.GCP_PROJECT }} +# # image_name: ${{ vars.DOCKER_BACK }} +# # image_tag: ${{ vars.DOCKER_BACK_VERSION }} +# # dockerfile: ./server/Dockerfile +# # context: ./server + +# ##### Deploiement Terraform ###### +# ################################## +# deploy-terraform: +# runs-on: ubuntu-latest +# steps: +# - name: Checkout +# uses: actions/checkout@v3 + +# - name: Setup Terraform +# uses: hashicorp/setup-terraform@v2 + +# - name: Terraform Init +# run: | +# cd terraform +# terraform init +# env: +# GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} + +# - name: Terraform Plan +# run: | +# cd terraform +# terraform plan +# env: +# GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} + +# - name: Terraform Apply +# run: | +# cd terraform +# terraform apply -auto-approve +# env: +# GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} + +# ##### Deploy front to GKE ###### +# ################################ +# deploy-front-to-gke: +# needs: [push-front-image-to-GAR, deploy-terraform] +# runs-on: ubuntu-latest +# steps: +# - name: Checkout +# uses: actions/checkout@v3 + +# - name: "Google auth" +# id: "auth" +# uses: "google-github-actions/auth@v1" +# with: +# credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" + +# - name: Set up Cloud SDK +# uses: google-github-actions/setup-gcloud@v1 +# with: +# project_id: ${{ secrets.GCP_PROJECT }} +# install_components: "gke-gcloud-auth-plugin" + +# - name: Configure gcloud +# run: gcloud config set compute/region europe-west2 + +# - name: Get cluster credential +# uses: google-github-actions/get-gke-credentials@v1 +# with: +# cluster_name: khagu-dev-cluster +# location: europe-west2 + +# - name: Deploy to GKE +# run: | +# gcloud auth configure-docker europe-west1-docker.pkg.dev +# kubectl apply -f ./client/prod-front.yml + + +# ##### Deploy back to GKE ###### +# ############################### +# deploy-back-to-gke: +# needs: [push-back-image-to-GAR, deploy-terraform] +# runs-on: ubuntu-latest +# steps: +# - name: Checkout +# uses: actions/checkout@v3 + +# - name: "Google auth" +# id: "auth" +# uses: "google-github-actions/auth@v1" +# with: +# credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" + +# - name: Set up Cloud SDK +# uses: google-github-actions/setup-gcloud@v1 +# with: +# project_id: ${{ secrets.GCP_PROJECT }} +# install_components: "gke-gcloud-auth-plugin" + +# - name: Configure gcloud +# run: gcloud config set compute/region europe-west2 + +# - name: Get cluster credential +# uses: google-github-actions/get-gke-credentials@v1 +# with: +# cluster_name: khagu-dev-cluster +# location: europe-west2 + +# - name: Deploy to GKE +# run: | +# gcloud auth configure-docker europe-west1-docker.pkg.dev +# kubectl apply -f ./server/prod-back.yml diff --git a/.github/workflows/raspberry.yml b/.github/workflows/raspberry.yml new file mode 100644 index 00000000..7f3c11bb --- /dev/null +++ b/.github/workflows/raspberry.yml @@ -0,0 +1,107 @@ +name: Pipeline Prod + +on: # Triggers the workflow + pull_request: # This workflow will run only for pull requests + branches: # This workflow will run only for the main branch + - main + +permissions: + pull-requests: write + +env: + # Use docker.io for Docker Hub if empty + SHA: ${{ github.event.pull_request.head.sha || github.event.after }} + REACT_APP_URL_API: ${{ secrets.REACT_APP_URL_API }} + +jobs: + ##### Check de l'image Front ###### + ################################### + check-front-image: + runs-on: ubuntu-latest # OS + steps: + - name: Checkout # Checkout the repository + uses: actions/checkout@v3 # Checkout the repository + + - name: Login to Docker Hub # Login to Docker Hub + uses: docker/login-action@v2 # Docker login action + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} # Docker Hub username + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} # Docker Hub access token + + - name: Extract Docker Front metadata # Extract Docker Front metadata + id: meta # Step ID + uses: docker/metadata-action@v4.4.0 # Docker metadata action + with: + images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }} # Docker Front image + labels: | + org.opencontainers.image.revision=${{ env.SHA }} + tags: | + type=edge,branch=$repo.default_branch + type=semver,pattern=v{{version}} + type=sha,prefix=,suffix=,format=short + + - name: Check Front image # Check Front image + uses: docker/scout-action@v0.18.1 # Docker scout action + with: + command: cves # Command to run on the image + image: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} # Docker Front image version to check + exit-code: true # Exit code + + ##### Check de l'image Back ###### + ################################### + check-back-image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Extract Docker Back metadata + id: meta + uses: docker/metadata-action@v4.4.0 + with: + images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }} + labels: | + org.opencontainers.image.revision=${{ env.SHA }} + tags: | + type=edge,branch=$repo.default_branch + type=semver,pattern=v{{version}} + type=sha,prefix=,suffix=,format=short + + - name: Check Back image + uses: docker/scout-action@v0.18.1 + with: + command: cves + image: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} + exit-code: true + + + + ##### Deploiement docker compose ###### + ################################ + deploy: + needs: [check-front-image, check-back-image] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Deploy to Raspberry Pi + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.RASPBERRY_PI_HOST }} + username: ${{ secrets.RASPBERRY_PI_USERNAME }} + key: ${{ secrets.RASPBERRY_PI_SSH_KEY }} + passphrase: ${{ secrets.RASPBERRY_PI_SSH_PASSPHRASE }} + script: | + docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_FRONT }}:${{ vars.DOCKER_FRONT_VERSION }} + docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ vars.DOCKER_BACK }}:${{ vars.DOCKER_BACK_VERSION }} + scp ./docker-compose.yml ${{ secrets.RASPBERRY_PI_USERNAME }}@${{ secrets.RASPBERRY_PI_HOST }}:/Documents/docker-compose.yml + ssh ${{ secrets.RASPBERRY_PI_USERNAME }}@${{ secrets.RASPBERRY_PI_HOST }} 'docker-compose -f /Documents/docker-compose.yml up -d' + + diff --git a/client/Dockerfile b/client/Dockerfile index 3e0f282a..3081a5c0 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,4 +1,4 @@ -FROM nginx:latest +FROM nginx:latest-arm RUN apt-get update -y diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7e484b6c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3' +services: + frontend: + image: khagu/khagu-dev-front:1.2 + ports: + - 80:80 + backend: + image: khagu/khagu-dev-back:1.1 + ports: + - 7000:7000 \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile index c434e554..0d71d7b8 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,6 +1,6 @@ -FROM node:latest +FROM node:latest-arm -RUN apt-get update && apt-get install -y +RUN apt-get update -y COPY . . From ad3410c337347b580034747a0cd8c37905456159 Mon Sep 17 00:00:00 2001 From: Maxence Date: Sat, 13 Apr 2024 15:51:17 +0200 Subject: [PATCH 3/3] remove arm --- client/Dockerfile | 2 +- server/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/Dockerfile b/client/Dockerfile index 3081a5c0..3e0f282a 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,4 +1,4 @@ -FROM nginx:latest-arm +FROM nginx:latest RUN apt-get update -y diff --git a/server/Dockerfile b/server/Dockerfile index 0d71d7b8..77102394 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,4 +1,4 @@ -FROM node:latest-arm +FROM node:latest RUN apt-get update -y