GCP Computing - Cloud Build
GCP Computing - Cloud Build
Deploy
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
gcloud auth list
nano quickstart.sh
#!/bin/sh
echo "Hello, world! The time is $(date)."
nano Dockerfile
# Dockerfile
FROM alpine
COPY quickstart.sh /
CMD ["/quickstart.sh"]
chmod +x quickstart.sh
gcloud artifacts repositories create quickstart-docker-repo \
--repository-format=docker \
--location=us-west1 \
--description="Docker repository"
gcloud builds submit \
--tag us-west1-docker.pkg.dev/${DEVSHELL_PROJECT_ID}/quickstart-docker-repo/quickstart-image:tag1
nano cloudbuild.yaml
# cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'YourRegionHere-docker.pkg.dev/$PROJECT_ID/quickstart-docker-repo/quickstart-image:tag1', '.' ]
images:
- 'YourRegionHere-docker.pkg.dev/$PROJECT_ID/quickstart-docker-repo/quickstart-image:tag1'
export REGION=us-west1
sed -i "s/YourRegionHere/$REGION/g" cloudbuild.yaml
gcloud builds submit --config cloudbuild.yaml
nano quickstart.sh
#!/bin/sh
if [ -z "$1" ]
then
echo "Hello, world! The time is $(date)."
exit 0
else
exit 1
fi
nano cloudbuild2.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'YourRegionHere-docker.pkg.dev/$PROJECT_ID/quickstart-docker-repo/quickstart-image:tag1', '.' ]
- name: 'YourRegionHere-docker.pkg.dev/$PROJECT_ID/quickstart-docker-repo/quickstart-image:tag1'
args: ['fail']
images:
- 'YourRegionHere-docker.pkg.dev/$PROJECT_ID/quickstart-docker-repo/quickstart-image:tag1'
sed -i "s/YourRegionHere/$REGION/g" cloudbuild2.yaml
gcloud builds submit --config cloudbuild2.yaml
This post is licensed under CC BY 4.0 by the author.
Comments powered by Disqus.