Skip to content
Snippets Groups Projects
Commit 18357eb0 authored by Nathan Rodet's avatar Nathan Rodet
Browse files

Changes to cloud-init config

parent 60e84810
No related branches found
No related tags found
6 merge requests!6End of development,!5Develop,!4End of development,!3Develop,!2hot-fix: change readme.md,!1Develop
Pipeline #49041 passed
#!/bin/bash
echo "|------------------------|"
echo "| INITIALISATION DU LABO |"
echo "|------------------------|"
if [ ! -f ".env" ]; then
echo "Créez un fichier .env de la forme suivante :"
echo "SCW_ACCESS_KEY="
echo "SCW_SECRET_KEY="
echo "TF_VAR_PROJECT_ID="
echo "TF_VAR_INSTANCES_COUNT=2"
exit 1
fi
export $(cat .env | xargs)
# Move to Terraform directory
cd ./terraform
# Initialize a Terraform working directory
terraform init
# Generate and show the execution plan
terraform plan
# Build the infrastructure
terraform apply
# Echo Terraform outputs
terraform output
# Move to default directory
cd ..
echo "|--------------|"
echo "| LABO DÉMARRÉ |"
echo "|--------------|"
echo "Se connecter sur les IPs, avec le port 80 pour webtop, et 8080 pour code-server."
echo "Le mot de passe des instances est yfB4W23G."
#!/bin/bash
export $(cat .env | xargs)
terraform destroy
#cloud-config #cloud-config
# System update
package_update: true package_update: true
package_upgrade: true package_upgrade: true
# Install Packages
packages: packages:
- curl - curl
- jq - jq
- git - git
runcmd: runcmd:
# Check env variables access
- "echo $USER_PASSWORD > test.txt"
# Install Rust
- "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" - "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
- "source \"$HOME/.cargo/env\"" - "source \"$HOME/.cargo/env\""
# Install Docker
- "curl -fsSL https://get.docker.com -o get-docker.sh | sh"
# Install atrium
- "git clone https://github.com/nicolaspernoud/atrium.git"
# Run Webtop Container
- "docker stop webtop"
- "docker rm webtop"
- "docker run -d --name=webtop --security-opt seccomp=unconfined -e PUID=0 -e PGID=0 -e TZ=Europe/Paris -e SUBFOLDER=/ -e KEYBOARD=fr-fr-azerty -e AUTO_LOGIN=false -p 80:3000 -v /root/webtop_data/:/config -v /var/run/docker.sock:/var/run/docker.sock --shm-size=8gb --cap-add=NET_ADMIN --privileged --restart unless-stopped --sysctl net.ipv6.conf.all.disable_ipv6=0 lscr.io/linuxserver/webtop:ubuntu-xfce"
# Install Code Server
- "curl -fsSL https://code-server.dev/install.sh | sh" - "curl -fsSL https://code-server.dev/install.sh | sh"
- "mkdir -p /root/.config/code-server/" - "mkdir -p /root/.config/code-server/"
- "echo 'bind-addr: 0.0.0.0:8080\nauth: password\npassword: yfB4W23G\ncert: false\n' > /root/.config/code-server/config.yaml" - "echo 'bind-addr: 0.0.0.0:8080\nauth: password\npassword: yfB4W23G\ncert: false\n' > /root/.config/code-server/config.yaml"
- "systemctl enable --now code-server@$USER" - "systemctl enable --now code-server@$USER"
...@@ -83,6 +83,7 @@ resource "scaleway_instance_server" "user_instance_server" { ...@@ -83,6 +83,7 @@ resource "scaleway_instance_server" "user_instance_server" {
security_group_id = scaleway_instance_security_group.www.id security_group_id = scaleway_instance_security_group.www.id
user_data = { user_data = {
USER_PASSWORD = var.USER_PASSWORD
cloud-init = file("cloud-init.yml") cloud-init = file("cloud-init.yml")
} }
...@@ -90,38 +91,4 @@ resource "scaleway_instance_server" "user_instance_server" { ...@@ -90,38 +91,4 @@ resource "scaleway_instance_server" "user_instance_server" {
scaleway_account_ssh_key.ssh_key, scaleway_account_ssh_key.ssh_key,
scaleway_instance_security_group.www scaleway_instance_security_group.www
] ]
} }
\ No newline at end of file
#resource "null_resource" "provisioner" {
# count = var.INSTANCES_COUNT
# depends_on = [
# scaleway_instance_server.user_instance_server
# ]
#
# connection {
# host = element(scaleway_instance_ip.public_ip.*.address, count.index)
# type = "ssh"
# user = "root"
# private_key = var.SCW_SSH_PRIVATE_KEY
# timeout = "2m"
# }
#
# // Install Rust
# provisioner "remote-exec" {
# inline = [
# "apt-get update -y'",
# "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y'",
# "source \"$HOME/.cargo/env\"",
# ]
# }
#
# // Install Code-server
# provisioner "remote-exec" {
# inline = [
# "curl -fsSL https://code-server.dev/install.sh | sh",
# "mkdir -p /root/.config/code-server/",
# "echo 'bind-addr: 0.0.0.0:8080\nauth: password\npassword: yfB4W23G\ncert: false\n' > /root/.config/code-server/config.yaml",
# "systemctl enable --now code-server@$USER"
# ]
# }
#}
\ No newline at end of file
...@@ -30,6 +30,12 @@ variable "SCW_SSH_PRIVATE_KEY" { ...@@ -30,6 +30,12 @@ variable "SCW_SSH_PRIVATE_KEY" {
description = "SSH private key from Gitlab agent for remote-exec" description = "SSH private key from Gitlab agent for remote-exec"
} }
variable "USER_PASSWORD" {
type = string
sensitive = true
description = "User password for accessing services"
}
variable "INSTANCES_COUNT" { variable "INSTANCES_COUNT" {
type = number type = number
description = "Number of instances to create" description = "Number of instances to create"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment