diff --git a/.github/workflows/deploy-manually.yml b/.github/workflows/deploy-manually.yml index 87e306e..5f95da0 100644 --- a/.github/workflows/deploy-manually.yml +++ b/.github/workflows/deploy-manually.yml @@ -13,11 +13,6 @@ on: options: - stg - prd - push_to_dockerhub: - description: "Push image to Dockerhub?" - required: true - type: boolean - default: false jobs: extract_environment: @@ -118,23 +113,6 @@ jobs: docker compose -f build.docker-compose.yml build docker compose -f build.docker-compose.yml push - - name: Login to Docker Hub - if: ${{inputs.push_to_dockerhub}} - uses: docker/login-action@v2 - with: - username: dadosfera - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Build, Tag, and Push Image to Dockerhub - if: ${{inputs.push_to_dockerhub}} - env: - ENV: ${{ needs.extract_environment.outputs.environment }} - IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }} - ACCOUNT_ID: ${{ steps.aws.outputs.aws-account-id }} - run: | - docker compose -f build.docker-compose.dockerhub.yml build - docker compose -f build.docker-compose.dockerhub.yml push - # - name: Create ZIP file to Deploy AWS Beanstalk # env: # ENV: ${{ needs.extract_environment.outputs.environment }} @@ -166,7 +144,10 @@ jobs: helmfile-deploy: needs: [extract_environment, semantic_release, build_ecr_image] - runs-on: [self-hosted, "prd-azure"] + env: + HOME: /home/runner + runs-on: [self-hosted, "prd-oracle"] + environment: ${{ needs.extract_environment.outputs.environment }} steps: - name: Checkout code @@ -177,13 +158,17 @@ jobs: with: version: 'v3.9.0' - - name: Install Azure ClI + - name: Install OCI CLI run: | - curl -sL https://aka.ms/InstallAzureCLIDeb | bash + bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" -- --accept-all-defaults + echo "$HOME/bin" >> $GITHUB_PATH - - uses: azure/login@v2 - with: - creds: '{"clientId":"${{ secrets.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ secrets.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.ARM_TENANT_ID }}"}' + - 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 @@ -194,24 +179,31 @@ jobs: 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/ + 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: Setup kubectl - uses: azure/setup-kubectl@v1 - with: - version: 'v1.30.1' - - - name: Authenticate with cluster + - name: Authenticate with OKE cluster env: - CLUSTER_NAME: platform-${{ needs.extract_environment.outputs.environment }} - run: az aks get-credentials --resource-group dadosfera-prd --name ${CLUSTER_NAME} --overwrite-existing + 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 helmfiles/${ENV}.yaml sync --set image.tag=$IMAGE_TAG + run: helmfile -f deploy/helmfiles/${ENV}.yaml sync --set image.tag=$IMAGE_TAG diff --git a/.github/workflows/validate-k8s.yml b/.github/workflows/validate-k8s.yml index 17ed975..015efc2 100644 --- a/.github/workflows/validate-k8s.yml +++ b/.github/workflows/validate-k8s.yml @@ -16,22 +16,18 @@ jobs: run: | if [ "${{ github.event.pull_request.base.ref }}" == "main" ]; then echo "environment=prd" >> $GITHUB_OUTPUT - elif [ "${{ github.event.pull_request.base.ref }}" == "beta" ]; then + elif [ "${{ github.event.pull_request.base.ref }}" == "stg" ]; then echo "environment=stg" >> $GITHUB_OUTPUT fi id: extract_environment - helmfile-deploy: + helmfile-check: + env: + HOME: /home/runner needs: [extract_environment] - runs-on: [self-hosted, "prd-azure"] - + environment: ${{ needs.extract_environment.outputs.environment }} + runs-on: [self-hosted, "prd-oracle"] steps: - - name: Summary - env: - ENV: ${{ needs.extract_environment.outputs.environment }} - run: | - echo "### :rocket: Deploy da branch \`$GITHUB_REF_NAME\` para o environment ($ENV)" >> $GITHUB_STEP_SUMMARY - - name: Checkout code uses: actions/checkout@v3 @@ -40,13 +36,28 @@ jobs: with: version: 'v3.9.0' - - name: Install Azure ClI + - name: Determine DNS_HOST based on environment + id: set_dns + env: + ENV: ${{ needs.extract_environment.outputs.environment }} run: | - curl -sL https://aka.ms/InstallAzureCLIDeb | bash + if [ "$ENV" = "prd" ]; then + echo "dns_host=dadosfera.ai" >> $GITHUB_OUTPUT + elif [ "$ENV" = "stg" ]; then + echo "dns_host=stg.dadosfera.ai" >> $GITHUB_OUTPUT + fi + + - 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 - - uses: azure/login@v2 - with: - creds: '{"clientId":"${{ secrets.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ secrets.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.ARM_TENANT_ID }}"}' + - 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 @@ -57,23 +68,35 @@ jobs: 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/ + 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: Setup kubectl uses: azure/setup-kubectl@v1 with: version: 'v1.30.1' - - name: Authenticate with cluster - env: - CLUSTER_NAME: platform-${{ needs.extract_environment.outputs.environment }} - run: az aks get-credentials --resource-group dadosfera-prd --name ${CLUSTER_NAME} --overwrite-existing - - name: Run Helmfile Diff env: ENV: ${{ needs.extract_environment.outputs.environment }} - run: helmfile -f helmfiles/${ENV}.yaml diff + run: helmfile -f deploy/helmfiles/${ENV}.yaml diff diff --git a/maestro/Chart.yaml b/deploy/helm-chart/Chart.yaml similarity index 100% rename from maestro/Chart.yaml rename to deploy/helm-chart/Chart.yaml diff --git a/maestro/templates/NOTES.txt b/deploy/helm-chart/templates/NOTES.txt similarity index 100% rename from maestro/templates/NOTES.txt rename to deploy/helm-chart/templates/NOTES.txt diff --git a/maestro/templates/deployment.yaml b/deploy/helm-chart/templates/deployment.yaml similarity index 86% rename from maestro/templates/deployment.yaml rename to deploy/helm-chart/templates/deployment.yaml index c648514..116ab30 100644 --- a/maestro/templates/deployment.yaml +++ b/deploy/helm-chart/templates/deployment.yaml @@ -27,15 +27,10 @@ spec: - name: {{ .Values.imagePullSecrets }} nodeSelector: "beta.kubernetes.io/os": linux + {{- if .Values.affinity }} affinity: - nodeAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - nodeSelectorTerms: - - matchExpressions: - - key: application - operator: In - values: - - general + {{- toYaml .Values.affinity | nindent 8 }} + {{- end }} tolerations: - key: "kubernetes.azure.com/scalesetpriority" @@ -48,13 +43,10 @@ spec: image: {{ .Values.image.repository }}:{{ .Values.image.tag }} ports: - containerPort: {{ .Values.containerPort }} + {{- if .Values.resources }} resources: - requests: - cpu: {{ .Values.resources.requests.cpu }} - memory: {{ .Values.resources.requests.memory }} - limits: - cpu: {{ .Values.resources.limits.cpu }} - memory: {{ .Values.resources.limits.memory }} + {{- toYaml .Values.resources | nindent 12 }} + {{- end }} env: - name: AWS_IDENTITY_POOL_ID value: {{ .Values.maestro.aws_identity_pool_id }} diff --git a/maestro/templates/ingress-private.yaml b/deploy/helm-chart/templates/ingress-private.yaml similarity index 100% rename from maestro/templates/ingress-private.yaml rename to deploy/helm-chart/templates/ingress-private.yaml diff --git a/maestro/templates/ingress.yaml b/deploy/helm-chart/templates/ingress.yaml similarity index 99% rename from maestro/templates/ingress.yaml rename to deploy/helm-chart/templates/ingress.yaml index faf1305..16d3ff6 100644 --- a/maestro/templates/ingress.yaml +++ b/deploy/helm-chart/templates/ingress.yaml @@ -3,6 +3,7 @@ kind: Ingress metadata: annotations: nginx.ingress.kubernetes.io/proxy-body-size: "0" + nginx.ingress.kubernetes.io/server-snippet: | underscores_in_headers on; ignore_invalid_headers on; diff --git a/maestro/templates/secret.yaml b/deploy/helm-chart/templates/secret.yaml similarity index 100% rename from maestro/templates/secret.yaml rename to deploy/helm-chart/templates/secret.yaml diff --git a/maestro/templates/service.yaml b/deploy/helm-chart/templates/service.yaml similarity index 100% rename from maestro/templates/service.yaml rename to deploy/helm-chart/templates/service.yaml diff --git a/maestro/values.yaml b/deploy/helm-chart/values.yaml similarity index 86% rename from maestro/values.yaml rename to deploy/helm-chart/values.yaml index 14dd9e4..f85c248 100644 --- a/maestro/values.yaml +++ b/deploy/helm-chart/values.yaml @@ -48,3 +48,13 @@ autoscaling: maxReplicas: 100 targetCPUUtilizationPercentage: 80 targetMemoryUtilizationPercentage: 80 + +affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: name + operator: In + values: + - general diff --git a/helmfiles/prd.yaml b/deploy/helmfiles/prd.yaml similarity index 91% rename from helmfiles/prd.yaml rename to deploy/helmfiles/prd.yaml index e4146e8..f3e9df6 100644 --- a/helmfiles/prd.yaml +++ b/deploy/helmfiles/prd.yaml @@ -1,8 +1,8 @@ charts: - name: maestro - chart: ../maestro + chart: ../helm-chart values: - - ../maestro/values.yaml + - ../helm-chart/values.yaml set: - name: maestro.duc_url value: duc.dadosfera.ai diff --git a/helmfiles/stg.yaml b/deploy/helmfiles/stg.yaml similarity index 79% rename from helmfiles/stg.yaml rename to deploy/helmfiles/stg.yaml index 5782e36..57b32b4 100644 --- a/helmfiles/stg.yaml +++ b/deploy/helmfiles/stg.yaml @@ -1,8 +1,8 @@ charts: - name: maestro - chart: ../maestro + chart: ../helm-chart values: - - ../maestro/values.yaml + - ../helm-chart/values.yaml set: - name: maestro.duc_url value: duc.stg.dadosfera.ai @@ -19,4 +19,8 @@ charts: - name: maestro.open_group_id value: e3f98a2f-7748-4981-8505-7695c8ca8218 - name: replicaCount - value: 1 \ No newline at end of file + value: 1 + - name: affinity + value: null + - name: resources + value: null \ No newline at end of file diff --git a/maestro/.helmignore b/maestro/.helmignore deleted file mode 100644 index 0e8a0eb..0000000 --- a/maestro/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*.orig -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/