diff --git a/.github/workflows/agent-production.yml b/.github/workflows/agent-production.yml new file mode 100644 index 00000000..1865c0c9 --- /dev/null +++ b/.github/workflows/agent-production.yml @@ -0,0 +1,89 @@ +name: Agent Production + +on: + push: + branches: ['main'] + # check which application has been changed + paths: + - 'apps/agent/**' + - 'infra/docker/Dockerfile.agent' + - '.github/workflows/agent-production.yml' + + +env: + REGION: "us-east1" + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} + GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }} + SERVICE: "sahil-agent-production" + +jobs: + build: + name: Build - Push - Deploy + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + outputs: + output1: ${{ steps.step1.outputs.IMAGE }} + + steps: + - name: Clone + uses: actions/checkout@v3 + id: step1 + - run: | + echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-agent:production-$GITHUB_SHA" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # GCP auth + - name: Authenticate the service account + uses: google-github-actions/auth@v1 + with: + credentials_json: '${{ env.GCP_SA_KEY }}' + + - name: Install gcloud on the job runner + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: '${{ env.GCP_SA_KEY }}' + project_id: '${{ env.GCP_PROJECT_ID }}' + export_default_credentials: true + + - name: Authorize admin account to push docker image + run: gcloud auth configure-docker + + - name: Use gcloud CLI + run: 'gcloud info' + + # Buils & Push + - name: Build & Push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: infra/docker/Dockerfile.agent + #labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ env.IMAGE }} + + - name: Deploy to Cloud Run + id: deploy + uses: google-github-actions/deploy-cloudrun@v0 + with: + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.IMAGE }} + # NOTE: env variables here + # env_vars: | + # NODE_ENV=production + # PORT=3000 + + # If required, use the Cloud Run url output in later steps + - name: Show Output + run: | + - echo ${{ steps.deploy.outputs.url }} + - echo ${{ steps.step1.outputs.IMAGE }} diff --git a/.github/workflows/agent-staging-test.yml b/.github/workflows/agent-staging-test.yml new file mode 100644 index 00000000..8e79c21a --- /dev/null +++ b/.github/workflows/agent-staging-test.yml @@ -0,0 +1,88 @@ +name: Agent Stagging Test + +on: + pull_request: + types: [opened, synchronize] + # check which application has been changed + paths: + - 'apps/agent/**' + - 'infra/docker/Dockerfile.agent' + - '.github/workflows/agent-staging.yml' + + +env: + REGION: "us-central1" + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} + GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }} + SERVICE: "sahil-agent-stagging" + +jobs: + build: + name: Build - Push - Deploy + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + outputs: + output1: ${{ steps.step1.outputs.IMAGE }} + + steps: + - name: Clone + uses: actions/checkout@v3 + id: step1 + - run: | + echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-agent:stagging-$GITHUB_SHA" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # GCP auth + - name: Authenticate the service account + uses: google-github-actions/auth@v1 + with: + credentials_json: '${{ env.GCP_SA_KEY }}' + + - name: Install gcloud on the job runner + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: '${{ env.GCP_SA_KEY }}' + project_id: '${{ env.GCP_PROJECT_ID }}' + export_default_credentials: true + + - name: Authorize admin account to push docker image + run: gcloud auth configure-docker + + - name: Use gcloud CLI + run: 'gcloud info' + + - name: Build & Push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: infra/docker/Dockerfile.agent + #labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ env.IMAGE }} + + - name: Deploy to Cloud Run + id: deploy + uses: google-github-actions/deploy-cloudrun@v0 + with: + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.IMAGE }} + # NOTE: env variables here + # env_vars: | + # NODE_ENV=production + # PORT=3000 + + # If required, use the Cloud Run url output in later steps + - name: Show Output + run: | + - echo ${{ steps.deploy.outputs.url }} + - echo ${{ steps.step1.outputs.IMAGE }} diff --git a/.github/workflows/agent-staging.yml b/.github/workflows/agent-staging.yml new file mode 100644 index 00000000..5189ed7f --- /dev/null +++ b/.github/workflows/agent-staging.yml @@ -0,0 +1,88 @@ +name: Agent Stagging + +on: + push: + branches: ['develop'] + # check which application has been changed + paths: + - 'apps/agent/**' + - 'infra/docker/Dockerfile.agent' + - '.github/workflows/agent-staging.yml' + + +env: + REGION: "us-central1" + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} + GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }} + SERVICE: "sahil-agent-stagging" + +jobs: + build: + name: Build - Push - Deploy + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + outputs: + output1: ${{ steps.step1.outputs.IMAGE }} + + steps: + - name: Clone + uses: actions/checkout@v3 + id: step1 + - run: | + echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-agent:stagging-$GITHUB_SHA" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # GCP auth + - name: Authenticate the service account + uses: google-github-actions/auth@v1 + with: + credentials_json: '${{ env.GCP_SA_KEY }}' + + - name: Install gcloud on the job runner + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: '${{ env.GCP_SA_KEY }}' + project_id: '${{ env.GCP_PROJECT_ID }}' + export_default_credentials: true + + - name: Authorize admin account to push docker image + run: gcloud auth configure-docker + + - name: Use gcloud CLI + run: 'gcloud info' + + - name: Build & Push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: infra/docker/Dockerfile.agent + #labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ env.IMAGE }} + + - name: Deploy to Cloud Run + id: deploy + uses: google-github-actions/deploy-cloudrun@v0 + with: + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.IMAGE }} + # NOTE: env variables here + # env_vars: | + # NODE_ENV=production + # PORT=3000 + + # If required, use the Cloud Run url output in later steps + - name: Show Output + run: | + - echo ${{ steps.deploy.outputs.url }} + - echo ${{ steps.step1.outputs.IMAGE }} diff --git a/.github/workflows/api-production.yml b/.github/workflows/api-production.yml new file mode 100644 index 00000000..363c3fb3 --- /dev/null +++ b/.github/workflows/api-production.yml @@ -0,0 +1,89 @@ +name: API Production + +on: + push: + branches: ['main'] + # check which application has been changed + paths: + - 'apps/api/**' + - 'infra/docker/Dockerfile.api' + - '.github/workflows/api-production.yml' + + +env: + REGION: "us-east1" + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} + GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }} + SERVICE: "sahil-api-production" + +jobs: + build: + name: Build - Push - Deploy + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + outputs: + output1: ${{ steps.step1.outputs.IMAGE }} + + steps: + - name: Clone + uses: actions/checkout@v3 + id: step1 + - run: | + echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-api:production-$GITHUB_SHA" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # GCP auth + - name: Authenticate the service account + uses: google-github-actions/auth@v1 + with: + credentials_json: '${{ env.GCP_SA_KEY }}' + + - name: Install gcloud on the job runner + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: '${{ env.GCP_SA_KEY }}' + project_id: '${{ env.GCP_PROJECT_ID }}' + export_default_credentials: true + + - name: Authorize admin account to push docker image + run: gcloud auth configure-docker + + - name: Use gcloud CLI + run: 'gcloud info' + + # Buils & Push + - name: Build & Push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: infra/docker/Dockerfile.api + #labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ env.IMAGE }} + + - name: Deploy to Cloud Run + id: deploy + uses: google-github-actions/deploy-cloudrun@v0 + with: + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.IMAGE }} + # NOTE: env variables here + # env_vars: | + # NODE_ENV=production + # PORT=3000 + + # If required, use the Cloud Run url output in later steps + - name: Show Output + run: | + - echo ${{ steps.deploy.outputs.url }} + - echo ${{ steps.step1.outputs.IMAGE }} diff --git a/.github/workflows/api-staging.yml b/.github/workflows/api-staging.yml new file mode 100644 index 00000000..6c677aaf --- /dev/null +++ b/.github/workflows/api-staging.yml @@ -0,0 +1,88 @@ +name: API Stagging + +on: + push: + branches: ['develop'] + # check which application has been changed + paths: + - 'apps/api/**' + - 'infra/docker/Dockerfile.api' + - '.github/workflows/api-staging.yml' + + +env: + REGION: "us-central1" + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} + GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }} + SERVICE: "sahil-api-stagging" + +jobs: + build: + name: Build - Push - Deploy + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + outputs: + output1: ${{ steps.step1.outputs.IMAGE }} + + steps: + - name: Clone + uses: actions/checkout@v3 + id: step1 + - run: | + echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-api:stagging-$GITHUB_SHA" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # GCP auth + - name: Authenticate the service account + uses: google-github-actions/auth@v1 + with: + credentials_json: '${{ env.GCP_SA_KEY }}' + + - name: Install gcloud on the job runner + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: '${{ env.GCP_SA_KEY }}' + project_id: '${{ env.GCP_PROJECT_ID }}' + export_default_credentials: true + + - name: Authorize admin account to push docker image + run: gcloud auth configure-docker + + - name: Use gcloud CLI + run: 'gcloud info' + + - name: Build & Push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: infra/docker/Dockerfile.api + #labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ env.IMAGE }} + + - name: Deploy to Cloud Run + id: deploy + uses: google-github-actions/deploy-cloudrun@v0 + with: + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.IMAGE }} + # NOTE: env variables here + # env_vars: | + # NODE_ENV=production + # PORT=3000 + + # If required, use the Cloud Run url output in later steps + - name: Show Output + run: | + - echo ${{ steps.deploy.outputs.url }} + - echo ${{ steps.step1.outputs.IMAGE }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1b739ecf..b739a218 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -22,6 +22,7 @@ on: jobs: analyze: name: Analyze + if: ${{ false }} # disable for now # Runner size impacts CodeQL analysis time. To learn more, please see: # - https://gh.io/recommended-hardware-resources-for-running-codeql # - https://gh.io/supported-runners-and-hardware-resources diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5ec5a4d..2ca5d5db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,21 +1,15 @@ name: Test on Pull Request & Push on: - push: - branches: ['main', 'develop'] pull_request: types: [opened, synchronize] jobs: build: name: Format, Build and Test - #if: ${{ false }} # disable for now + if: ${{ false }} # disable for now timeout-minutes: 15 runs-on: ubuntu-latest - # To use Remote Caching, uncomment the next lines and follow the steps below. - # env: - # TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} - # TURBO_TEAM: ${{ vars.TURBO_TEAM }} strategy: matrix: @@ -30,6 +24,28 @@ jobs: with: node-version: ${{ matrix.node-version }} + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache node modules + id: cache-yarn + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: $ {{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - if: ${{ steps.cache-yarn.outputs.cache-hit != 'true' }} + name: List the state of node modules + continue-on-error: true + run: yarn list + - name: Install dependencies run: yarn install --frozen-lockfile --ignore-engines diff --git a/.github/workflows/website-production.yml b/.github/workflows/website-production.yml new file mode 100644 index 00000000..1d7dc45c --- /dev/null +++ b/.github/workflows/website-production.yml @@ -0,0 +1,89 @@ +name: Website Production + +on: + push: + branches: ['main'] + # check which application has been changed + paths: + - 'apps/website/**' + - 'infra/docker/Dockerfile.website' + - '.github/workflows/website-production.yml' + + +env: + REGION: "us-east1" + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} + GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }} + SERVICE: "sahil-website-production" + +jobs: + build: + name: Build - Push - Deploy + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + + outputs: + output1: ${{ steps.step1.outputs.IMAGE }} + + steps: + - name: Clone + uses: actions/checkout@v3 + id: step1 + - run: | + echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-website:production-$GITHUB_SHA" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # GCP auth + - name: Authenticate the service account + uses: google-github-actions/auth@v1 + with: + credentials_json: '${{ env.GCP_SA_KEY }}' + + - name: Install gcloud on the job runner + uses: google-github-actions/setup-gcloud@v1 + with: + service_account_key: '${{ env.GCP_SA_KEY }}' + project_id: '${{ env.GCP_PROJECT_ID }}' + export_default_credentials: true + + - name: Authorize admin account to push docker image + run: gcloud auth configure-docker + + - name: Use gcloud CLI + run: 'gcloud info' + + # Buils & Push + - name: Build & Push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: infra/docker/Dockerfile.website + #labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ env.IMAGE }} + + - name: Deploy to Cloud Run + id: deploy + uses: google-github-actions/deploy-cloudrun@v0 + with: + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.IMAGE }} + # NOTE: env variables here + # env_vars: | + # NODE_ENV=production + # PORT=3000 + + # If required, use the Cloud Run url output in later steps + - name: Show Output + run: | + - echo ${{ steps.deploy.outputs.url }} + - echo ${{ steps.step1.outputs.IMAGE }} diff --git a/.github/workflows/website-staging.yml b/.github/workflows/website-staging.yml index 8f401743..a22353d4 100644 --- a/.github/workflows/website-staging.yml +++ b/.github/workflows/website-staging.yml @@ -1,26 +1,42 @@ -name: Website Stagging to Cloud Run +name: Website Stagging on: push: - branches: - - develop + branches: ['develop'] + # check which application has been changed + paths: + - 'apps/website/**' + - 'infra/docker/Dockerfile.website' + - '.github/workflows/website-staging.yml' + env: - REGION: "us-east1" + REGION: "us-central1" GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} GCP_PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }} + SERVICE: "sahil-website-stagging" jobs: build: - name: Build the app + name: Build - Push - Deploy runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + outputs: + output1: ${{ steps.step1.outputs.IMAGE }} + steps: - name: Clone uses: actions/checkout@v3 - - run: echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-web-dev:$GITHUB_SHA" >> $GITHUB_ENV + id: step1 + - run: | + echo "IMAGE=gcr.io/${{ env.GCP_PROJECT_ID }}/sahil-website:stagging-$GITHUB_SHA" >> $GITHUB_ENV + # GCP auth - name: Authenticate the service account uses: google-github-actions/auth@v1 with: @@ -39,34 +55,53 @@ jobs: - name: Use gcloud CLI run: 'gcloud info' - - name: Build a docker image - run: |- - docker build -f infra/docker/Dockerfile.website -t ${{ env.IMAGE }} . + # Buils & Push + - name: Build & Push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + file: infra/docker/Dockerfile.website + #labels: ${{ steps.meta.outputs.labels }} + push: true + tags: ${{ env.IMAGE }} - - name: Push image to gcr.io - run: docker push ${{ env.IMAGE }} + - name: Deploy to Cloud Run + id: deploy + uses: google-github-actions/deploy-cloudrun@v0 + with: + service: ${{ env.SERVICE }} + region: ${{ env.REGION }} + image: ${{ env.IMAGE }} + # NOTE: env variables here + # env_vars: | + # NODE_ENV=production + # PORT=3000 - stagging: - needs: build - name: Deploy to stagging env - runs-on: ubuntu-latest + # If required, use the Cloud Run url output in later steps + - name: Show Output + run: | + - echo ${{ steps.deploy.outputs.url }} + - echo ${{ steps.step1.outputs.IMAGE }} - steps: - - name: Clone - uses: actions/checkout@v3 + # stagging: + # needs: build + # name: Deploy to stagging env + # runs-on: ubuntu-latest - - name: Terraform Plan and Apply - working-directory: infra/terraform/cloudrun - run: | - terraform init - terraform plan \ - -out=tfplan \ - -var="project_id=${{ env.GCP_PROJECT_ID }}" \ - -var="project_number=${{env.GCP_PROJECT_NUMBER}}" \ - -var="service_account=${{env.GCP_PROJECT_NUMBER}}-compute@developer.gserviceaccount.com" \ - -var="region=${{ env.REGION }}" \ - -var="service_name=sahil-website-development" \ - -var="image_url=${{ env.IMAGE }}" \ - -var="concurrency=80" \ - -var="timeout=300" \ - terraform apply tfplan + # - name: Terraform Plan and Apply + # working-directory: infra/terraform/cloudrun + # run: | + # terraform init + # terraform plan \ + # -out=tfplan \ + # -var="project_id=${{ env.GCP_PROJECT_ID }}" \ + # -var="project_number=${{env.GCP_PROJECT_NUMBER}}" \ + # -var="service_account=${{env.GCP_PROJECT_NUMBER}}-compute@developer.gserviceaccount.com" \ + # -var="region=us-central1" \ + # -var="service_name=sahil-test" \ + # -var="image_url=${{ env.IMAGE }}" \ + # -var="concurrency=80" \ + # -var="timeout=300" \ + # terraform apply tfplan diff --git a/docker-compose.yml b/docker-compose.yml index 6d3fe34f..970589ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,12 +7,12 @@ services: build: context: . dockerfile: ./infra/docker/Dockerfile.website - image: sahil-website-test - env_file: - - .env + image: sahil-website restart: always ports: - '3000:3000' + env_file: + - path: ./apps/website/.env # API sahil-api: