forked from shivaaws69/Wisdom-School-Spring-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild-version.yaml
More file actions
137 lines (116 loc) · 4.06 KB
/
cloudbuild-version.yaml
File metadata and controls
137 lines (116 loc) · 4.06 KB
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
steps:
# Step 1: Retrieve the latest version or initialize v1.0
- name: gcr.io/cloud-builders/gcloud
id: "get-version"
entrypoint: "bash"
args:
- "-c"
- |
if gsutil stat gs://school-build-logs/version.txt; then
gsutil cp gs://school-build-logs/version.txt version.txt
newversion=$(cat version.txt)
else
newversion="v1.0"
fi
echo "Previous Version: $newversion"
# Extract major and minor versions
major=$(echo $newversion | cut -d'.' -f1 | sed 's/v//')
minor=$(echo $newversion | cut -d'.' -f2)
# Increment minor version
newversion="v${major}.$((minor + 1))"
echo "New Version: $newversion"
echo "$newversion" > version.txt
# Step 2: Build the Maven project
- name: gcr.io/cloud-builders/mvn
args:
- clean
- package
# Step 3: Authenticate Docker with Google Cloud
- name: gcr.io/cloud-builders/gcloud
args:
- auth
- configure-docker
- asia-south1-docker.pkg.dev
# Step 4: Build the Docker image with the new version tag
- name: gcr.io/cloud-builders/docker
id: "build-image"
entrypoint: "bash"
args:
- "-c"
- |
newversion=$(cat version.txt)
docker build -t asia-south1-docker.pkg.dev/aqueous-cortex-445305-m6/newschool/sch:$newversion .
# Step 5: Push the Docker image with the new version tag
- name: gcr.io/cloud-builders/docker
id: "push-image"
entrypoint: "bash"
args:
- "-c"
- |
newversion=$(cat version.txt)
docker push asia-south1-docker.pkg.dev/aqueous-cortex-445305-m6/newschool/sch:$newversion
# Step 6: Save the new version to a GCS bucket for the next build
- name: gcr.io/cloud-builders/gsutil
args: ["cp", "version.txt", "gs://school-build-logs/version.txt"]
images:
- "asia-south1-docker.pkg.dev/aqueous-cortex-445305-m6/newschool/sch"
logsBucket: gs://school-build-logs
# steps:
# # Step 1: Retrieve the latest version or initialize v1.0
# - name: gcr.io/cloud-builders/gcloud
# id: "get-version"
# entrypoint: "bash"
# args:
# - "-c"
# - |
# if gsutil stat gs://school-build-logs/version.txt; then
# gsutil cp gs://school-build-logs/version.txt version.txt
# newversion=$(cat version.txt)
# else
# newversion="v1.0"
# fi
# echo "Previous Version: $newversion"
# # Extract major and minor versions
# newmajor=$(echo $newversion | cut -d'.' -f1 | sed 's/v//')
# newminor=$(echo $newversion | cut -d'.' -f2)
# # Increment minor version
# newversion="v${newmajor}.$((newminor + 1))"
# echo "New Version: $newversion"
# echo $newversion > version.txt
# # Step 2: Build the Maven project
# - name: gcr.io/cloud-builders/mvn
# args:
# - clean
# - package
# # Step 3: Authenticate Docker with Google Cloud
# - name: gcr.io/cloud-builders/gcloud
# args:
# - auth
# - configure-docker
# - asia-south1-docker.pkg.dev
# # Step 4: Build the Docker image with the new version tag
# - name: gcr.io/cloud-builders/docker
# id: "build-image"
# entrypoint: "bash"
# args:
# - "-c"
# - |
# newversion=$(cat version.txt)
# docker build -t asia-south1-docker.pkg.dev/$_PROJECT_ID/newschool/sch:$newversion .
# # Step 5: Push the Docker image with the new version tag
# - name: gcr.io/cloud-builders/docker
# id: "push-image"
# entrypoint: "bash"
# args:
# - "-c"
# - |
# newversion=$(cat version.txt)
# docker push asia-south1-docker.pkg.dev/$_PROJECT_ID/newschool/sch:$newversion
# # Step 6: Save the new version to a GCS bucket for the next build
# - name: gcr.io/cloud-builders/gsutil
# args: ["cp", "version.txt", "gs://school-build-logs/version.txt"]
# images:
# - "asia-south1-docker.pkg.dev/$_PROJECT_ID/newschool"
# logsBucket: gs://school-build-logs # Option 1 (Use GCS logs)
# # options:
# # logging: CLOUD_LOGGING_ONLY # Option 2 (Use Cloud Logging)