Skip to content

Commit deda8a0

Browse files
committed
feat: added terraform v1
1 parent df35358 commit deda8a0

File tree

16 files changed

+598
-1
lines changed

16 files changed

+598
-1
lines changed

.gitignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,17 @@ dmypy.json
131131

132132

133133
# Ignore config.yaml for Oracle Autonomous Database
134-
config.yaml
134+
config.yaml
135+
136+
# Terraform
137+
**/.terraform/*
138+
*.tfstate
139+
*.tfstate.*
140+
*.tfvars
141+
override.tf
142+
override.tf.json
143+
*_override.tf
144+
*_override.tf.json
145+
.terraform.lock.hcl
146+
.terraformrc
147+
terraform.rc

dev/README.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# LoL Optimizer deployment
2+
3+
## Requirements
4+
5+
- Active Oracle Cloud Account
6+
- Credits available
7+
- Administrative permissions
8+
9+
## Download
10+
11+
Open OCI Console, and click Cloud Shell.
12+
13+
```
14+
git clone --branch livelabs https://github.com/jasperan/f1-telemetry-oracle.git
15+
```
16+
17+
Change to `f1-telemetry-oracle` directory:
18+
```
19+
cd f1-telemetry-oracle/
20+
```
21+
22+
## Set up
23+
24+
From this directory `./dev`.
25+
```
26+
cd dev/
27+
```
28+
29+
```
30+
cp terraform/terraform.tfvars.template terraform/terraform.tfvars
31+
```
32+
33+
Get details for the `terraform.tfvars` file:
34+
- Tenancy:
35+
```
36+
echo $OCI_TENANCY
37+
```
38+
- Compartment (root by default):
39+
```
40+
echo $OCI_TENANCY
41+
```
42+
> If you need a specific compartment, get the OCID by name with:
43+
> ```
44+
> oci iam compartment list --all --compartment-id-in-subtree true --name COMPARTMENT_NAME --query "data[].id"
45+
> ```
46+
- SSH Public Key:
47+
```
48+
cat ~/.ssh/id_rsa.pub
49+
```
50+
51+
Refresh the Riot Developer API key, only valid for 24 hours.
52+
53+
Edit the values with `vim` or `nano` with your tenancy, compartment, ssh public key and Riot API key:
54+
```
55+
vim terraform/terraform.tfvars
56+
```
57+
58+
## Deploy
59+
60+
```
61+
./start.sh
62+
```
63+
64+
> If there are permission errors with **start.sh**, make sure to change permissions appropriately before trying to execute again:
65+
```
66+
chmod 700 start.sh
67+
```
68+
69+
70+
The output will be an `ssh` command to connect with the machine.
71+
72+
> Re-run the `start.sh` in case of failure
73+
74+
## Test
75+
76+
After ssh into the machine, run the check app.
77+
78+
```
79+
python3 src/check.py
80+
```
81+
82+
All checks should indicate `OK`. If any `FAIL`, review the setup and make sure `terraform.tfvars` are valid.
83+
84+
### Destroy
85+
86+
```
87+
./stop.sh
88+
```
89+
90+
91+
## AJSON export/import
92+
93+
Create Bucket.
94+
95+
```
96+
BEGIN
97+
DBMS_CLOUD.CREATE_CREDENTIAL(
98+
credential_name => 'LOL_BUCKET_CREDENTIALS',
99+
username => 'user1@example.com',
100+
password => 'password'
101+
);
102+
END;
103+
/
104+
```
105+
106+
Match:
107+
```
108+
BEGIN
109+
DBMS_CLOUD.EXPORT_DATA(
110+
credential_name => 'LOL_BUCKET_CREDENTIALS',
111+
file_uri_list => 'https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/namespace-string/b/lolbackup/o/match_export',
112+
query => 'SELECT * FROM match',
113+
format => JSON_OBJECT('type' value 'csv', 'delimiter' value '|', 'compression' value 'gzip'));
114+
END;
115+
/
116+
```
117+
118+
Match Detail:
119+
```
120+
BEGIN
121+
DBMS_CLOUD.EXPORT_DATA(
122+
credential_name => 'LOL_BUCKET_CREDENTIALS',
123+
file_uri_list => 'https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/namespace-string/b/lolbackup/o/match_detail_export',
124+
query => 'SELECT * FROM match_detail',
125+
format => JSON_OBJECT('type' value 'csv', 'delimiter' value '|', 'compression' value 'gzip'));
126+
END;
127+
/
128+
```
129+
130+
Summoner:
131+
```
132+
BEGIN
133+
DBMS_CLOUD.EXPORT_DATA(
134+
credential_name => 'LOL_BUCKET_CREDENTIALS',
135+
file_uri_list => 'https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/namespace-string/b/lolbackup/o/summoner_export',
136+
query => 'SELECT * FROM summoner',
137+
format => JSON_OBJECT('type' value 'csv', 'delimiter' value '|', 'compression' value 'gzip'));
138+
END;
139+
/
140+
```
141+
142+
Predictor Live Client:
143+
```
144+
BEGIN
145+
DBMS_CLOUD.EXPORT_DATA(
146+
credential_name => 'LOL_BUCKET_CREDENTIALS',
147+
file_uri_list => 'https://objectstorage.eu-frankfurt-1.oraclecloud.com/n/namespace-string/b/lolbackup/o/predictor_liveclient_export',
148+
query => 'SELECT * FROM predictor_liveclient',
149+
format => JSON_OBJECT('type' value 'csv', 'delimiter' value '|', 'compression' value 'gzip'));
150+
END;
151+
/
152+
```
153+
154+
> Update Credentials?
155+
> ```
156+
> BEGIN
157+
> DBMS_CLOUD.UPDATE_CREDENTIAL(
158+
> credential_name => 'LOL_BUCKET_CREDENTIALS',
159+
> attribute => 'PASSWORD',
160+
> value => 'password');
161+
> END;
162+
> /
163+
> ```

dev/start.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
start_time=$(date +%s)
4+
5+
banner()
6+
{
7+
echo "+------------------------------------------+"
8+
printf "| %-40s |\n" "`date`"
9+
echo "| |"
10+
printf "|`tput bold` %-40s `tput sgr0`|\n" "$@"
11+
echo "+------------------------------------------+"
12+
}
13+
14+
checkpoint()
15+
{
16+
if [ $? -ne 0 ]; then
17+
exit $?
18+
fi
19+
}
20+
21+
if [ -z "$BASE_DIR" ]
22+
then
23+
export BASE_DIR=$(pwd)
24+
fi
25+
26+
banner "Terraform Init"
27+
cd $BASE_DIR/terraform
28+
terraform init
29+
checkpoint
30+
31+
banner "Terraform Apply"
32+
terraform apply -auto-approve
33+
checkpoint
34+
35+
sleep 2
36+
37+
banner "Ansible Provisioning"
38+
export ANSIBLE_HOST_KEY_CHECKING=False
39+
ansible-playbook -i generated/app.ini ../ansible/server/server.yaml
40+
checkpoint
41+
42+
banner "Output"
43+
terraform output
44+
checkpoint
45+
46+
cd $BASE_DIR
47+
48+
end_time=$(date +%s)
49+
elapsed=$(( end_time - start_time ))
50+
echo "Time: $elapsed sec"

dev/stop.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
start_time=$(date +%s)
4+
5+
banner()
6+
{
7+
echo "+------------------------------------------+"
8+
printf "| %-40s |\n" "`date`"
9+
echo "| |"
10+
printf "|`tput bold` %-40s `tput sgr0`|\n" "$@"
11+
echo "+------------------------------------------+"
12+
}
13+
14+
if [ -z "$BASE_DIR" ]
15+
then
16+
export BASE_DIR=$(pwd)
17+
fi
18+
19+
banner "Terraform Destroy"
20+
cd $BASE_DIR/terraform
21+
terraform destroy -auto-approve
22+
23+
end_time=$(date +%s)
24+
elapsed=$(( end_time - start_time ))
25+
echo "Time: $elapsed sec"

dev/terraform/ansible_inventory.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "local_file" "ansible_inventory" {
2+
content = templatefile("${path.module}/inventory.tftpl",
3+
{
4+
public_ip = oci_core_instance.compute[0].public_ip
5+
}
6+
)
7+
filename = "${path.module}/generated/app.ini"
8+
}

dev/terraform/compute.tf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
variable "instance_name" {
2+
default = "lol"
3+
}
4+
5+
variable "instance_shape" {
6+
default = "VM.Standard.E3.Flex"
7+
}
8+
9+
variable "instance_ocpus" {
10+
default = 1
11+
}
12+
13+
variable "instance_shape_config_memory_in_gbs" {
14+
default = 8
15+
}
16+
17+
data "oci_core_images" "images" {
18+
compartment_id = var.compartment_ocid
19+
shape = var.instance_shape
20+
operating_system = "Oracle Linux"
21+
operating_system_version = "8"
22+
sort_by = "TIMECREATED"
23+
sort_order = "DESC"
24+
}
25+
26+
data "oci_identity_availability_domain" "ad" {
27+
compartment_id = var.tenancy_ocid
28+
ad_number = 1
29+
}
30+
31+
resource "oci_core_instance" "compute" {
32+
count = 1
33+
availability_domain = data.oci_identity_availability_domain.ad.name
34+
compartment_id = var.compartment_ocid
35+
display_name = "${var.instance_name}-${random_string.deploy_id.result}_${count.index}"
36+
shape = var.instance_shape
37+
38+
metadata = {
39+
ssh_authorized_keys = var.ssh_public_key
40+
}
41+
42+
shape_config {
43+
ocpus = var.instance_ocpus
44+
memory_in_gbs = var.instance_shape_config_memory_in_gbs
45+
}
46+
47+
create_vnic_details {
48+
subnet_id = oci_core_subnet.publicsubnet.id
49+
display_name = var.instance_name
50+
assign_public_ip = true
51+
assign_private_dns_record = true
52+
hostname_label = "${var.instance_name}${count.index}"
53+
}
54+
55+
source_details {
56+
source_type = "image"
57+
source_id = data.oci_core_images.images.images[0].id
58+
}
59+
60+
timeouts {
61+
create = "60m"
62+
}
63+
}

dev/terraform/data.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "random_string" "deploy_id" {
2+
length = 4
3+
special = false
4+
}

dev/terraform/datascience.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
resource "oci_datascience_project" "lol_project" {
2+
compartment_id = var.compartment_ocid
3+
4+
description = "RedBull Project"
5+
display_name = "RedBull Project ${random_string.deploy_id.result}"
6+
7+
depends_on = [
8+
oci_core_subnet.privatesubnet
9+
]
10+
}
11+
12+
# FIXME bad hack to avoid: The specified subnet is not accessible. Select a different subnet.
13+
resource "time_sleep" "wait_a_bit" {
14+
create_duration = "120s"
15+
}
16+
17+
resource "oci_datascience_notebook_session" "lol_notebook_session" {
18+
compartment_id = var.compartment_ocid
19+
project_id = oci_datascience_project.lol_project.id
20+
21+
display_name = "RedBull Notebook Session"
22+
23+
notebook_session_config_details {
24+
shape = data.oci_datascience_notebook_session_shapes.ds_shapes.notebook_session_shapes[0].name
25+
26+
subnet_id = oci_core_subnet.privatesubnet.id
27+
}
28+
29+
depends_on = [
30+
time_sleep.wait_a_bit
31+
]
32+
33+
}
34+
35+
data "oci_datascience_notebook_session_shapes" "ds_shapes" {
36+
compartment_id = var.compartment_ocid
37+
filter {
38+
name = "core_count"
39+
values = [1]
40+
}
41+
}
42+
43+
output "ds_notebook_session_shape" {
44+
value = data.oci_datascience_notebook_session_shapes.ds_shapes.notebook_session_shapes[0].name
45+
}
46+
47+
output "ds_notebook_session" {
48+
value = oci_datascience_notebook_session.lol_notebook_session.notebook_session_url
49+
}

0 commit comments

Comments
 (0)