Skip to content

Merge pull request #29 from alexandreafj/snyk-fix-3115f8e8dcbf0feb536… #42

Merge pull request #29 from alexandreafj/snyk-fix-3115f8e8dcbf0feb536…

Merge pull request #29 from alexandreafj/snyk-fix-3115f8e8dcbf0feb536… #42

on:
push:
branches:
- master
paths:
- 'order-item-api/**'
- '!**.md'
name: Build/Deploy new Revision
env:
DOCKER_ROOT_IMAGE_NAME: order-item-api:${{github.sha}}
DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_IMAGE_NAME }}/order-item-api:${{github.sha}}
REGION: ${{ secrets.REGION }}
PROJECT_ID: ${{ secrets.PROJECT_ID }}
defaults:
run:
working-directory: order-item-api
jobs:
running-unity-tests:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: install dependencies
run: npm ci
- name: run unity tests
run: npm t
build:
needs: [running-unity-tests]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup google cloud sdk
uses: google-github-actions/auth@v0
with:
project_id: ${{ secrets.PROJECT_ID }}
credentials_json: ${{ secrets.GCP_CREDENTIALS_PIPELINE }}
- name: authorize docker push
run: gcloud auth configure-docker us-central1-docker.pkg.dev
- name: build image
run: docker build -t ${{env.DOCKER_ROOT_IMAGE_NAME}} .
- name: tag image
run: docker tag ${{env.DOCKER_ROOT_IMAGE_NAME}} ${{env.DOCKER_IMAGE_NAME}}
- name: push image
run: docker push ${{env.DOCKER_IMAGE_NAME}}
deploy-revision:
needs: [build]
runs-on: ubuntu-latest
environment: production
env:
TF_VAR_container_registry_docker_image: ${{ secrets.DOCKER_IMAGE_NAME }}/order-item-api:${{github.sha}}
TF_VAR_gcp_project: ${{ secrets.PROJECT_ID }}
TF_VAR_gcp_region: ${{ secrets.REGION }}
TF_VAR_gcp_instance_unix_socket: ${{ secrets.INSTANCE_UNIX_SOCKET }}
TF_VAR_mysql_username: ${{ secrets.GCP_MYSQL_USERNAME }}
TF_VAR_mysql_password: ${{ secrets.GCP_MYSQL_PASSWORD }}
TF_VAR_mysql_database: ${{ secrets.GCP_MYSQL_DATABASE }}
TF_VAR_redis_namespace: ${{ secrets.REDIS_NAMESPACE }}
TF_VAR_redis_host: ${{ secrets.GCP_REDIS_HOST }}
TF_VAR_gcp_sql_database_name: ${{ secrets.GCP_SQL_NAME }}
TF_VAR_new_relic_license_key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
TF_VAR_new_relic_app_name: ${{ secrets.NEW_RELIC_APP_NAME }}
GOOGLE_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS_PIPELINE }}
defaults:
run:
shell: bash
working-directory: order-item-api/terraform
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
cli_config_credentials_hostname: app.terraform.io
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Terraform Init
id: init
run: terraform init
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Format
id: format
run: terraform fmt && terraform fmt -check
- name: Terraform Plan
id: plan
run: terraform plan
continue-on-error: true
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: terraform apply -auto-approve