From 8d27772bb4c5b55ab7aa9e9be5866868f47ee823 Mon Sep 17 00:00:00 2001 From: flolu Date: Wed, 24 Mar 2021 17:07:40 +0100 Subject: [PATCH] feat: only deploy on releases --- .github/workflows/deploy.yaml | 68 ++++++++++++++++++ .github/workflows/{ci-cd.yaml => test.yaml} | 78 +-------------------- infrastructure/modules/k8s-ingress/main.tf | 2 - 3 files changed, 69 insertions(+), 79 deletions(-) create mode 100644 .github/workflows/deploy.yaml rename .github/workflows/{ci-cd.yaml => test.yaml} (50%) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..657d736 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,68 @@ +name: deploy +on: release +jobs: + deploy: + runs-on: ubuntu-20.04 + defaults: + run: + working-directory: ./infrastructure + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@master + with: + service_account_key: ${{ secrets.GCP_SA_KEY }} + project_id: ${{ secrets.GCP_PROJECT_ID }} + export_default_credentials: true + + - name: Install Terraform + uses: hashicorp/setup-terraform@v1 + with: + terraform_version: 0.14.3 + # Reason: https://github.com/hashicorp/setup-terraform/issues/20 + terraform_wrapper: false + + - name: Terraform format + id: fmt + run: terraform fmt -check + + - name: Terraform init + id: init + run: terraform init + + - name: Terraform validate + id: validate + run: terraform validate -no-color + + - name: Terraform plan + id: plan + run: make plan-infrastructure + working-directory: . + + - name: Terraform update + run: make update-infrastructure + working-directory: . + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + working-directory: . + + - name: Load cached node_modules + uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: yarn install --prefer-offline --frozen-lockfile + working-directory: . + + - name: Deploy to Kubernetes + run: make deploy + working-directory: . diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/test.yaml similarity index 50% rename from .github/workflows/ci-cd.yaml rename to .github/workflows/test.yaml index fa95177..374f6df 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/test.yaml @@ -1,4 +1,4 @@ -name: ci-cd +name: test on: push jobs: check-code: @@ -83,79 +83,3 @@ jobs: - name: Run tests run: make test-integration - - # TODO flag to enable / disable deployment... I don't want to pay cloud costst for a project no one uses! :) - # enabled: deploy - # disabled destroy - - deploy: - runs-on: ubuntu-20.04 - needs: [check-code, unit-tests, integration-tests] - defaults: - run: - working-directory: ./infrastructure - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Cloud SDK - uses: google-github-actions/setup-gcloud@master - with: - service_account_key: ${{ secrets.GCP_SA_KEY }} - project_id: ${{ secrets.GCP_PROJECT_ID }} - export_default_credentials: true - - - name: Install Terraform - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: 0.14.3 - # Reason: https://github.com/hashicorp/setup-terraform/issues/20 - terraform_wrapper: false - - - name: Terraform format - id: fmt - run: terraform fmt -check - - - name: Terraform init - id: init - run: terraform init - - - name: Terraform validate - id: validate - run: terraform validate -no-color - - - name: Terraform plan - id: plan - run: make plan-infrastructure - working-directory: . - - - name: Terraform update - if: github.ref == 'refs/heads/master' - run: make update-infrastructure - working-directory: . - - - name: Get yarn cache directory path - if: github.ref == 'refs/heads/master' - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - working-directory: . - - - name: Load cached node_modules - if: github.ref == 'refs/heads/master' - uses: actions/cache@v2 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install dependencies - if: github.ref == 'refs/heads/master' - run: yarn install --prefer-offline --frozen-lockfile - working-directory: . - - - name: Deploy to Kubernetes - if: github.ref == 'refs/heads/master' - run: make deploy - working-directory: . diff --git a/infrastructure/modules/k8s-ingress/main.tf b/infrastructure/modules/k8s-ingress/main.tf index 243ca93..823320b 100644 --- a/infrastructure/modules/k8s-ingress/main.tf +++ b/infrastructure/modules/k8s-ingress/main.tf @@ -58,8 +58,6 @@ resource "kubernetes_ingress" "ingress" { } } - # TODO why not host api on /api ? - # https://github.com/GoogleCloudPlatform/gke-bazel-demo/blob/e0d3856092c09c74f9e75e9307a24496c5f67eb6/js-client/manifests/deployment.yaml#L66 rule { host = "api.${var.domain}" http {