Deploy DO Droplet for OpenClaw (make vpc not overlap with k8s) #45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Terraform Apply | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| id-token: write | |
| contents: write | |
| jobs: | |
| apply_infra: | |
| name: Apply Infra | |
| runs-on: ubuntu-latest | |
| environment: prod | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Setup Terraform | |
| - uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: "v1.12.2" | |
| # Configure aws creds | |
| - uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: us-west-1 | |
| role-to-assume: arn:aws:iam::691595548805:role/github_actions_full_admin | |
| - name: Terraform init | |
| id: init | |
| run: | | |
| terraform -chdir=environments/prod/infra init | |
| - name: Terraform Format Check | |
| run: | | |
| terraform -chdir=environments/prod/infra fmt -check | |
| - name: Terraform Validate | |
| run: | | |
| terraform -chdir=environments/prod/infra validate | |
| - name: Terraform Apply | |
| run: terraform -chdir=environments/prod/infra apply -auto-approve | |
| env: | |
| DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} | |
| apply_k8s: | |
| name: Apply K8s | |
| runs-on: ubuntu-latest | |
| needs: | |
| - apply_infra | |
| environment: prod | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Setup Terraform | |
| - uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: "v1.12.2" | |
| # Configure aws creds | |
| - uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: us-west-1 | |
| role-to-assume: arn:aws:iam::691595548805:role/github_actions_full_admin | |
| - name: Terraform init | |
| id: init | |
| run: | | |
| terraform -chdir=environments/prod/infra init # Kubeconfig is fetched out of infra state; needs initializing | |
| terraform -chdir=environments/prod/k8s init | |
| - name: Terraform Format Check | |
| run: | | |
| terraform -chdir=environments/prod/infra fmt -check | |
| terraform -chdir=environments/prod/k8s fmt -check | |
| - name: Terraform Validate | |
| run: | | |
| terraform -chdir=environments/prod/infra validate | |
| terraform -chdir=environments/prod/k8s validate | |
| - name: Terraform Apply | |
| env: | |
| DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }} | |
| TF_VAR_cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| TF_VAR_email: ${{ secrets.EMAIL }} | |
| TF_VAR_domain: ${{ secrets.DOMAIN }} | |
| TF_VAR_github_email: ${{ secrets.EMAIL }} | |
| TF_VAR_github_pat: ${{ secrets.GH_PAT }} | |
| TF_VAR_postgres_admin_password: ${{ secrets.POSTGRES_ADMIN_PASSWORD }} | |
| TF_VAR_postgres_replication_password: ${{ secrets.POSTGRES_REPLICATION_PASSWORD }} | |
| TF_VAR_hydra_database_password: ${{ secrets.HYDRA_DATABASE_PASSWORD }} | |
| TF_VAR_hydra_system_secret: ${{ secrets.HYDRA_SYSTEM_SECRET }} | |
| TF_VAR_hydra_cookie_secret: ${{ secrets.HYDRA_COOKIE_SECRET }} | |
| TF_VAR_kratos_database_password: ${{ secrets.KRATOS_DATABASE_PASSWORD }} | |
| TF_VAR_apple_developer_team_id: ${{ secrets.APPLE_DEVELOPER_TEAM_ID }} | |
| TF_VAR_chat_siwa_primary_app_id: ${{ secrets.CHAT_PRIMARY_APP_ID }} | |
| run: | | |
| kubeconfig_path="/tmp/kubeconfig" | |
| BOLD="\033[1m" | |
| RESET="\033[0m" | |
| CYAN="\033[36m" | |
| ORANGE="\033[0;33m" | |
| RED="\033[31m" | |
| info_message () { | |
| local message="$1" | |
| local mtype="INFO" | |
| timestamp=$(date +"%Y-%m-%d %H:%M:%S") | |
| echo -e "${CYAN}${timestamp} [$mtype] ${RESET}$message" | |
| } | |
| info_message "Exporting kubeconfig to $kubeconfig_path" | |
| terraform -chdir=environments/prod/infra output -raw kubeconfig > "$kubeconfig_path" | |
| export KUBECONFIG="$kubeconfig_path" | |
| if terraform -chdir=environments/prod/k8s state list >/dev/null 2>&1; then | |
| info_message "Terraform state exists - determining if this is a fresh cluster" | |
| if [ "$(kubectl get ns -o json | jq '.items | length')" -eq 5 ]; then | |
| info_message "Determined that this is a fresh cluster." | |
| kubectl cluster-info | |
| info_message "Tainting k8s Terraform module" | |
| terraform -chdir=environments/prod/k8s state list | xargs -I{} sh -c 'terraform -chdir=environments/prod/k8s taint "{}" || echo "Skipping {}"' | |
| else | |
| info_message "This is not a fresh cluster - there are already resources in it. Skipping resource taint" | |
| fi | |
| else | |
| info_message "Terraform state for K8s Terraform project is empty. Skipping to apply" | |
| fi | |
| info_message "Running Terraform Apply (k8s)" | |
| terraform -chdir=environments/prod/k8s apply -var="kubeconfig=$kubeconfig_path" -auto-approve |