-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathcloudbuild.yaml
88 lines (82 loc) · 2.8 KB
/
cloudbuild.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
options:
logging: CLOUD_LOGGING_ONLY
substitutions:
_BUILD_ENV: "test" # Set this to the target environment (test, release, etc.)
_FIREBASE_PROJECT_ID: "your-project-id" # Replacing with dynamic project ID
_FIREBASE_SITE_ID: "${_BUILD_ENV}_site_id" # Placeholder for Firebase site ID
steps:
# Step 1: Install Node.js dependencies
- name: 'gcr.io/cloud-builders/npm'
entrypoint: 'sh'
args:
- '-c'
- |
echo clean
npm cache clean --force
echo remove
rm -rf node_modules package-lock.json
echo Installing source NPM dependencies...
npm install
# Step 2: Conditionally run builds based on _BUILD_ENV
- name: 'gcr.io/cloud-builders/npm'
entrypoint: 'sh'
args:
- '-c'
- |
echo "Build env:" ${_BUILD_ENV}
if [ "${_BUILD_ENV}" = "test" ]; then
npm run build-test;
elif [ "${_BUILD_ENV}" = "release" ]; then
npm run build-release;
elif [ "${_BUILD_ENV}" = "staging" ]; then
npm run build-staging;
elif [ "${_BUILD_ENV}" = "prod" ]; then
npm run build-prod;
elif [ "${_BUILD_ENV}" = "prod-enterprise" ]; then
npm run build-prod-enterprise;
elif [ "${_BUILD_ENV}" = "prod-in" ]; then
npm run build-prod-in;
elif [ "${_BUILD_ENV}" = "prod-eu" ]; then
npm run build-prod-eu;
elif [ "${_BUILD_ENV}" = "prod-cn" ]; then
npm run build-prod-cn;
elif [ "${_BUILD_ENV}" = "prod_beta" ]; then
npm run build-beta;
else
npm run build-test;
fi
# Step 3: Updated firebase.json dynamically
- name: 'alpine'
entrypoint: 'sh'
args:
- '-c'
- |
echo "Updating firebase.json with site ID..."
# Update the site ID dynamically
sed -i 's/"site": ".*"/"site": "'"${_FIREBASE_SITE_ID}"'"/' firebase.json
# Step 4: Validating the build directory contains index.html
- name: 'alpine'
entrypoint: 'sh'
args:
- '-c'
- |
echo "Checking if webplugin/build contains index.html..."
if [ ! -f "webplugin/build/index.html" ]; then
echo "Error: index.html not found in webplugin/build. Build process might have failed."
exit 1
fi
echo "firebase.json exists, now validating its structure..."
if [ ! -f "firebase.json" ]; then
echo "Error: firebase.json file does not exist."
exit 1
fi
# Step 5: Deploy to Firebase Hosting
- name: 'gcr.io/$PROJECT_ID/firebase'
args:
- 'deploy'
- '--only'
- 'hosting:${_FIREBASE_SITE_ID}'
- '--project'
- '${_FIREBASE_PROJECT_ID}'
- '--token'
- '${_FIREBASE_TOKEN}'