This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
226 lines (209 loc) · 8.58 KB
/
code-engine-preview.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
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
name: Docker image deployment process in IBM Cloud Code Engine
on:
workflow_call:
inputs:
container_registry_namespace:
default: community-digital
required: false
type: string
code_engine_project:
required: true
type: string
code_engine_registry_secret:
default: ibm-container-registry
required: false
type: string
docker_image_name:
required: true
type: string
docker_image_port:
default: '8080'
required: false
type: string
build_args:
required: false
type: string
ibmcloud_region:
default: us-south
required: false
type: string
ibmcloud_resource_group:
default: Quantum Community
required: false
type: string
env_name:
default: 'Preview'
required: false
type: string
clone_textbook_repo:
default: 'false'
required: false
type: string
secrets:
ibmcloud_account:
required: true
ibmcloud_api_key:
required: true
ibmid_client_id:
required: false
ibmid_client_secret:
required: false
mongodb_uri:
required: false
textbook_repo_clone_key:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ANALYTICS_CATEGORY:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_INSTANCE_ID:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ANALYTICS_KEY:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ENABLED:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_CODE:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_CODE_TYPE:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_TITLE:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_SCRIPT_SRC:
required: false
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_UT30:
required: false
AIRTABLE_ACCESS_TOKEN:
required: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Set preview tag
run: |
if "${{ inputs.env_name == 'Preview' }}" ; then
echo "PREVIEW_TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
else
echo "PREVIEW_TAG=`node -p "'${{ inputs.env_name }}'.toLowerCase()"`" >> $GITHUB_ENV
fi
- name: Create APP_NAME and DOCKER_IMAGE_TAG env variables
run: |
echo "APP_NAME=${{ inputs.docker_image_name }}-${{ env.PREVIEW_TAG }}" >> $GITHUB_ENV
echo "DOCKER_IMAGE_TAG=icr.io/${{ inputs.container_registry_namespace }}/${{ inputs.docker_image_name }}:${{ env.PREVIEW_TAG }}" >> $GITHUB_ENV
- name: Fetch content of the PR
uses: actions/checkout@v3
- name: Clone Qiskit/textbook submodule for platypus
if: inputs.clone_textbook_repo == 'true'
run: |
eval `ssh-agent -s`
ssh-add - <<< "${{ secrets.textbook_repo_clone_key }}"
git config --global url."[email protected]:".insteadOf "https://github.com"
git submodule update --init --recursive --depth 1
git config --global --remove-section url."[email protected]:"
- name: GH deployment status (start)
id: gh_deployment
uses: bobheadxi/deployments@v1
with:
step: start
token: ${{ github.token }}
env: ${{ inputs.env_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup IBM Cloud CLI
run: |
curl -o IBM_Cloud_CLI_2.20.0_amd64.tar.gz -L https://download.clis.cloud.ibm.com/ibm-cloud-cli/2.20.0/IBM_Cloud_CLI_2.20.0_amd64.tar.gz
tar xvf IBM_Cloud_CLI_2.20.0_amd64.tar.gz
sh Bluemix_CLI/install
ibmcloud --version
ibmcloud config --check-version=false
ibmcloud plugin install -f code-engine
ibmcloud plugin install -f container-registry
- name: Authenticate with IBM Cloud CLI
run: |
ibmcloud login -g "${{ inputs.ibmcloud_resource_group }}" -r "${{ inputs.ibmcloud_region }}" -c "${{ secrets.ibmcloud_account }}" --apikey "${{ secrets.ibmcloud_api_key }}"
- name: Remove previous Docker image (if exists)
run: |
ibmcloud cr region-set global
if ibmcloud cr image-list | grep "${{ inputs.docker_image_name }}" | grep "${{ env.PREVIEW_TAG }}" ; then
ibmcloud cr image-rm "${{ env.DOCKER_IMAGE_TAG }}"
else
echo "no image to remove"
fi
- name: Log-in into IBM Container Registry
uses: docker/login-action@v2
with:
registry: icr.io
username: iamapikey
password: ${{ secrets.ibmcloud_api_key }}
- name: Build and push to IBM registry
if: github.repository != 'Qiskit/qiskit.org' && github.repository != 'Qiskit/platypus'
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ env.DOCKER_IMAGE_TAG }}
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_TAG }}
cache-to: type=inline
build-args: ${{ inputs.build_args }}
- name: Build and push to IBM registry for qiskit.org
if: github.repository == 'Qiskit/qiskit.org'
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ env.DOCKER_IMAGE_TAG }}
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_TAG }}
cache-to: type=inline
build-args: |
AIRTABLE_ACCESS_TOKEN=${{ secrets.AIRTABLE_ACCESS_TOKEN }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ANALYTICS_CATEGORY=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ANALYTICS_CATEGORY }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_INSTANCE_ID=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_INSTANCE_ID }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ANALYTICS_KEY=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ANALYTICS_KEY_STAGING }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_ENABLED=true
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_CODE=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_CODE }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_CODE_TYPE=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_CODE_TYPE }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_TITLE=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_PRODUCT_TITLE }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_SCRIPT_SRC=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_SCRIPT_SRC_STAGING }}
NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_UT30=${{ secrets.NUXT_PUBLIC_IBM_ANALYTICS_SEGMENT_UT30 }}
- name: Build and push to IBM registry for platypus
if: github.repository == 'Qiskit/platypus'
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.DOCKER_IMAGE_TAG }}
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_TAG }}
cache-to: type=inline
build-args: |
IBMID_CLIENT_ID=${{ secrets.ibmid_client_id }}
IBMID_CLIENT_SECRET=${{ secrets.ibmid_client_secret }}
MONGODB_URI=${{ secrets.mongodb_uri }}
TEXTBOOK_REPO_CLONE_KEY=${{ secrets.textbook_repo_clone_key }}
- name: Determine Code Engine project and app status
id: ce_command_choice
run: |
ibmcloud ce project select -n "${{ inputs.code_engine_project }}"
if ibmcloud ce app list -q | grep "${{ env.APP_NAME }}" ; then
echo "command=update" >> $GITHUB_OUTPUT
else
echo "command=create" >> $GITHUB_OUTPUT
fi
- name: Create a new preview application in Code Engine
id: ce_app_creation
run: |
ibmcloud ce app ${{ steps.ce_command_choice.outputs.command }} \
--name "${{ env.APP_NAME }}" \
--image "${{ env.DOCKER_IMAGE_TAG }}" \
--registry-secret "${{ inputs.code_engine_registry_secret }}" \
--port "${{ inputs.docker_image_port }}" \
--cpu 0.25 \
--memory 0.5G \
--min 1
echo "preview_url=$(\
ibmcloud ce app get --name "${{ env.APP_NAME }}" --output url
)" >> $GITHUB_OUTPUT
- name: GH deployment status (finish)
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ github.token }}
env: ${{ steps.gh_deployment.outputs.env }}
status: ${{ job.status }}
override: false
deployment_id: ${{ steps.gh_deployment.outputs.deployment_id }}
env_url: ${{ steps.ce_app_creation.outputs.preview_url }}