Skip to content

Commit 65058ed

Browse files
committed
feat: updated new infra
1 parent dd7498d commit 65058ed

File tree

1 file changed

+123
-77
lines changed

1 file changed

+123
-77
lines changed

neural_networks_hero/infra/infra.md

Lines changed: 123 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,138 @@
11
# Infrastructure
22

3+
Estimated Time: 15-20 minutes
4+
35
## Introduction
46

5-
In this lab we will build the infrastructure that we will use to run the rest of the workshop.
7+
In this lab, we will build the infrastructure that we will use to run the rest of the workshop.
8+
9+
The main four elements that we will be creating are:
610

7-
The main element that we will be creating is a **Data Science** session and notebook, to experiment with the newly-generated data using notebooks.
11+
- **Compute** instance using a Linux-based image from Oracle Cloud.
12+
- **Autonomous JSON Database** where we'll allocate the JSON documents.
13+
- **Data Science** session and notebook, to experiment with the newly-generated data using notebooks.
814

915
![Infrastructure](images/lol_infra.png)
1016

11-
We will use Cloud Shell to execute _`start.sh`_ script that will call Terraform to deploy all the infrastructure required and setup the configuration. If you don't know about Terraform, don't worry, there is no need. Also, there are no installation requirements: we will use Cloud Shell (which has Terraform installed by default) to deploy our infrastructure.
17+
We will use Cloud Shell to execute `start.sh` script, which will call Terraform and Ansible to deploy all the infrastructure required and setup the configuration. If you don't know about Terraform or Ansible, don't worry, there is no need.
1218

13-
Terraform is an Open Source tool to deploy resources in the cloud with code. You declare what you want in Oracle Cloud and Terraform make sure you get the resources created.
19+
- Terraform is an Open Source tool to deploy resources in the cloud with code. You declare what you want in Oracle Cloud and Terraform make sure you get the resources created.
20+
- Ansible is an Open Source tool to provision on top of the created resources. It automates the dependency installation, copies the source code, and config files so everything is ready for you to use.
1421

