forked from shivaaws69/Wisdom-School-Spring-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild-add.yaml
More file actions
60 lines (53 loc) · 1.82 KB
/
cloudbuild-add.yaml
File metadata and controls
60 lines (53 loc) · 1.82 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
steps:
# Step 1: Get the commit ID
- name: gcr.io/cloud-builders/git
id: "get-commit-id"
entrypoint: "bash"
args:
- "-c"
- |
echo "Source code is already cloned by Cloud Build."
git fetch --unshallow
newcommit=$(git rev-parse --short=6 HEAD)
echo "Commit ID is: $newcommit"
echo "$newcommit" > /workspace/commit_id # ✅ Save commit ID for later use
# Step 2: Set up JDK (for Maven)
- name: gcr.io/cloud-builders/mvn
args:
- clean
- package
# Step 3: Authenticate to Google Cloud
- name: gcr.io/cloud-builders/gcloud
args:
- auth
- configure-docker
- asia-south1-docker.pkg.dev
# Step 4: Build the Docker image with commit ID as tag
- name: gcr.io/cloud-builders/docker
id: "build-image"
entrypoint: "bash"
args:
- "-c"
- |
newcommit=$(cat /workspace/commit_id) # ✅ Retrieve commit ID
repo="asia-south1-docker.pkg.dev/${_PROJECT_ID}/newschool/sch" # ✅ Ensure no spaces
repo=$(echo $repo | tr -d ' ') # ✅ Remove any unwanted spaces
echo "Building Docker image: $repo:$newcommit"
docker build -t "$repo:$newcommit" .
# Step 5: Push the Docker image with commit ID as tag
- name: gcr.io/cloud-builders/docker
id: "push-image"
entrypoint: "bash"
args:
- "-c"
- |
newcommit=$(cat /workspace/commit_id) # ✅ Retrieve commit ID
repo="asia-south1-docker.pkg.dev/${_PROJECT_ID}/newschool/sch" # ✅ Ensure no spaces
repo=$(echo $repo | tr -d ' ') # ✅ Remove any unwanted spaces
echo "Pushing Docker image: $repo:$newcommit"
docker push "$repo:$newcommit"
# images:
# - "asia-south1-docker.pkg.dev/${_PROJECT_ID}/newschool/sch:$newcommit"
logsBucket: gs://school-build-logs
options:
logging: GCS_ONLY