Skip to content

Commit 6b9ba1e

Browse files
authored
Merge pull request #34 from timclegg/feat/no-custom-image
feat: removing custom image usage
2 parents 40e34b5 + 37ecd18 commit 6b9ba1e

24 files changed

+807
-443
lines changed

beginners/05.ML_Model_Serving.ipynb

Lines changed: 384 additions & 384 deletions
Large diffs are not rendered by default.

beginners/README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Prerequisites
44

5-
You'll need an OCI free trial account: <a href="https://signup.cloud.oracle.com/?sourceType=_ref_coc-asset-opcSignIn&language=en_US" target="_blank" title="Sign up for free trial">click here to sign up</a> (right click and open in a new tab so you can keep these instructions open). We're going to use a ready-to-go image to install the required resources, so all you need to start is a free account.
5+
You'll need an OCI free trial account: <a href="https://signup.cloud.oracle.com/?sourceType=_ref_coc-asset-opcSignIn&language=en_US" target="_blank" title="Sign up for free trial">click here to sign up</a> (right click and open in a new tab so you can keep these instructions open).
66

77
Registered lab participants should have received $500 in credits to use for Data Science operations.
88

@@ -29,36 +29,43 @@ For Windows, and step-by-step instructions for Mac/Linux, please see the [Oracle
2929
<a href="https://cloud.oracle.com/resourcemanager/stacks/create?region=home&zipUrl=https://github.com/oracle-devrel/redbull-analytics-hol/releases/latest/download/redbull-analytics-hol-latest.zip" target="_blank"><img src="https://oci-resourcemanager-plugin.plugins.oci.oraclecloud.com/latest/deploy-to-oracle-cloud.svg" alt="Deploy to Oracle Cloud"/></a>
3030
2. If needed, log into your account. You should then be presented with the **Create Stack** page.
3131

32-
These next few steps will deploy a stack to your OCI tenancy. This will include a Compute instance and the necessary tools to deploy and run JupyterLab from within your OCI account.
32+
These next few steps will deploy a stack to your OCI tenancy. This will include the necessary tools to deploy and run JupyterLab from within your OCI account.
3333

3434
Under *Stack Information* (the first screen), check the box *I have reviewed and accept the Oracle Terms of Use*. Once that box is checked, the information for the stack will be populated automatically.
3535

3636
![Create Stack](./docs/red-bull-hol-1a-create-stack-information.jpg)
37-
3. Click **Next** at the bottom of the screen. This will take you to the **Configure Variables** page. On this page you'll need to provide the SSH key we created in the prerequisites if you want SSH access to your Compute instance.
37+
3. Click **Next** at the bottom of the screen. This will take you to the **Configure Variables** page. On this page you'll need to provide the SSH key we created in the prerequisites. You can copy and paste the contents of the public key (`.pub`), or use the file selector to upload the `.pub` file directly.
3838

3939
![Configure Variables](./docs/red-bull-hol-configure-variables.jpg)
4040
4. On the **Review** page, be sure *Run Apply* is checked, and click **Create**.
4141

4242
![Review and Create](./docs/red-bull-hol-1c-create-stack-review.jpg)
43-
5. This will take you to the **Job Details** page, and OCI will begin creating the stack and deploying the custom image for the lab. This will take about 11 minutes. When it completes (assuming everything went smoothly), the **Job Details** will show a bright green square with "Succeeded" below it.
43+
5. This will take you to the **Job Details** page, and OCI will begin creating the stack and deploying the scripts for the lab. This will take 8-10 minutes. When it completes (assuming everything went smoothly), the **Job Details** will show a bright green square with "Succeeded" below it.
4444

4545
![Create Stack Succeeded](./docs/red-bull-hol-1d-create-stack-succeeded.jpg)
46-
6. Once the Create Stack job has succeeded, click the hamburger menu in the upper left, select **Compute** in the sidebar, and click **Instances** in the menu.
46+
6. Once the Create Stack job has succeeded, click "Outputs."
4747

48-
![Instances in the Menu](./docs/red-bull-hol-2a-menu-instances.jpg)
49-
7. On the **Instances** screen, make sure "redbullhol" is selected under *Compartment*. If "redbullhol" isn't in the dropdown menu, you may need to refresh the page for the new compartment to show up.
48+
![Show Outputs](./docs/red-bull-hol-show-outputs.jpg)
5049

51-
![Instances Compartment](./docs/red-bull-hol-2c-instances-compartment.jpg)
52-
8. Once the "redbullhol" compartment is selected, you should see a running Instance in the list. The address you'll need to access it is in the *Public IP* column. Copy the IP address shown.
50+
The outputs will include a terminal command you'll need to run. Replace the private key reference with the path to the private key that matches the public key you uploaded. The final command should look similar to:
5351

54-
![Public IP](./docs/red-bull-hol-2d-instances-public-ip.jpg)
55-
9. Next, open a new tab in your browser to load up the web UI for JupyterLab. Paste the IP address you just copied with `:8001` added to the end. The URL should look like `http://xxx.xxx.xxx.xxx:8001` (substituting the public IP we copied in the previous step). JupyterLab is running on port 8001, so when you navigate to this URL you should see the Juypter login.
52+
```console
53+
$ ssh -i ~/.ssh/id_rsa2 opc@123.456.789.100 'source redbullenv/bin/activate; jupyter server list'
54+
```
5655

57-
_**Note:** You should not be on VPN when opening JupyterLab._
56+
7. Open a terminal and run the above command. The output of the command will include a url containing a token. You'll need the token portion of the url (the part after `?token=`) for the next step.
57+
58+
![SSH Output](./docs/red-bull-hol-terminal-ssh-output.jpg)
59+
8. Back in the **Outputs** display in your browser, copy the IP address for your Jupyter Lab (ending with `:8888`). Paste that into a new browser window/tab and append `?token=YOUR_TOKEN`, replacing `YOUR_TOKEN` with the token from step 7. Load the resulting URL.
60+
61+
![Jupyter Lab URL](./docs/red-bull-hol-jupyter-url.jpg)
62+
9. Your new deployment uses a self-signed certificate, so you'll get a warning from your browser that the connection is insecure. You'll need to approve the loading of the page. In most browsers you'll see an "Advanced" or similar button, and clicking it will offer you the option to ignore security concerns and load the page anyway.
5863

59-
![Jupyter Login](./docs/red-bull-hol-3b-jupyter-login.jpg)
60-
10. Log in with the password `Redbull1`.
61-
11. You should now see the JupyterLab. Navigate in the sidebar to `/redbull-analytics-hol/beginners/` to see the Jupyter notebooks for this lab.
64+
You'll need to repeat the security approval procedure when loading the Flask app created by the lab.
65+
66+
_**Note:** You should not be on VPN when opening JupyterLab._
67+
68+
10. You should now see the JupyterLab. Navigate in the sidebar to `/redbull-analytics-hol/beginners/` to see the Jupyter notebooks for this lab.
6269

6370
## Up and Running
6471

13.8 KB
Loading
92.2 KB
Loading
23.2 KB
Loading

beginners/web/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ def predict_position():
6767
return render_template('index.html',tables=[df1.to_html(classes='driver')])
6868

6969
if __name__ == '__main__':
70-
app.run(host='0.0.0.0', port=8080, debug=True)
70+
app.run(host='0.0.0.0', port=8443, debug=True, ssl_context='adhoc')
7171

7272

terraform/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,73 @@ When you no longer need the deployment, you can run this command to destroy the
196196
```
197197
terraform destroy
198198
```
199+
200+
## Requirements
201+
202+
| Name | Version |
203+
|------|---------|
204+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.5 |
205+
206+
## Providers
207+
208+
| Name | Version |
209+
|------|---------|
210+
| <a name="provider_oci"></a> [oci](#provider\_oci) | 4.31.0 |
211+
| <a name="provider_oci.home"></a> [oci.home](#provider\_oci.home) | 4.31.0 |
212+
| <a name="provider_random"></a> [random](#provider\_random) | 3.1.0 |
213+
| <a name="provider_time"></a> [time](#provider\_time) | 0.7.2 |
214+
| <a name="provider_tls"></a> [tls](#provider\_tls) | 3.1.0 |
215+
216+
## Modules
217+
218+
No modules.
219+
220+
## Resources
221+
222+
| Name | Type |
223+
|------|------|
224+
| [oci_core_default_dhcp_options.Default-DHCP-Options-for-redbullvcn](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_default_dhcp_options) | resource |
225+
| [oci_core_default_route_table.Default-Route-Table-for-redbullvcn](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_default_route_table) | resource |
226+
| [oci_core_default_security_list.Default-Security-List-for-redbullvcn](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_default_security_list) | resource |
227+
| [oci_core_instance.redbull_lab1](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_instance) | resource |
228+
| [oci_core_internet_gateway.redbullig](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_internet_gateway) | resource |
229+
| [oci_core_subnet.redbullsubnet](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_subnet) | resource |
230+
| [oci_core_vcn.redbullvcn](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/core_vcn) | resource |
231+
| [oci_identity_compartment.redbullhol](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/identity_compartment) | resource |
232+
| [oci_identity_tag.release](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/identity_tag) | resource |
233+
| [oci_identity_tag_namespace.devrel](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/resources/identity_tag_namespace) | resource |
234+
| [random_id.tag](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
235+
| [time_sleep.wait_60_seconds](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
236+
| [tls_private_key.this](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
237+
| [oci_core_images.this](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/core_images) | data source |
238+
| [oci_identity_availability_domain.AD1](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_availability_domain) | data source |
239+
| [oci_identity_compartment.current_compartment](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_compartment) | data source |
240+
| [oci_identity_region_subscriptions.home_region_subscriptions](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_region_subscriptions) | data source |
241+
| [oci_identity_regions.current_region](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_regions) | data source |
242+
| [oci_identity_regions.home-region](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_regions) | data source |
243+
| [oci_identity_tenancy.tenant_details](https://registry.terraform.io/providers/hashicorp/oci/latest/docs/data-sources/identity_tenancy) | data source |
244+
245+
## Inputs
246+
247+
| Name | Description | Type | Default | Required |
248+
|------|-------------|------|---------|:--------:|
249+
| <a name="input_compartment_ocid"></a> [compartment\_ocid](#input\_compartment\_ocid) | The compartment OCID to deploy resources to | `string` | `""` | no |
250+
| <a name="input_compute_image_name"></a> [compute\_image\_name](#input\_compute\_image\_name) | The name of the compute image to use for the compute instances. | `string` | `"Oracle-Linux-7.9-2021.08.27-0"` | no |
251+
| <a name="input_fingerprint"></a> [fingerprint](#input\_fingerprint) | 'API Key' fingerprint, more details can be found at https://docs.cloud.oracle.com/en-us/iaas/Content/General/Concepts/credentials.htm#two | `string` | `""` | no |
252+
| <a name="input_private_key"></a> [private\_key](#input\_private\_key) | The private key (provided as a string value) | `string` | `""` | no |
253+
| <a name="input_private_key_password"></a> [private\_key\_password](#input\_private\_key\_password) | The password to use for the private key | `string` | `""` | no |
254+
| <a name="input_private_key_path"></a> [private\_key\_path](#input\_private\_key\_path) | Path to private key used to create OCI 'API Key', more details can be found at https://docs.cloud.oracle.com/en-us/iaas/Content/General/Concepts/credentials.htm#two | `string` | `""` | no |
255+
| <a name="input_redbull_compartment"></a> [redbull\_compartment](#input\_redbull\_compartment) | The name of the compartment created to hold all of the resources | `string` | `"redbullhol"` | no |
256+
| <a name="input_region"></a> [region](#input\_region) | OCI Region as documented at https://docs.cloud.oracle.com/en-us/iaas/Content/General/Concepts/regions.htm | `string` | n/a | yes |
257+
| <a name="input_ssh_public_key"></a> [ssh\_public\_key](#input\_ssh\_public\_key) | The public SSH key to use for the compute instance | `string` | `""` | no |
258+
| <a name="input_ssh_public_key_path"></a> [ssh\_public\_key\_path](#input\_ssh\_public\_key\_path) | The path to the public SSH key to use for the compute instance | `string` | `""` | no |
259+
| <a name="input_tenancy_ocid"></a> [tenancy\_ocid](#input\_tenancy\_ocid) | OCI tenant OCID, more details can be found at https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#five | `string` | n/a | yes |
260+
| <a name="input_user_ocid"></a> [user\_ocid](#input\_user\_ocid) | OCI user OCID, more details can be found at https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#five | `string` | `""` | no |
261+
262+
## Outputs
263+
264+
| Name | Description |
265+
|------|-------------|
266+
| <a name="output_get_jupyter_token"></a> [get\_jupyter\_token](#output\_get\_jupyter\_token) | n/a |
267+
| <a name="output_instance_pub_ip"></a> [instance\_pub\_ip](#output\_instance\_pub\_ip) | n/a |
268+
| <a name="output_jupyter_url"></a> [jupyter\_url](#output\_jupyter\_url) | n/a |

terraform/computes.tf

Lines changed: 95 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
# Copyright (c) 2021 Oracle and/or its affiliates.
22

3-
### custom image
4-
5-
resource "oci_core_image" "redbullhol_image" {
6-
compartment_id = oci_identity_compartment.redbullhol.id
7-
depends_on = [time_sleep.wait_60_seconds]
8-
9-
display_name = "redbullhol_image"
10-
11-
image_source_details {
12-
source_type = "objectStorageUri"
13-
source_uri = "https://objectstorage.eu-frankfurt-1.oraclecloud.com/p/i0H4G1oKfKV7nOqjyeJ_SsXKhIZFgfmXFcFVEcr_9XEAVpkTOHc2MWtoz2WNmMXr/n/emeasespainsandbox/b/publichol/o/redbullhol-20210809-1523"
14-
}
15-
}
16-
173
#### redbull_lab1
184
resource oci_core_instance redbull_lab1 {
195
availability_domain = data.oci_identity_availability_domain.AD1.name
206
compartment_id = oci_identity_compartment.redbullhol.id
21-
shape = "VM.Standard2.2"
7+
shape = "VM.Standard2.2"
228

239
agent_config {
2410
is_management_disabled = "false"
@@ -37,11 +23,11 @@ resource oci_core_instance redbull_lab1 {
3723
display_name = "redbulllab1"
3824

3925
metadata = {
40-
"ssh_authorized_keys" = var.ssh_public_key
26+
ssh_authorized_keys = local.ssh_public_keys
4127
}
42-
28+
4329
source_details {
44-
source_id = oci_core_image.redbullhol_image.id
30+
source_id = local.list_images[var.compute_image_name].id
4531
source_type = "image"
4632
}
4733

@@ -51,4 +37,95 @@ resource oci_core_instance redbull_lab1 {
5137
defined_tags = {
5238
"${oci_identity_tag_namespace.devrel.name}.${oci_identity_tag.release.name}" = local.release
5339
}
40+
41+
connection {
42+
agent = false
43+
timeout = "60m"
44+
host = oci_core_instance.redbull_lab1.public_ip
45+
user = "opc"
46+
private_key = tls_private_key.public_private_key_pair.private_key_pem
47+
}
48+
49+
provisioner "file" {
50+
source = "scripts/jupyterlab.service"
51+
destination = "/home/opc/jupyterlab.service"
52+
53+
connection {
54+
private_key = tls_private_key.this.private_key_pem
55+
user = "opc"
56+
host = self.public_ip
57+
}
58+
}
59+
60+
provisioner "file" {
61+
source = "scripts/launchapp.sh"
62+
destination = "/home/opc/launchapp.sh"
63+
64+
connection {
65+
private_key = tls_private_key.this.private_key_pem
66+
user = "opc"
67+
host = self.public_ip
68+
}
69+
}
70+
71+
provisioner "file" {
72+
source = "scripts/launchjupyterlab.sh"
73+
destination = "/home/opc/launchjupyterlab.sh"
74+
75+
connection {
76+
private_key = tls_private_key.this.private_key_pem
77+
user = "opc"
78+
host = self.public_ip
79+
}
80+
}
81+
82+
provisioner "file" {
83+
source = "scripts/script_install_pyenv.sh"
84+
destination = "/home/opc/script_install_pyenv.sh"
85+
86+
connection {
87+
private_key = tls_private_key.this.private_key_pem
88+
user = "opc"
89+
host = self.public_ip
90+
}
91+
}
92+
93+
provisioner "file" {
94+
source = "scripts/script_install_root.sh"
95+
destination = "/home/opc/script_install_root.sh"
96+
97+
connection {
98+
private_key = tls_private_key.this.private_key_pem
99+
user = "opc"
100+
host = self.public_ip
101+
}
102+
}
103+
104+
provisioner "file" {
105+
source = "scripts/checkpyenv.py"
106+
destination = "/home/opc/checkpyenv.py"
107+
108+
connection {
109+
private_key = tls_private_key.this.private_key_pem
110+
user = "opc"
111+
host = self.public_ip
112+
}
113+
}
114+
115+
provisioner "remote-exec" {
116+
inline = [
117+
"chmod +x /home/opc/script_install_pyenv.sh",
118+
"chmod +x /home/opc/script_install_root.sh",
119+
"chmod +x /home/opc/launchjupyterlab.sh",
120+
"chmod +x /home/opc/launchapp.sh",
121+
"/home/opc/script_install_pyenv.sh",
122+
"sudo -i /home/opc/script_install_root.sh"
123+
]
124+
125+
connection {
126+
private_key = tls_private_key.this.private_key_pem
127+
user = "opc"
128+
host = self.public_ip
129+
}
130+
}
54131
}

terraform/data_sources.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ data "oci_identity_region_subscriptions" "home_region_subscriptions" {
3434
data oci_identity_availability_domain AD1 {
3535
compartment_id = var.compartment_ocid
3636
ad_number = "1"
37-
}
37+
}
38+
39+
data "oci_core_images" "this" {
40+
compartment_id = var.compartment_ocid
41+
filter {
42+
name = "state"
43+
values = ["AVAILABLE"]
44+
}
45+
}

terraform/locals.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2021 Oracle and/or its affiliates.
2+
3+
locals {
4+
private_key = try(file(var.private_key_path), var.private_key)
5+
ssh_public_key = try(file(var.ssh_public_key_path), var.ssh_public_key)
6+
7+
ssh_public_keys = join("\n", [
8+
trimspace(local.ssh_public_key),
9+
trimspace(tls_private_key.this.public_key_openssh)
10+
])
11+
12+
release = "1.0"
13+
14+
#Transform the list of images in a tuple
15+
list_images = { for s in data.oci_core_images.this.images :
16+
s.display_name =>
17+
{ id = s.id,
18+
operating_system = s.operating_system
19+
}
20+
}
21+
22+
}

0 commit comments

Comments
 (0)