15-
> **Note**: in the figure above, there's also a compute instance and autonomous database deployed automatically by Terraform. These resources are completely optional and you can run the workshop without them. However, if you're interested in integrating everything that we'll talk about in the workshop with **your own datasets**, this is the way to do it. You can check out more information on this [in this workshop](https://oracle-devrel.github.io/leagueoflegends-optimizer/hols/workshops/dataextraction/index.html).
22+
Do you want to learn more? Feel free to check the code for terraform and ansible after the workshop [in our official repository.](https://github.com/oracle-devrel/leagueoflegends-optimizer/)
1623

17-
Do you want to learn more? Feel free to check [Terraform's code in this repository](https://github.com/oracle-devrel/leagueoflegends-optimizer/tree/main/dev/terraform) after the workshop.
24+
### Prerequisites
1825

19-
Estimated Time: 15 minutes
26+
- An Oracle Free Tier, Paid or LiveLabs Cloud Account
27+
- Active Oracle Cloud Account with available credits to use for Data Science service.
2028

21-
### Prerequisites
29+
### Objectives
2230

23-
* An Oracle Free Tier, Paid or LiveLabs Cloud Account
24-
* Active Oracle Cloud Account with available credits to use for Data Science service.
31+
In this lab, you will learn how to:
2532

33+
- Use Oracle Cloud Infrastructure for your Compute needs
34+
- Deploy resources using Terraform and Ansible
35+
- Learn about federation, and what's necessary to authenticate a Terraform request
36+
- Download the datasets we will use
2637

2738
## Task 1: Cloud Shell
2839

40+
First, we need to download the official repository to get access to all the code (Terraform and Ansible code for this step).
41+
2942
1. From the Oracle Cloud Console, click on **Cloud Shell**.
3043
![Cloud Shell Button](images/cloud-shell-button.png)
3144

3245
2. As soon as the Cloud Shell is loaded, you can download the assets to run this lab.
33-
```
46+
47+
```bash
3448
<copy>git clone --branch livelabs https://github.com/oracle-devrel/leagueoflegends-optimizer.git</copy>
3549
```
3650

37-
3. The result will look like this:
51+
3. The result will look like this
3852
![Git Clone](images/git-clone.png)
3953

4054
4. Change directory with `cd` to `leagueoflegends-optimizer` directory:
41-
```
42-
<copy>cd leagueoflegends-optimizer/dev</copy>
43-
```
44-
5. Terraform uses a file called `tfvars` that contains the variables Terraform uses to talk to Oracle Cloud and set up your deployment the way you want it. You are going to copy a template we provide to use your own values. Run on Cloud Shell the following command.
4555

56+
```bash
57+
<copy>
58+
cd leagueoflegends-optimizer/dev
59+
</copy>
4660
```
47-
<copy>cp terraform/terraform.tfvars.template terraform/terraform.tfvars</copy>
61+
62+
5. Terraform uses a file called `tfvars` that contains the variables Terraform uses to talk to Oracle Cloud and set up your deployment the way you want it. You are going to copy a template we provide to use your own values. Run on Cloud Shell the following command:
63+
64+
```bash
65+
<copy>
66+
cp terraform/terraform.tfvars.template terraform/terraform.tfvars
67+
</copy>
4868
```
4969

50-
## Task 2: Deploy with Terraform
70+
## Task 2: Deploy with Terraform and Ansible
5171

5272
1. Click on **Code Editor**. Next to the Cloud Shell one.
5373
![Cloud Code Editor](images/cloud-code-editor.png)
5474

55-
2. On the **Code Editor**, inside the Explorer section on the left panel, expand your username and navigate onto _`dev/terraform`_. You should see the file **`terraform.tfvars`**. Click on it:
56-
![Go To File](images/code-editor-go-to-file.png)
75+
> **Note**: for **Safari** users:<br>
76+
> First, it isn't the recommended browser for OCI. Firefox or Chrome are fully tested and are recommended.<br>
77+
> With Safari, if you get a message _Cannot Start Code Editor_, go to _**Settings** > **Privacy**_ and disable _**Prevent cross-site tracking**_.<br>
78+
> Then open Code Editor again.
5779
58-
3. The file will open and you can copy values you will get from running commands on Cloud Shell and paste it on the Code Editor.
80+
2. On the **Code Editor**, go to _**File** > **Open**_.
81+
![Open menu](images/code-editor-open-menu.png)
5982
60-
4. Copy the output of the following command as the region:
83+
3. On the pop-up, edit the path by clicking the pencil icon:
84+
![Open Pop Up](images/code-editor-open-popup.png)
6185
86+
4. Append, at the end, the path to the `terraform.tfvars`
87+
![Path to tfvars](images/code-editor-path.png)
88+
89+
```bash
90+
<copy>/leagueoflegends-optimizer/dev/terraform/terraform.tfvars</copy>
6291
```
92+
93+
5. Type _[ENTER]_ to select, click on the `terraform.tfvars` file and click Open.
94+
95+
![TFVars Open](images/code-editor-open-tfvars.png)
96+
97+
6. The file will open and you can copy values you will get from running commands on Cloud Shell and paste it on the Code Editor.
98+
99+
7. Copy the output of the following command as the region:
100+
101+
```bash
63102
<copy>echo $OCI_REGION</copy>
64103
```
65104
66105
![Paste Region](images/paste-region.png)
67106
68-
5. Copy the output of the following command as the tenancy OCID:
69-
```
107+
8. Copy the output of the following command as the tenancy OCID:
108+
109+
```bash
70110
<copy>echo $OCI_TENANCY</copy>
71111
```
72112
73113
![Paste Tenancy OCID](images/paste-tenancy-ocid.png)
74114
75-
6. Copy the output of the same command as the compartment OCID:
115+
9. Copy the output of the same command as the compartment OCID:
76116
77117
```bash
78118
<copy>echo $OCI_TENANCY</copy>
79119
```
80120
81-
> Note: we can paste the same OCID here in both tenancy and compartment because the root compartment in a tenancy is equal to the tenancy's OCID.
82-
83121
![Paste Compartment OCID](images/paste-compartment-ocid.png)
84122
85-
> You can deploy the infrastructure **on a specific compartment**<br>
123+
> **Note**: for experienced Oracle Cloud users:<br>
124+
> Do you want to deploy the infrastructure on a specific compartment?<br>
86125
> You can get the Compartment OCID in different ways.<br>
87126
> The coolest one is with OCI CLI from the Cloud Shell.<br>
88-
> You have to change _`COMPARTMENT_NAME`_ for the actual compartment name you are looking for and run the command:
89-
> ```
90-
> <copy>oci iam compartment list --all --compartment-id-in-subtree true --query "data[].id" --name COMPARTMENT_NAME</copy>
91-
> ```
127+
> You have to change _`COMPARTMENT_NAME`_ for the compartment name you are looking for and run the following command:
128+
129+
```bash
130+
<copy>
131+
oci iam compartment list --all --compartment-id-in-subtree true --query "data[].id" --name COMPARTMENT_NAME
132+
</copy>
133+
```
92134
93-
7. Generate a SSH key pair, by default it will create a private key on _`~/.ssh/id_rsa`_ and a public key _`~/.ssh/id_rsa.pub`_.
135+
10. Generate a SSH key pair, by default it will create a private key on _`~/.ssh/id_rsa`_ and a public key _`~/.ssh/id_rsa.pub`_.
94136
It will ask to enter the path, a passphrase and confirm again the passphrase; type _[ENTER]_ to continue all three times.
95137
96138
```bash
@@ -103,17 +145,24 @@ Estimated Time: 15 minutes
103145
> ```
104146
> And select all defaults. Then, try running the command again.
105147

106-
8. We need the public key in our notes, so keep the result of the content of the following command in your notes.
148+
11. We need the public key in our notes, so keep the result of the content of the following command in your notes.
107149

108150
```bash
109151
<copy>cat ~/.ssh/id_rsa.pub</copy>
110152
```
111153

112154
![Paste Public SSH Key](images/paste-public-ssh-key.png)
113155

114-
9. You can leave `riotgames_api_key` as it is. We are not using the API key for this specific workshop.
156+
12. From the previous lab, you should have the Riot Developer API Key.
157+
158+
![Riot API Key](images/riot_api_key_gen.png)
159+
160+
Paste the Riot API Key on the `riotgames_api_key` entry of the file.
161+
162+
![Paste Riot API Key](images/paste-riot-api-key.png)
163+
164+
13. Save the file.
115165

116-
10. Save the file in the Code Editor.
117166
![Code Editor Save](images/code-editor-save.png)
118167

119168
## Task 3: Start Deployment
@@ -125,51 +174,50 @@ Estimated Time: 15 minutes
125174
```
126175

127176
2. The script will run and it looks like this.
177+
128178
![Start SH beginning](images/start-sh-beginning.png)
129179

130180
3. Terraform will create resources for you, and during the process it will look like this.
131-
![Start SH terraform](images/start-sh-terraform.png)
132-
133-
4. The final part of the script is to print the output of all the work done.
134-
![Start SH output](images/start-sh-output.png)
135-
136-
5. Copy the Data Science notebook URL from the output variable _`ds_notebook_session`_. This is the URL we will use to connect to our Data Science environment.
137-
![Start SH output](images/start-sh-ssh.png)
138181

139-
> Note: login credentials for the Data Science notebook are the same as the ones used to access Oracle Cloud Infrastructure.
140-
141-
## Task 4: Accessing Notebook
182+
![Start SH terraform](images/start-sh-terraform.png)
142183

143-
Having just created our OCI Data Science environment, we need to install the necessary Python dependencies to execute our code. For that, we'll access our environment.
184+
4. Ansible will continue the work as part of the `start.sh` script. It looks like this.
144185

145-
* The easiest way is to access into the notebook **through the URL** that we previously copied from Terraform's output.
186+
![Start SH ansible](images/start-sh-ansible.png)
146187

147-
![terraform output](images/start-sh-ssh.png)
188+
5. The final part of the script is to print the output of all the work done.
148189

149-
If you have done it this way, make sure to **skip through to the next task**.
190+
![Start SH output](images/start-sh-output.png)
150191

151-
* (Optionally) We can also access to the notebook via the OCI console, on the top left burger menu:
192+
6. Copy the ssh command from the output variable `compute`.
152193

153-
![select data science](./images/select_data_science.png)
194+
![Start SH output](images/start-sh-ssh.png)
154195

155-
> You may find the Data Science section by also searching in the top left bar, or in the Analytics & AI tab, if it doesn't appear in "Recently visited" for you:
196+
## Task 4: Check Deployment
156197

157-
![analytics tab within OCI](images/analyticstab.png)
198+
1. Run the `ssh` command from the output of the script. It will look like this.
158199

159-
Now, we have access to a [list of our Data Science projects launched within OCI.](https://cloud.oracle.com/data-science/projects) We access our project, and inside our project we'll find the notebook.
200+
```bash
201+
<copy>ssh opc@PUBLIC_IP</copy>
202+
```
160203

161-
> The name of the notebook may be different than shown here in the screenshot.
204+
2. In the new machine, run the python script `check.py` that makes sure everything is working.
162205

163-
![open notebook - 1](./images/open-notebook.png)
206+
```bash
207+
<copy>python src/check.py</copy>
208+
```
164209

165-
![open notebook - 2](./images/open-notebook2.png)
210+
3. The result will confirm database connection and Riot API works.
166211

167-
You should now see the Jupyter environment
212+
![Python Check OK](images/python-check-ok.png)
168213

169-
![jupyter environment](./images/notebook.png)
214+
4. If you get an error, make sure the _`terraform/terraform.tfvars`_ file from the previous task contains the correct values. In case of any error, just run the _`start.sh`_ script again.
170215

171216
## Task 5: Setting up Data Science Environment
172217

218+
Once we have set up our Cloud shell to extract data, we also need to prepare a Data Science environment to work with the data once it's been collected.
219+
To achieve this, we need to load this workshop's notebook into our environment through the official repository.
220+
173221
We now need to load our notebook into our environment.
174222

175223
1. Opening a **Terminal** inside the _'Other'_ section the console and re-downloading the repository again:
@@ -184,10 +232,10 @@ We now need to load our notebook into our environment.
184232
</copy>
185233
```
186234

187-
3. Install the conda environment
235+
3. Install the conda environment specifying the Python version we want (you can choose between 3.8, 3.9 and 3.10)
188236

189237
```bash
190-
<copy>odsc conda create -n myconda</copy>
238+
<copy>conda create -n myconda python=3.9</copy>
191239
```
192240

193241
![proceed](./images/proceed.png)
@@ -196,30 +244,32 @@ We now need to load our notebook into our environment.
196244

197245
```bash
198246
<copy>
199-
conda activate /home/datascience/conda/myconda_v1_0
247+
conda activate myconda
200248
</copy>
201249
```
202250

203-
5. Install Python 3.8 within the conda environment:
251+
5. Install conda dependencies, so our environment shows up in the Kernel selector:
204252

205253
```bash
206254
<copy>
207-
conda install -y python=3.8
255+
conda install nb_conda_kernels
208256
</copy>
209257
```
210258

211259
6. Install Python dependencies:
212260

213261
```bash
214262
<copy>
215-
pip install -r leagueoflegends-optimizer/deps/requirements_nn.txt
263+
pip install -r leagueoflegends-optimizer/deps/requirements_2023.txt
216264
</copy>
217265
```
218266

219267
> Note: make sure to accept prompts by typing 'y' as in 'Yes' when asked.
220268

221269
After these commands, all requirements will be fulfilled and we're ready to execute our notebooks with our newly created conda environment.
222270
271+
Once we execute any notebook in this Data Science environment, remember that we'll need to select the correct conda environment under the _Kernel_ dropdown menu.
272+
223273
## Task 6: Downloading DataSets
224274

225275
We now need to load our datasets into our environment. For that, we reuse the terminal we created in the previous step:
@@ -230,8 +280,7 @@ Then, we execute the following command, which will download all necessary datase
230280

231281
```bash
232282
<copy>
233-
wget https://objectstorage.eu-frankfurt-1.oraclecloud.com/p/wPITlcIlqhE3VuDjIxeXyqwWTUa8o96q5jy-6gBXSNhO4OKha1A1JetWozNFZIAZ/n/axywji1aljc2/b/league-hol-ocw-datasets/o/ocw_datasets.zip && unzip ocw_datasets.zip -d /home/datascience/.
234-
283+
wget https://objectstorage.eu-frankfurt-1.oraclecloud.com/p/FcwFW-_ycli9z8O_3Jf8gHbc1Fr8HkG9-vnL4I7A07mENI60L8WIMGtG5cc8Qmuu/n/axywji1aljc2/b/league-hol-ocw-datasets/o/league_ocw_2023.zip && unzip league_ocw_2023.zip -d /home/datascience/.
235284
</copy>
236285
```
237286

@@ -243,17 +292,14 @@ We should now see the repository / files in our file explorer:
243292

244293
![file explorer - 1](./images/file_explorer.png)
245294

246-
![file explorer - 2](./images/file_explorer_2.png)
295+
We navigate to the _`leagueoflegends-optimizer/notebooks/`_ directory and the notebook [_`models_2023.ipynb`_](https://github.com/oracle-devrel/leagueoflegends-optimizer/blob/livelabs/notebooks/models_2023.ipynb) is the one we will review during this workshop.
247296

248-
We navigate to the _`leagueoflegends-optimizer/notebooks/`_ directory and the notebook [_`neural_networks_lol.ipynb`_](https://github.com/oracle-devrel/leagueoflegends-optimizer/blob/livelabs/notebooks/neural_networks_lol.ipynb) is the one we will review during this workshop.
249-
250-
Let's open both of them and get to work.
251-
252-
You may now [proceed to the next lab](#next).
297+
![file explorer - 2](./images/file_explorer_2.png)
253298

299+
Let's open it. You may now [proceed to the next lab](#next).
254300
255301
## Acknowledgements
256302
257-
* **Author** - Nacho Martinez, Data Science Advocate @ DevRel
258-
* **Contributors** - Victor Martin - Product Strategy Director
259-
* **Last Updated By/Date** - May 31st, 2023
303+
- **Author** - Nacho Martinez, Data Science Advocate @ DevRel
304+
- **Contributors** - Victor Martin, Product Strategy Director
305+
- **Last Updated By/Date** - May 31st, 2023

0 commit comments

Comments
 (0)