-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathci.yaml
143 lines (130 loc) · 3.81 KB
/
ci.yaml
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
substitutions:
# Cloud deploy vars
_ARTIFACT_REGISTRY_URI: us-central1-docker.pkg.dev/open-match-build/om2
_JOB_NAME: om-core
_SERVICE_ACCOUNT: [email protected]
_RUN_REGION: us-central1
# Application environment vars
_OM_LOGGING_LEVEL: info
_OM_REDIS_WRITE_HOST: 10.82.52.86
_OM_REDIS_READ_HOST: 10.82.52.85
steps:
# Update dependencies and build image
- name: 'golang:1.23'
id: "Update Dependencies"
entrypoint: bash
args:
- -c
- |
go get -u
go mod tidy
# Run unit tests
- name: 'golang:1.23'
id: "Unit Tests"
waitFor: ["Update Dependencies"]
entrypoint: go
args: ['test', './...']
# Build
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
id: "Build"
waitFor: ["Update Dependencies"]
entrypoint: gcloud
args:
- builds
- submit
- --pack
- image=${_ARTIFACT_REGISTRY_URI}/${_JOB_NAME}:${COMMIT_SHA}
# Deploy existing container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
id: "Deploy:ingress vpc, all egress vpc"
waitFor: ["Build"]
entrypoint: gcloud
args:
- run
- deploy
# service config
- ${_JOB_NAME}
- --no-allow-unauthenticated
- --concurrency
- "1000"
- --service-account
- ${_SERVICE_ACCOUNT}
- --region
- ${_RUN_REGION}
# Network config
- --network
- default
- --subnet
- default
- --vpc-egress
- all-traffic
# ingress config
- --ingress
- all
# sidecar 'otel-collector' config
- --container
- "opentelemetry-collector"
- --image
- '${_ARTIFACT_REGISTRY_URI}/otel-collector-sidecar'
# 'core' config
- --container
- "core"
- --image
- '${_ARTIFACT_REGISTRY_URI}/${_JOB_NAME}:${COMMIT_SHA}'
- --port
- "8080"
- --memory
- 1024Mi
# env vars for 'core'
- --update-env-vars
- "OM_LOGGING_LEVEL=${_OM_LOGGING_LEVEL}"
- --update-env-vars
- "OM_REDIS_WRITE_HOST=${_OM_REDIS_WRITE_HOST}"
- --update-env-vars
- "OM_REDIS_READ_HOST=${_OM_REDIS_READ_HOST}"
# Simple E2E test on ticket creation
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
id: "Test:service health check"
waitFor: ["Deploy:ingress vpc, all egress vpc"]
entrypoint: 'bash'
args:
- -c
- |
# Exit on any error
set -e
echo "Test starts!"
# Create the static ticket JSON
cat > ticket.json << EOF
{
"ticket": {
"attributes": {
"tags": [
"1716274574658687844"
],
"stringArgs": {
"class": "dps"
},
"doubleArgs": {
"1716274574658687844": 1716274574658687700
},
"creationTime": "2024-05-21T06:56:14.658687844Z"
}
}
}
EOF
# Impersonate the service account
TOKEN=$(gcloud auth print-identity-token \
--impersonate-service-account=${_SERVICE_ACCOUNT})
# Make the request and store response
response=$(curl -s -H "Authorization: Bearer $${TOKEN}" \
-d "@ticket.json" \
https://om-core-205790239254.us-central1.run.app/tickets)
echo "Response: $${response}"
# Validate response format
if ! echo "$${response}" | grep -qE '^\{"ticketId":"[0-9]+-[0-9]+"\}$'; then
echo "Error: Response format is incorrect"
echo "Expected format: {\"ticketId\":\"NUMBER-NUMBER\"}"
echo "Received: $${response}"
exit 1
fi
echo "Test passed successfully!"