-
Notifications
You must be signed in to change notification settings - Fork 29
/
@orb.yml
173 lines (163 loc) · 5.99 KB
/
@orb.yml
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
version: 2.1
description: >
An orb for working with Google Container Registry (GCR)
examples:
simple_build_and_push:
description: Log into Google Cloud Plaform, build and push image to GCR
usage:
version: 2.1
orbs:
gcp-gcr: circleci/gcp-gcr@1.0.0
workflows:
build_and_push_image:
jobs:
- gcp-gcr/build_and_push_image_using_remote_docker:
context: myContext # your context containing gcloud login variables
google-project-id: myGoogleProjectId
google-compute-zone: myGoogleComputeZone
registry-url: us.gcr.io # gcr.io, eu.gcr.io, asia.gcr.io
image: my-image # your image name
tag: latest
orbs:
gcp-cli: circleci/gcp-cli@1.0.2
executors:
default:
description: >
A debian-based machine executor.
machine: true
commands:
gcr-auth:
description: >
Configure Docker to use gcloud as a credential helper. Using this command requires the use of a 'machine' executor.
parameters:
gcloud-service-key:
description: The gcloud service key
type: env_var_name
default: GCLOUD_SERVICE_KEY
google-project-id:
description: Environment variable name for the Google project ID to connect with via the gcloud CLI
type: env_var_name
default: GOOGLE_PROJECT_ID
google-compute-zone:
description: The Google compute zone to connect with via the gcloud CLI
type: env_var_name
default: GOOGLE_COMPUTE_ZONE
steps:
- gcp-cli/install
- gcp-cli/initialize:
google-project-id: <<parameters.google-project-id>>
google-compute-zone: <<parameters.google-compute-zone>>
- run:
name: gcloud alpha auth configure-docker
command: |
# Set sudo to work whether logged in as root user or non-root user
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
# configure Docker to use gcloud as a credential helper
mkdir -p /home/circleci/.docker
$SUDO gcloud alpha auth configure-docker --quiet --project $<<parameters.google-project-id>>
# if applicable, provide circleci user access to the docker config file
if [[ -d /home/circleci/.docker ]]; then
$SUDO chown circleci:circleci /home/circleci/.docker -R
fi
if [[ -d /home/circleci/.config ]]; then
$SUDO chown circleci:circleci /home/circleci/.config -R
fi
build-image:
description: Build a docker image
parameters:
registry-url:
description: The GCR registry URL from ['', us, eu, asia].gcr.io
type: string
default: gcr.io
google-project-id:
description: The Google project ID to connect with via the gcloud CLI
type: env_var_name
default: GOOGLE_PROJECT_ID
image:
description: A name for your docker image
type: string
tag:
description: A docker image tag
type: string
default: "latest"
path-to-dockerfile:
description: The relative path to the Dockerfile to use when building image
type: string
default: "."
steps:
- run:
name: Build docker image
command: docker build -t <<parameters.registry-url>>/$<<parameters.google-project-id>>/<<parameters.image>>:<<parameters.tag>> <<parameters.path-to-dockerfile>>
push-image:
description: "Push a container image to the GCR registry"
parameters:
registry-url:
description: The GCR registry URL from ['', us, eu, asia].gcr.io
type: string
default: gcr.io
google-project-id:
description: The Google project ID to connect with via the gcloud CLI
type: env_var_name
default: GOOGLE_PROJECT_ID
image:
description: A name for your docker image
type: string
tag:
description: A docker image tag
type: string
default: "latest"
steps:
- run:
name: Push image to GCR
command: |
docker push <<parameters.registry-url>>/$<<parameters.google-project-id>>/<<parameters.image>>:<<parameters.tag>>
jobs:
build_and_push_image:
description: >
Install GCP CLI, if needed, and configure. Build and push image to repository.
Requires environment variable for GCLOUD_SERVICE_KEY.
executor: default
parameters:
gcloud-service-key:
description: The gcloud service key
type: env_var_name
default: GCLOUD_SERVICE_KEY
google-project-id:
description: The Google project ID to connect with via the gcloud CLI
type: env_var_name
default: GOOGLE_PROJECT_ID
google-compute-zone:
description: The Google compute zone to connect with via the gcloud CLI
type: env_var_name
default: GOOGLE_COMPUTE_ZONE
registry-url:
description: The GCR registry URL from ['', us, eu, asia].gcr.io
type: string
default: gcr.io
image:
description: A name for your docker image
type: string
tag:
description: A docker image tag
type: string
default: "latest"
path-to-dockerfile:
description: The relative path to the Dockerfile to use when building image
type: string
default: "."
steps:
- checkout
- gcr-auth:
google-project-id: <<parameters.google-project-id>>
google-compute-zone: <<parameters.google-compute-zone>>
- build-image:
registry-url: <<parameters.registry-url>>
google-project-id: <<parameters.google-project-id>>
image: <<parameters.image>>
tag: << parameters.tag >>
path-to-dockerfile: <<parameters.path-to-dockerfile>>
- push-image:
registry-url: <<parameters.registry-url>>
google-project-id: <<parameters.google-project-id>>
image: <<parameters.image>>
tag: <<parameters.tag>>