Skip to content

chore: working on integrating turborepo remote cache #132

chore: working on integrating turborepo remote cache

chore: working on integrating turborepo remote cache #132

Workflow file for this run

name: Terraform
on: [push]
env:
REGION: ${{ vars.FVST_PROJECT_REGION }}
DOCKER_TAG: gh-run-${{ github.run_number }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- service: "blog-graphql"
use_prisma: true
environment: "staging"
google_cloud_token: "GOOGLE_CLOUD_TOKEN_STAGING"
turborepo_bucket: "FVST_PROJECT_TURBOREPO_BUCKET_STAGING"
- service: "todo-graphql"
use_prisma: true
environment: "staging"
google_cloud_token: "GOOGLE_CLOUD_TOKEN_STAGING"
turborepo_bucket: "FVST_PROJECT_TURBOREPO_BUCKET_STAGING"
- service: "user-graphql"
use_prisma: true
environment: "staging"
google_cloud_token: "GOOGLE_CLOUD_TOKEN_STAGING"
turborepo_bucket: "FVST_PROJECT_TURBOREPO_BUCKET_STAGING"
- service: "graphql-gateway"
use_prisma: false
environment: "staging"
google_cloud_token: "GOOGLE_CLOUD_TOKEN_STAGING"
turborepo_bucket: "FVST_PROJECT_TURBOREPO_BUCKET_STAGING"
env:
PROJECT: ${{ vars.FVST_PROJECT_PREFIX }}-fvst-${{matrix.environment}}
REGISTRY: ${{ vars.FVST_PROJECT_REGION }}-docker.pkg.dev/${{ vars.FVST_PROJECT_PREFIX }}-fvst-${{matrix.environment}}/registry
steps:
- uses: "actions/checkout@v3"
- uses: ./.github/actions/setup-google-cloud-auth
id: "auth"
with:
google_cloud_token: ${{ secrets[matrix.google_cloud_token] }}
region: ${{ vars.FVST_PROJECT_REGION }}
- uses: ./.github/actions/setup-turborepo-remote-cache
id: "turborepo-cache"
with:
bucket: ${{ vars[matrix.turborepo_bucket] }}
#
# - name: Login to Artifact Registry
# uses: docker/login-action@v2
# with:
# registry: ${{ vars.FVST_PROJECT_REGION }}-docker.pkg.dev
# username: oauth2accesstoken
# password: ${{ steps.auth.outputs.access_token }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
allow: network.host
tags: ${{env.REGISTRY}}/${{matrix.service}}:${{env.DOCKER_TAG}},${{env.REGISTRY}}/${{matrix.service}}:latest
file: tooling/docker/nest/Dockerfile
cache-from: type=registry,ref=${{env.REGISTRY}}/${{matrix.service}}:buildcache
cache-to: type=registry,ref=${{env.REGISTRY}}/${{matrix.service}}:buildcache,mode=max
build-args: |
APP_NAME=${{ matrix.service }}
TURBO_TOKEN=${{ steps.turborepo-cache.outputs.TURBO_TOKEN }}
TURBO_TEAMID=${{ steps.turborepo-cache.outputs.TURBO_TEAMID }}
TURBO_API=${{ steps.turborepo-cache.outputs.TURBO_API_FOR_DOCKER }}
deploy:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
include:
- environment: staging
google_cloud_token: GOOGLE_CLOUD_TOKEN_STAGING
terraform_bucket: FVST_PROJECT_TF_STATE_BUCKET_STAGING
# - environment: production
# google_cloud_token: GOOGLE_CLOUD_TOKEN_PRODUCTION
# terraform_bucket: FVST_PROJECT_TF_STATE_BUCKET_PRODUCTION
env:
PROJECT: ${{ vars.FVST_PROJECT_PREFIX }}-fvst-${{matrix.environment}}
GOOGLE_CLOUD_TOKEN_ENV: ${{ secrets[matrix.google_cloud_token] }}
TERRAFORM_BUCKET: ${{ vars[matrix.terraform_bucket] }}
TF_VAR_project: ${{ vars.FVST_PROJECT_PREFIX }}-fvst-${{matrix.environment}}
TF_VAR_region: ${{ vars.FVST_PROJECT_REGION }}
steps:
- uses: "actions/checkout@v3"
- name: "Unpack Key"
id: "google-key"
run: |
GOOGLE_CLOUD_TOKEN=$(echo $GOOGLE_CLOUD_TOKEN_ENV | base64 --decode)
echo "GOOGLE_CLOUD_TOKEN=$GOOGLE_CLOUD_TOKEN" >> $GITHUB_OUTPUT
- name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{steps.google-key.outputs.GOOGLE_CLOUD_TOKEN}}"
export_environment_variables: true
create_credentials_file: true
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
- name: Info
run: gcloud info
- name: Setup terraform remote and configuration
run: |
cat <<EOT >> "./infra/envs/${{matrix.environment}}/backend.tf"
terraform {
backend "gcs" {
bucket = "$TERRAFORM_BUCKET"
}
}
EOT
- name: Terraform init
working-directory: ./infra/envs/${{matrix.environment}}
run: terraform init
- name: Terraform apply
working-directory: ./infra/envs/${{matrix.environment}}
run: terraform apply -auto-approve