Skip to content

Commit

Permalink
feat: only deploy on releases
Browse files Browse the repository at this point in the history
  • Loading branch information
flolu committed Mar 24, 2021
1 parent 769607b commit 8d27772
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 79 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -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: .
78 changes: 1 addition & 77 deletions .github/workflows/ci-cd.yaml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci-cd
name: test
on: push
jobs:
check-code:
Expand Down Expand Up @@ -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: .
2 changes: 0 additions & 2 deletions infrastructure/modules/k8s-ingress/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8d27772

Please sign in to comment.