diff --git a/.github/workflows/_deploy.yml b/.github/workflows/_deploy.yml new file mode 100644 index 0000000..97a4db2 --- /dev/null +++ b/.github/workflows/_deploy.yml @@ -0,0 +1,83 @@ +name: Deploy (reusable) + +on: + workflow_call: + inputs: + module: + description: "Skaffold module: orion, worker, pusher, emailnotifierjob, memberreconciler, or migrations" + required: true + type: string + environment: + description: "Target environment: dev or prod" + required: true + type: string + +jobs: + deploy: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + defaults: + run: + working-directory: go + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go/go.mod + cache-dependency-path: go/go.sum + + - name: Resolve environment settings + id: env + run: | + if [ "${{ inputs.environment }}" = "prod" ]; then + echo "project=flowy-prod-440017" >> "$GITHUB_OUTPUT" + echo "cluster=${{ vars.PROD_GKE_CLUSTER_NAME }}" >> "$GITHUB_OUTPUT" + echo "region=${{ vars.PROD_GKE_REGION }}" >> "$GITHUB_OUTPUT" + elif [ "${{ inputs.environment }}" = "dev" ]; then + echo "project=flowy-dev-440017" >> "$GITHUB_OUTPUT" + echo "cluster=${{ vars.DEV_GKE_CLUSTER_NAME }}" >> "$GITHUB_OUTPUT" + echo "region=${{ vars.DEV_GKE_REGION }}" >> "$GITHUB_OUTPUT" + else + echo "Unknown environment: ${{ inputs.environment }}" >&2 + exit 1 + fi + + - name: Run tests + run: go test ./... + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ inputs.environment == 'prod' && secrets.PROD_GKE_SERVICE_ACCOUNT_KEY || secrets.DEV_GKE_SERVICE_ACCOUNT_KEY }} + + - uses: google-github-actions/setup-gcloud@v2 + + - name: Install gke-gcloud-auth-plugin + run: gcloud components install gke-gcloud-auth-plugin --quiet + + - name: Configure Docker for Artifact Registry + run: gcloud auth configure-docker us-west2-docker.pkg.dev --quiet + + - name: Get GKE credentials + run: | + gcloud container clusters get-credentials "${{ steps.env.outputs.cluster }}" \ + --region "${{ steps.env.outputs.region }}" \ + --project "${{ steps.env.outputs.project }}" + + - name: Install skaffold + run: | + curl -fsSLo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 + sudo install skaffold /usr/local/bin/ + skaffold version + + - name: Deploy + env: + SKAFFOLD_DEFAULT_REPO: us-west2-docker.pkg.dev/${{ steps.env.outputs.project }}/deployments + run: | + if [ "${{ inputs.module }}" = "migrations" ]; then + kubectl delete job migrations --ignore-not-found + skaffold run -p migrations --tail + else + skaffold run -p ${{ inputs.environment }} -m ${{ inputs.module }} + fi diff --git a/.github/workflows/deploy-emailnotifierjob.yml b/.github/workflows/deploy-emailnotifierjob.yml new file mode 100644 index 0000000..5e22ac2 --- /dev/null +++ b/.github/workflows/deploy-emailnotifierjob.yml @@ -0,0 +1,22 @@ +name: Deploy emailnotifierjob + +on: + workflow_dispatch: + inputs: + environment: + description: "Target environment" + required: true + type: choice + options: [dev, prod] + +concurrency: + group: deploy-emailnotifierjob-${{ inputs.environment }} + cancel-in-progress: false + +jobs: + deploy: + uses: ./.github/workflows/_deploy.yml + with: + module: emailnotifierjob + environment: ${{ inputs.environment }} + secrets: inherit diff --git a/.github/workflows/deploy-memberreconciler.yml b/.github/workflows/deploy-memberreconciler.yml new file mode 100644 index 0000000..ee4bde7 --- /dev/null +++ b/.github/workflows/deploy-memberreconciler.yml @@ -0,0 +1,22 @@ +name: Deploy memberreconciler + +on: + workflow_dispatch: + inputs: + environment: + description: "Target environment" + required: true + type: choice + options: [dev, prod] + +concurrency: + group: deploy-memberreconciler-${{ inputs.environment }} + cancel-in-progress: false + +jobs: + deploy: + uses: ./.github/workflows/_deploy.yml + with: + module: memberreconciler + environment: ${{ inputs.environment }} + secrets: inherit diff --git a/.github/workflows/deploy-migrations.yml b/.github/workflows/deploy-migrations.yml new file mode 100644 index 0000000..5b9e953 --- /dev/null +++ b/.github/workflows/deploy-migrations.yml @@ -0,0 +1,22 @@ +name: Deploy migrations + +on: + workflow_dispatch: + inputs: + environment: + description: "Target environment" + required: true + type: choice + options: [dev, prod] + +concurrency: + group: deploy-migrations-${{ inputs.environment }} + cancel-in-progress: false + +jobs: + deploy: + uses: ./.github/workflows/_deploy.yml + with: + module: migrations + environment: ${{ inputs.environment }} + secrets: inherit diff --git a/.github/workflows/deploy-orion.yml b/.github/workflows/deploy-orion.yml new file mode 100644 index 0000000..824d94e --- /dev/null +++ b/.github/workflows/deploy-orion.yml @@ -0,0 +1,22 @@ +name: Deploy orion + +on: + workflow_dispatch: + inputs: + environment: + description: "Target environment" + required: true + type: choice + options: [dev, prod] + +concurrency: + group: deploy-orion-${{ inputs.environment }} + cancel-in-progress: false + +jobs: + deploy: + uses: ./.github/workflows/_deploy.yml + with: + module: orion + environment: ${{ inputs.environment }} + secrets: inherit diff --git a/.github/workflows/deploy-pusher.yml b/.github/workflows/deploy-pusher.yml new file mode 100644 index 0000000..25b27c4 --- /dev/null +++ b/.github/workflows/deploy-pusher.yml @@ -0,0 +1,22 @@ +name: Deploy pusher + +on: + workflow_dispatch: + inputs: + environment: + description: "Target environment" + required: true + type: choice + options: [dev, prod] + +concurrency: + group: deploy-pusher-${{ inputs.environment }} + cancel-in-progress: false + +jobs: + deploy: + uses: ./.github/workflows/_deploy.yml + with: + module: pusher + environment: ${{ inputs.environment }} + secrets: inherit diff --git a/.github/workflows/deploy-worker.yml b/.github/workflows/deploy-worker.yml new file mode 100644 index 0000000..a190cf3 --- /dev/null +++ b/.github/workflows/deploy-worker.yml @@ -0,0 +1,22 @@ +name: Deploy worker (particleprocessorworker) + +on: + workflow_dispatch: + inputs: + environment: + description: "Target environment" + required: true + type: choice + options: [dev, prod] + +concurrency: + group: deploy-worker-${{ inputs.environment }} + cancel-in-progress: false + +jobs: + deploy: + uses: ./.github/workflows/_deploy.yml + with: + module: worker + environment: ${{ inputs.environment }} + secrets: inherit