Skip to content

Commit

Permalink
enable solutions management
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkcjelli authored and frittentheke committed Jun 30, 2022
1 parent d795098 commit f54426a
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ mail/mail_template.txt
mail/mail_template_en.txt
mail/mail_info.yaml
passwords
solutions.patch
30 changes: 29 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This terraform script will create the following resources:

If you look for the GCP terraform configuration, take a look at the folder `gcp_setup`.

## Prerequisite
## Prerequisites

- terraform (`v1.1.7+`)
- [puttygen](https://www.puttygen.com/) (tested with Release 0.71)
Expand Down Expand Up @@ -49,6 +49,34 @@ After the creation of the instances run `./scripts/check_connection.sh` to check
Terraform state is stored locally by default. The `main.tf` contains the required backend config snippet to enable remote state with a single command.
This could be useful if you have to hand over the training environment to someone else.

## Automatically download and unpack solutions

In order to automatically download and unpack solutions, set the variable `solutions_url` to the URL provided by the Linux Foundation. The solutions will be unpacked on every machine in the `/home/student/LF*` directory.

see [terraform.tfvars.example](terraform.tfvars.example) for an example, you'll have to provide the Linux Foundation provided username and password inside the url.

### Bonus: Automatically patching solutions

If you find that the official solutions contain errors, you can also automatically fix them and patch all the solutions you automatically downloaded.

To do that:

1. Download the solutions on your machine using the official URL (of course use the correct username and password)
```
wget https://training.linuxfoundation.org/cm/LFS458/LFS458_V1.22.1_SOLUTIONS.tar.xz --user=**USERNAME** --password=**PASSWORD**
```
1. Unpack the tarball
1. Duplicate the unpacked directory:
```
cp -a LFS458 LFS458patched
```
1. In the `LFS458patched` directory (or whatever you named it), edit, delete and create all files as needed
1. create a patch for the whole tree:
```
diff -ruN LFS458 LFS458patched > solutions.patch
```
1. Copy the `solutions.patch` file (using exactly this name) to the terraform base dir (next to your `terraform.tfvars` file)

## Sending Mails

Ensure that the [Gmail API](https://developers.google.com/gmail/api/quickstart/python#step_1_turn_on_the) is activated.
Expand Down
18 changes: 10 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ provider "openstack" {
# -backend-config="state_name=terraform-$TRAINER_NAME.stat"

module "student_workspace" {
source = "./modules/student_workspace"
students = var.students
instances = var.instances
network = openstack_networking_network_v2.network.id
machine_type = var.machine_type
course_type = var.course_type
trainer = var.trainer
sec_groups = [openstack_networking_secgroup_v2.sec.name]
source = "./modules/student_workspace"
students = var.students
instances = var.instances
network = openstack_networking_network_v2.network.id
machine_type = var.machine_type
course_type = var.course_type
trainer = var.trainer
sec_groups = [openstack_networking_secgroup_v2.sec.name]
solutions_url = var.solutions_url
solutions_patch = fileexists("${path.module}/solutions.patch") ? filebase64("${path.module}/solutions.patch") : ""
}

module "wetty_server" {
Expand Down
30 changes: 30 additions & 0 deletions modules/student_workspace/cloudinit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ users:
ssh_authorized_keys:
- ${SSH_PUB_KEY}
write_files:
%{ if SOLUTIONS_PATCH != "" }
- path: "/tmp/solutions.patch"
permissions: "0666"
encoding: b64
content: ${SOLUTIONS_PATCH}
%{ endif }
- path: "/tmp/download_solutions.sh"
permissions: "0700"
content: |
#!/bin/bash
if [[ "${SOLUTIONS_URL}" =~ https://.+:[email protected]/cm/.+SOLUTIONS.tar.+ ]]
then
echo "downloading solutions from ${SOLUTIONS_URL}"
wget -P /tmp -q ${SOLUTIONS_URL}
echo "unpack solutions"
tar -xvf /tmp/*SOLUTIONS.tar* -C /home/${DEFAULT_USER}/
echo "chown solutions to ${DEFAULT_USER}"
chown -R ${DEFAULT_USER}:users /home/${DEFAULT_USER}/LF*
if [[ -f /tmp/solutions.patch ]]
then
echo "trying to patch solutions"
patch -d /home/${DEFAULT_USER} -p0 < /tmp/solutions.patch
fi
else
echo "SOLUTIONS_URL invalid or username password part missing"
fi
- path: "/etc/vim/vimrc.local"
permissions: "0744"
content: |
Expand All @@ -36,6 +63,9 @@ write_files:
set shiftwidth=2
set softtabstop=2
runcmd:
- /tmp/download_solutions.sh

power_state:
mode: reboot
timeout: 30
2 changes: 2 additions & 0 deletions modules/student_workspace/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ resource "openstack_compute_instance_v2" "instance" {
{
DEFAULT_USER = "student"
SSH_PUB_KEY = trimspace(tls_private_key.ssh_key[split("-", each.value)[0]].public_key_openssh)
SOLUTIONS_URL = var.solutions_url
SOLUTIONS_PATCH = var.solutions_patch
}
)

Expand Down
10 changes: 10 additions & 0 deletions modules/student_workspace/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ variable "trainer" {
variable "sec_groups" {
type = list(string)
}

variable "solutions_url" {
type = string
default = ""
}

variable "solutions_patch" {
type = string
default = ""
}
23 changes: 23 additions & 0 deletions solutions.patch.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff -ruN LFD459/SOLUTIONS/s_02/k8sWorker.sh LFD459p/SOLUTIONS/s_02/k8sWorker.sh
--- LFD459/SOLUTIONS/s_02/k8sWorker.sh 2022-02-24 20:24:03.000000000 +0000
+++ LFD459p/SOLUTIONS/s_02/k8sWorker.sh 2022-05-20 12:33:07.621080542 +0000
@@ -47,7 +47,7 @@
sudo apt-get update

# Install cri-o
-sudo apt-get install -y cri-o cri-o-runc podman buildah
+sudo apt-get install -y cri-o cri-o-runc podman

sleep 3

diff -ruN LFD459/SOLUTIONS/s_02/k8scp.sh LFD459p/SOLUTIONS/s_02/k8scp.sh
--- LFD459/SOLUTIONS/s_02/k8scp.sh 2022-02-24 20:24:03.000000000 +0000
+++ LFD459p/SOLUTIONS/s_02/k8scp.sh 2022-05-20 12:32:55.557075552 +0000
@@ -48,7 +48,7 @@
sudo apt-get update

# Install cri-o
-sudo apt-get install -y cri-o cri-o-runc podman buildah
+sudo apt-get install -y cri-o cri-o-runc podman

sleep 3
5 changes: 5 additions & 0 deletions terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ course_type = "lfs458"
instances = ["cp", "worker"]
# instances = ["cp", "secondcp", "thirdcp", "ha-proxy", "worker"]
network_range = "172.128.0.0/24"
wetty_config = { enabled = false,
trainer_email = "[email protected]"
}

#solutions_url = "https://username:[email protected]/cm/LFD459/LFD459_V1.23.1-u1_SOLUTIONS.tar.xz"
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ variable "dns_domain" {
description = "domain for creating DNS records, currently only used for wetty-server"
default = "training-lf-kubernetes.fra.ics.inovex.io."
}

variable "solutions_url" {
description = "URL to download and unpack solutions from LF"
type = string
default = ""
}

0 comments on commit f54426a

Please sign in to comment.