Skip to content

Commit aab26f0

Browse files
Merge pull request #8 from oindrillac/master
modified s2i build nb steps to account for private repos and env vars
2 parents 3973af9 + 54f8012 commit aab26f0

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

notebooks/notebook2image/ODSC19-Demo-OpenShift-Machine-Learning-Setup.ipynb

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"* Access to OpenShift\n",
1212
"* Install oc client\n",
1313
"* Git clone a repo\n",
14+
"* Set env Variables\n",
1415
"* Deploy new app\n",
1516
"* Expose it as a service\n",
1617
"* Interact with the service"
@@ -107,6 +108,17 @@
107108
"Once the user has made the appropriate changes to their notebook they can push it back to github for the s2i builder. "
108109
]
109110
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"## Set Environment Variables as Secrets\n",
116+
"\n",
117+
"Any environment variables needed for the notebook to execute such as s3 bucket credentials can be configured as [Secrets](https://docs.openshift.com/container-platform/3.11/dev_guide/secrets.html) in OpenShift. Using the web console, by navigating to Resources and Secrets, we can create \"Generic\" Secret types for the environment variable, set a \"Secret Name\", specify the name of the key referenced in the notebook as \"Key\" and the value of the environment variable as \"Value\".\n",
118+
"\n",
119+
"After launching the service, we can add these Secrets to the Build Environment Variables and selecting \"Add Value from Config Map or Secret\". We can let the initial build fail and upon triggering a \"Rebuild\", the secrets will be used."
120+
]
121+
},
110122
{
111123
"cell_type": "markdown",
112124
"metadata": {},
@@ -128,6 +140,31 @@
128140
"~https://github.com/MichaelClifford/example-model-s2i-notebook"
129141
]
130142
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"When building from a private Git repo, we need to follow some additional steps. We can use deploy keys to authenticate the private Git repository.\n",
148+
"By following the steps outlined [here](https://www.openshift.com/blog/private-git-repositories-part-2a-repository-ssh-keys), we can generate an ssh key to be used with the repository. We need to add the Public key (the .pub file) that we generated to the Github Repo by going to the repo settings under \"Add deploy key\". \n",
149+
"\n",
150+
"The private key can be added as a Source Secret on OpenShift the same way we added environment variables. For adding the private ssh key, we can create a new Source Secret and select authentication type as \"SSH Key\", specify a secret name and paste the private key that we generated in the Private SSH Key section.\n",
151+
"\n",
152+
"Once we have set up the Secret, we can run the `new-app` command with the ssh url of the repo and specify the --source-secret parameter."
153+
]
154+
},
155+
{
156+
"cell_type": "code",
157+
"execution_count": null,
158+
"metadata": {},
159+
"outputs": [],
160+
"source": [
161+
"%%bash\n",
162+
"oc new-app --name model \\\n",
163+
"quay.io/willbenton/simple-model-s2i:demo\\\n",
164+
"~git@github.com:MichaelClifford/example-model-s2i-notebook.git \\\n",
165+
"--source-secret secretname"
166+
]
167+
},
131168
{
132169
"cell_type": "markdown",
133170
"metadata": {},
@@ -197,7 +234,7 @@
197234
"name": "python",
198235
"nbconvert_exporter": "python",
199236
"pygments_lexer": "ipython3",
200-
"version": "3.6.3"
237+
"version": "3.8.3"
201238
},
202239
"varInspector": {
203240
"cols": {
@@ -230,5 +267,5 @@
230267
}
231268
},
232269
"nbformat": 4,
233-
"nbformat_minor": 2
270+
"nbformat_minor": 4
234271
}

0 commit comments

Comments
 (0)