From 8a399fbbcfe982a61923ebbc4fb665fa36bcf551 Mon Sep 17 00:00:00 2001 From: marcos-silva-rodrigues Date: Thu, 7 Aug 2025 18:03:22 -0300 Subject: [PATCH] CI: fix multi cloud deploy and maestro env --- .github/workflows/deploy-manually.yml | 79 ++----------------- .../{k8s-setup.yml => k8s-deploy.yml} | 73 +++++++++++++++-- deploy/helm-chart/values-stg.yaml | 22 ++++++ deploy/helm-chart/values.yaml | 2 +- deploy/helmfiles/stg.yaml | 19 +---- 5 files changed, 98 insertions(+), 97 deletions(-) rename .github/workflows/{k8s-setup.yml => k8s-deploy.yml} (56%) create mode 100644 deploy/helm-chart/values-stg.yaml diff --git a/.github/workflows/deploy-manually.yml b/.github/workflows/deploy-manually.yml index cf9f3cb..b947858 100644 --- a/.github/workflows/deploy-manually.yml +++ b/.github/workflows/deploy-manually.yml @@ -142,76 +142,11 @@ jobs: docker system prune --volumes -a -f docker system df - # k8s-setup: - # needs: [extract_environment] - # uses: ./.github/workflows/k8s-setup.yml - # with: - # cloud: oracle - # environment: ${{ needs.extract_environment.outputs.environment }} - # secrets: inherit - - helmfile-deploy: + k8s-deploy: needs: [extract_environment, semantic_release, build_ecr_image] - env: - HOME: /home/runner - runs-on: [self-hosted, "prd-oracle"] - environment: ${{ needs.extract_environment.outputs.environment }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Helm - uses: azure/setup-helm@v1 - with: - version: 'v3.9.0' - - - name: Install OCI CLI - run: | - bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" -- --accept-all-defaults - echo "$HOME/bin" >> $GITHUB_PATH - - - name: Configure OCI CLI - run: | - mkdir -p ~/.oci || true - echo "${{ secrets.OCI_CONFIG }}" > ~/.oci/config - echo "${{ secrets.OCI_PRIVATE_KEY }}" > ~/.oci/oci_api_key.pem - chmod 600 ~/.oci/oci_api_key.pem - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - - name: Install Helmfile - run: | - wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz - tar -xzf helmfile_0.148.0_linux_amd64.tar.gz - sudo mv helmfile /usr/local/bin/ - helmfile --version - - - name: Install Helm Diff Plugin - run: helm plugin install https://github.com/databus23/helm-diff || true - - - name: Authenticate with OKE cluster - env: - ENV: ${{ needs.extract_environment.outputs.environment }} - STG_CLUSTER_ID: "ocid1.cluster.oc1.sa-saopaulo-1.aaaaaaaagh3jvln52a3ebm3dodx6emmhv5bmfs7i7sv2k4zkbcbrzcl6v37q" - PRD_CLUSTER_ID: "ocid1.cluster.oc1.sa-saopaulo-1.aaaaaaaanf3vptl6hc2tzd4enfd2hfpsht3wikxww5xejc3l7cwfm6l3sndq" - run: | - if [ "$ENV" = "stg" ]; then - CLUSTER_ID=$STG_CLUSTER_ID - elif [ "$ENV" = "prd" ]; then - CLUSTER_ID=$PRD_CLUSTER_ID - else - echo "Unknown environment: $ENV" - exit 1 - fi - - oci ce cluster create-kubeconfig --cluster-id ${CLUSTER_ID} --file $HOME/.kube/config --region sa-saopaulo-1 --token-version 2.0.0 --kube-endpoint PRIVATE_ENDPOINT - - - name: Run Helmfile Apply - env: - ENV: ${{ needs.extract_environment.outputs.environment }} - IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }} - run: helmfile -f deploy/helmfiles/${ENV}.yaml sync --set image.tag=$IMAGE_TAG + uses: ./.github/workflows/k8s-deploy.yml + with: + cloud: ${{ (needs.extract_environment.outputs.environment == 'prd' && 'azure' ) || 'oracle' }} + environment: ${{ needs.extract_environment.outputs.environment }} + image: ${{ needs.semantic_release.outputs.new_release_version }} + secrets: inherit diff --git a/.github/workflows/k8s-setup.yml b/.github/workflows/k8s-deploy.yml similarity index 56% rename from .github/workflows/k8s-setup.yml rename to .github/workflows/k8s-deploy.yml index 75fc081..d3d469d 100644 --- a/.github/workflows/k8s-setup.yml +++ b/.github/workflows/k8s-deploy.yml @@ -1,4 +1,4 @@ -name : K8s Setup kube config to deploy +name : K8s deploy on: workflow_call: @@ -13,12 +13,24 @@ on: required: true default: "prd" type: string + image: + description: "Image Tag" + required: true + type: string jobs: azure: if: inputs.cloud == 'azure' runs-on: [self-hosted, "prd-azure"] steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Helm + uses: azure/setup-helm@v1 + with: + version: 'v3.9.0' + - name: Install Azure ClI run: | curl -sL https://aka.ms/InstallAzureCLIDeb | bash @@ -36,6 +48,27 @@ jobs: uses: azure/setup-kubectl@v1 with: version: 'v1.30.1' + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install Helmfile + run: | + wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz + tar -xzf helmfile_0.148.0_linux_amd64.tar.gz + mv helmfile /usr/local/bin/ + helmfile --version + + - name: Install Helm Diff Plugin + run: helm plugin install https://github.com/databus23/helm-diff || true + + - name: Run Helmfile Apply + env: + ENV: ${{ inputs.environment }} + IMAGE_TAG: ${{ inputs.image }} + run: helmfile -f deploy/helmfiles/${ENV}.yaml sync --set image.tag=$IMAGE_TAG oracle: if: inputs.cloud == 'oracle' @@ -43,7 +76,17 @@ jobs: env: HOME: /home/runner steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Helm + uses: azure/setup-helm@v1 + with: + version: 'v3.9.0' + - name: Install OCI CLI + env: + HOME: /home/runner run: | bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" -- --accept-all-defaults echo "$HOME/bin" >> $GITHUB_PATH @@ -54,7 +97,22 @@ jobs: echo "${{ secrets.OCI_CONFIG }}" > ~/.oci/config echo "${{ secrets.OCI_PRIVATE_KEY }}" > ~/.oci/oci_api_key.pem chmod 600 ~/.oci/oci_api_key.pem - + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install Helmfile + run: | + wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz + tar -xzf helmfile_0.148.0_linux_amd64.tar.gz + sudo mv helmfile /usr/local/bin/ + helmfile --version + + - name: Install Helm Diff Plugin + run: helm plugin install https://github.com/databus23/helm-diff || true + - name: Authenticate with OKE cluster env: ENV: ${{ inputs.environment }} @@ -71,8 +129,9 @@ jobs: fi oci ce cluster create-kubeconfig --cluster-id ${CLUSTER_ID} --file $HOME/.kube/config --region sa-saopaulo-1 --token-version 2.0.0 --kube-endpoint PRIVATE_ENDPOINT - - - name: Setup kubectl - uses: azure/setup-kubectl@v1 - with: - version: 'v1.30.1' + + - name: Run Helmfile Apply + env: + ENV: ${{ inputs.environment }} + IMAGE_TAG: ${{ inputs.image }} + run: helmfile -f deploy/helmfiles/${ENV}.yaml sync --set image.tag=$IMAGE_TAG \ No newline at end of file diff --git a/deploy/helm-chart/values-stg.yaml b/deploy/helm-chart/values-stg.yaml new file mode 100644 index 0000000..9bcd584 --- /dev/null +++ b/deploy/helm-chart/values-stg.yaml @@ -0,0 +1,22 @@ +maestro: + env: stg + duc_url: duc.stg.dadosfera.ai + pi_factory_url: pi-factory.stg.dadosfera.ai + in_factory_url: in-factory.stg.dadosfera.ai + tr_factory_url: in-factory.stg.dadosfera.ai + open_customer_id: b3e3dfe5-b992-4586-a73c-c0b0c00f615d + open_group_id: e3f98a2f-7748-4981-8505-7695c8ca8218 + +hostname: maestro.stg.dadosfera.ai + +replicaCount: 1 + +affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: name + operator: In + values: + - general \ No newline at end of file diff --git a/deploy/helm-chart/values.yaml b/deploy/helm-chart/values.yaml index 93dc99d..9ed722c 100644 --- a/deploy/helm-chart/values.yaml +++ b/deploy/helm-chart/values.yaml @@ -60,7 +60,7 @@ affinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - - key: name + - key: applications operator: In values: - general diff --git a/deploy/helmfiles/stg.yaml b/deploy/helmfiles/stg.yaml index 6dbfe05..362d061 100644 --- a/deploy/helmfiles/stg.yaml +++ b/deploy/helmfiles/stg.yaml @@ -3,23 +3,8 @@ charts: chart: ../helm-chart values: - ../helm-chart/values.yaml - set: - - name: maestro.duc_url - value: duc.stg.dadosfera.ai - - name: hostname - value: maestro.stg.dadosfera.ai - - name: maestro.pi_factory_url - value: pi-factory.stg.dadosfera.ai - - name: maestro.in_factory_url - value: in-factory.stg.dadosfera.ai - - name: maestro.tr_factory_url - value: in-factory.stg.dadosfera.ai - - name: maestro.open_customer_id - value: b3e3dfe5-b992-4586-a73c-c0b0c00f615d - - name: maestro.open_group_id - value: e3f98a2f-7748-4981-8505-7695c8ca8218 - - name: replicaCount - value: 1 + - ../helm-chart/values-stg.yaml + # Environment to test Network Policies # - name: private-maestro