-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaction.yml
More file actions
275 lines (244 loc) · 9.49 KB
/
action.yml
File metadata and controls
275 lines (244 loc) · 9.49 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: Code Engine GitHub Action
description: Github action to interact with IBM Cloud Code Engine deploy Apps, Jobs and Functions
author: IBM
branding:
icon: cloud
color: blue
inputs:
api-key:
description: IAM API Key used to log into the IBM Cloud
required: true
resource-group:
description: An IBM Cloud Resource Group is a logical container used to organize and manage related cloud resources
required: false
region:
description: The Region refers to a geographical area where the project is are located
required: true
project:
description: A Code Engine Project Is the grouping of your Apps, Functions and Jobs
required: true
# App, Function, Job or build Specific inputs
component:
description: The type of component that should be deployed [App, Function, Job, Build]
required: true
name:
description: Name of the App, Function, Job or build
required: true
runtime:
description: Runtime used for the Function only required for function
required: false
image:
description: Name of the image that is used for this application
required: false
registry-secret:
description: Name of the registry secret used to authenticate against the Container registry
required: false
port:
description: Port of the Application
required: false
trusted-profiles:
description: Enable trusted profiles
required: false
default: false
build-source:
description: path to the directory containing the source code
required: false
default: .
build-strategy:
description: strategy used for building the image ['dockerfile', 'buildpacks']
required: false
default: buildpacks
build-size:
description: The size to use for the build, which determines the amount of resources used. Valid values include small, medium, large, xlarge, and xxlarge.
required: false
default: medium
cpu:
description: CPU configuration set for the component. If not set default Code Engine values are used.
required: false
memory:
description: Memory configuration set for the component. If not set default Code Engine values are used.
required: false
outputs:
image-with-digest:
description: "The built image with digest"
value: ${{ steps.create-build.outputs.image-with-digest }}
# actual action code
runs:
using: composite
steps:
# Default steps required
- name: Install IBM Cloud CLI
uses: IBM/actions-ibmcloud-cli@v1
with:
api_key: ${{ inputs.api-key }}
region: ${{ inputs.region }}
group: ${{ inputs.resource-group }}
plugins: code-engine
# Select the project using Name or ID
# If the project doesn`t exist the project is created with the provided Name
- name: Select Code Engine Project
shell: bash
run: |
if ibmcloud ce project select --name "${{ inputs.project }}" || ibmcloud ce project select --id ${{ inputs.project }} ; then
echo "Project Selected"
else
ibmcloud ce project create --name "${{ inputs.project }}" --wait
fi
# set resources for target
- name: Set resources
id: set-resources
shell: bash
env:
CPU: ${{ inputs.cpu }}
MEMORY: ${{ inputs.memory }}
TRUSTED_PROFILES: ${{ inputs.trusted-profiles }}
run: |
# set the CPU value
if [[ "${CPU}" != "" ]] ; then
echo "cpu=--cpu ${CPU}" >> "$GITHUB_OUTPUT"
else
echo "cpu=" >> "$GITHUB_OUTPUT"
fi
# set the memory value
if [[ "${MEMORY}" != "" ]] ; then
echo "memory=--memory ${MEMORY}" >> "$GITHUB_OUTPUT"
else
echo "memory=" >> "$GITHUB_OUTPUT"
fi
if [[ "${TRUSTED_PROFILES}" == "true" ]] ; then
echo "TRUSTED_PROFILES=--TRUSTED_PROFILES-enabled" >> "$GITHUB_OUTPUT"
else
echo "TRUSTED_PROFILES=" >> "$GITHUB_OUTPUT"
fi
- name: configure-build-image
id: conf-build-img
shell: bash
env:
IMAGE: ${{ inputs.image }}
REGION: ${{ inputs.region }}
REGISTRY_SECRET: ${{ inputs.registry-secret }}
BUILD_SOURCE: ${{ inputs.build-source }}
BUILD_STRATEGY: ${{ inputs.build-strategy }}
BUILD_SIZE: ${{ inputs.build-size }}
run: |
if [[ "${IMAGE}" != "" ]] ; then
if [[ "${REGISTRY_SECRET}" != "" ]]; then
echo "build-img=--image ${IMAGE} --registry-secret ${REGISTRY_SECRET}" >> "$GITHUB_OUTPUT"
else
echo "build-img=--image ${IMAGE}" >> "$GITHUB_OUTPUT"
fi
else
echo "build-img=--build-source ${BUILD_SOURCE} --build-size ${BUILD_SIZE} --build-strategy ${BUILD_STRATEGY}" >> "$GITHUB_OUTPUT"
fi
# Functions Steps
- name: Create or Update Functions
shell: bash
id: fn-create
if: ( inputs.component == 'function' || inputs.component == 'func' || inputs.component == 'fn' )
env:
NAME: ${{ inputs.name }}
RUNTIME: ${{ inputs.runtime }}
BUILD_SOURCE: ${{ inputs.build-source }}
CPU: ${{ steps.set-resources.outputs.cpu }}
MEMORY: ${{ steps.set-resources.outputs.memory }}
TRUSTED_PROFILES: ${{ steps.set-resources.outputs.TRUSTED_PROFILES }}
run: |
if ibmcloud ce fn get --name ${NAME} ; then
ibmcloud ce fn update --name ${NAME} --runtime ${RUNTIME} --build-source ${BUILD_SOURCE} ${TRUSTED_PROFILES} ${CPU} ${MEMORY}
else
ibmcloud ce fn create --name ${NAME} --runtime ${RUNTIME} --build-source ${BUILD_SOURCE} ${TRUSTED_PROFILES} ${CPU} ${MEMORY}
fi
# Build Steps
- name: Create or Update build
shell: bash
id: create-build
if: ( inputs.component == 'build')
env:
NAME: ${{ inputs.name }}
IMAGE: ${{ inputs.image }}
REGION: ${{ inputs.region }}
REGISTRY_SECRET: ${{ inputs.registry-secret }}
BUILD_SOURCE: ${{ inputs.build-source }}
BUILD_STRATEGY: ${{ inputs.build-strategy }}
BUILD_SIZE: ${{ inputs.build-size }}
run: |
if [[ "${IMAGE}" == "" ]] ; then
echo "image needs to be set for build"
exit 1
fi
NAME=${NAME}-$(date +"%Y%m%d%H%M%S")
if ibmcloud ce buildrun get --name ${NAME} ; then
echo "buildrun already exists"
else
if [[ "${REGISTRY_SECRET}" == "" ]] ; then
echo "using default secret for current region: ce-auto-icr-private-${REGION}"
REGISTRY_SECRET="ce-auto-icr-private-${REGION}"
fi
ibmcloud ce buildrun submit --name ${NAME} --source ${BUILD_SOURCE} --strategy ${BUILD_STRATEGY} --image ${IMAGE} --registry-secret ${REGISTRY_SECRET} --size ${BUILD_SIZE} --wait
fi
BUILDRUNDATA=$(ibmcloud ce buildrun get --name ${NAME} --output json)
IMAGE_WITH_DIGEST="$(echo ${BUILDRUNDATA} | jq -r '.output_image')@$(echo ${BUILDRUNDATA} | jq -r '.status_details.output_digest')"
echo "Output image with digest: ${IMAGE_WITH_DIGEST}"
echo "image-with-digest=${IMAGE_WITH_DIGEST}" >> $GITHUB_OUTPUT
# Application Steps
- name: Create or Update Application
shell: bash
id: create-app
if: ( inputs.component == 'application' || inputs.component == 'app' )
env:
NAME: ${{ inputs.name }}
CPU: ${{ steps.set-resources.outputs.cpu }}
MEMORY: ${{ steps.set-resources.outputs.memory }}
CONFBUILDIMG: ${{ steps.conf-build-img.outputs.build-img }}
PORT: ${{ inputs.port }}
TRUSTED_PROFILES: ${{ steps.set-resources.outputs.TRUSTED_PROFILES }}
run: |
# set the PORT value
PORTFLAG=""
if [[ "${PORT}" != "" ]] ; then
PORTFLAG="--port ${PORT}"
fi
if ibmcloud ce application get --name ${NAME} ; then
ibmcloud ce application update --name ${NAME} ${CONFBUILDIMG} ${PORTFLAG} ${TRUSTED_PROFILES} ${CPU} ${MEMORY}
else
ibmcloud ce application create --name ${NAME} ${CONFBUILDIMG} ${PORTFLAG} ${TRUSTED_PROFILES} ${CPU} ${MEMORY}
fi
# Job Steps
- name: Create or Update Job
shell: bash
id: create-job
if: inputs.component == 'job'
env:
NAME: ${{ inputs.name }}
CPU: ${{ steps.set-resources.outputs.cpu }}
MEMORY: ${{ steps.set-resources.outputs.memory }}
CONFBUILDIMG: ${{ steps.conf-build-img.outputs.build-img }}
TRUSTED_PROFILES: ${{ steps.set-resources.outputs.TRUSTED_PROFILES }}
run: |
if ibmcloud ce job get --name ${NAME} ; then
ibmcloud ce job update --name ${NAME} ${CONFBUILDIMG} --wait ${TRUSTED_PROFILES} ${CPU} ${MEMORY}
else
ibmcloud ce job create --name ${NAME} ${CONFBUILDIMG} --wait ${TRUSTED_PROFILES} ${CPU} ${MEMORY}
fi
- name: Get component
shell: bash
if: steps.fn-create.outcome == 'success' || steps.app-create.outcome == 'success' || steps.job-create.outcome == 'success'
env:
NAME: ${{ inputs.name }}
run: |
case ${{ inputs.component }} in
function|func|fn)
ibmcloud ce fn get --name ${NAME}
;;
application|app)
ibmcloud ce app get --name ${NAME}
;;
job)
ibmcloud ce job get --name ${NAME}
;;
*)
echo "Wrong Code Engine component used!"
echo "Use[ function | func | fn | application | app | job ]"
exit 1
;;
esac