-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (99 loc) · 3.51 KB
/
order-item-api.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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