diff --git a/.github/workflows/deploy-oracle.yml b/.github/workflows/deploy-oracle.yml new file mode 100644 index 0000000..56fe840 --- /dev/null +++ b/.github/workflows/deploy-oracle.yml @@ -0,0 +1,112 @@ +name: Deploy + +on: + push: + branches: + - main + - beta + +jobs: + extract_environment: + runs-on: ubuntu-22.04 + outputs: + environment: ${{ steps.extract_environment.outputs.environment }} + steps: + - name: Extract Environment + run: | + if [ ${GITHUB_REF} == "refs/heads/main" ]; then + echo "environment=prd" >> $GITHUB_OUTPUT + elif [ ${GITHUB_REF} == "refs/heads/beta" ]; then + echo "environment=stg" >> $GITHUB_OUTPUT + fi + id: extract_environment + + helmfile-deploy: + needs: [extract_environment] + runs-on: [self-hosted, "prd-azure"] + env: + OCI_CLI_USER: ${{ secrets.OCI_CLI_USER }} + OCI_CLI_TENANCY: ${{ secrets.OCI_CLI_TENANCY }} + OCI_CLI_FINGERPRINT: ${{ secrets.OCI_CLI_FINGERPRINT }} + OCI_CLI_KEY_CONTENT: ${{ secrets.OCI_CLI_KEY_CONTENT }} + OCI_CLI_REGION: ${{ secrets.OCI_CLI_REGION }} + + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Helm + uses: azure/setup-helm@v1 + with: + version: 'v3.9.0' + + + - name: Determine DNS_HOST based on environment + id: set_dns + env: + ENV: ${{ needs.extract_environment.outputs.environment }} + run: | + 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: Oracle Set Cluster Context + env: + ENV: ${{ needs.extract_environment.outputs.environment }} + uses: oracle-actions/run-oci-cli-command@v1.3.2 + with: + command: | + if [ "$ENV" = "prd" ]; then + CLUSTER_ID="${{ secrets.OCI_CLUSTER_ID_PRD }}" + elif [ "$ENV" = "stg" ]; then + CLUSTER_ID="${{ secrets.OCI_CLUSTER_ID_STG }}" + 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: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install Jinja CLI + run: | + python -m pip install --upgrade pip + pip install jinja2 + + - name: Render Jinja Templates + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + ROUTE53_DNS_HOSTS: ${{ steps.set_dns.outputs.dns_host }} + run: | + python3 parse_yaml.py + + - 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: ${{ needs.extract_environment.outputs.environment }} + run: helmfile -f helmfiles/${ENV}.yaml sync + + - 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: Apply with kubectl + run: kubectl apply -f system/ \ No newline at end of file