diff --git a/README.md b/README.md index c3386aed16a65d76378920b3cdf2924a4e526565..32c3e7f1b3a18f5e52fc2f951273efefbd7d7b3c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Alpha Project Manager +# Labo Rust -An Infrastructure as Code manager to deploy lab infrastructure and configure instances. Working with Atrium, Gitlab CI, Terraform, Cloud-init and Scaleway. +Infrastructure as Code project to deploy lab infrastructure and configure instances. Working with Atrium, Gitlab CI, Terraform, Cloud-init, bash scripts and Scaleway. ### How does it work ? @@ -30,11 +30,13 @@ After the resources provisionned with Terraform, Cloud-init will configure the i After deployment, each resource can be accessed though HTTPS depending on their count number : - https://desktop-0.rust-0.daag.alpha.grandlyon.com/ - https://code-0.rust-0.daag.alpha.grandlyon.com/ +- https://terminal-0.rust-0.daag.alpha.grandlyon.com/ - https://rust-0.daag.alpha.grandlyon.com/ - https://desktop-1.rust-1.daag.alpha.grandlyon.com/ - https://code-1.rust-1.daag.alpha.grandlyon.com/ +- https://terminal-1.rust-1.daag.alpha.grandlyon.com/ - https://rust-1.daag.alpha.grandlyon.com/ ### Credentials @@ -57,7 +59,7 @@ Template are available to the link below. In this example, you will find how to create a file to a defined path with cloud-init. Content inside `%` are meant to be replaced with sed command to be able to use environment variables or user-data. -**example:** +**Example:** ```yaml write_files: - content: | @@ -94,7 +96,7 @@ sed -i "s/%atrium_count_index%/$(scw-userdata atrium_count_index)/g" /root/atriu The example show how to curl a configuration file from repository to a defined path with cloud-init. -**example :** +**Example :** ```yaml runcmd: # @@ -111,11 +113,10 @@ runcmd: ## Use Gitlab variables in instances -### Example - From my instances, I should be able to access the variables as user-data using the command `scw-userdata <my-variable>` after declaring them in Terraform. **Some documentation : https://blog.scaleway.com/introducing-scaleway-cloud-init-support/** +**Example : Declare in Terraform** ```HCL user_data = { atrium_count_index = count.index @@ -126,6 +127,11 @@ user_data = { } ``` +** Example : Retrieve in instance +```bash +scw-userdata atrium_count_index +``` + ## Setup Terraform Locally First, you must setup 2 local files for your variables : @@ -164,7 +170,7 @@ Now, you can create a file for your variables information called **variables-loc SCW_PROJECT_ID = "" SCW_ACCESS_KEY = "" SCW_SECRET_KEY = "" -INSTANCES_COUNT = "2" +INSTANCES_COUNT = "" ENVIRONMENT = "" ``` diff --git a/instance-scripts/config-files/atrium.yaml b/instance-scripts/config-files/atrium.yaml index af50a7c7b6e2fcd6442f0ed44cb2beafa57d63e9..b9f6de3f6cc1e9de8850f93af647f93887b56e3e 100644 --- a/instance-scripts/config-files/atrium.yaml +++ b/instance-scripts/config-files/atrium.yaml @@ -5,21 +5,21 @@ letsencrypt_email: %atrium_letsencrypt_email% tls_mode: Auto apps: # optional : applications served by atrium - id: 1 - name: Code %atrium_count_index% + name: Code icon: web_asset color: 4292030255 is_proxy: true host: code-%atrium_count_index% target: localhost:8080 - id: 2 - name: Desktop %atrium_count_index% + name: Desktop icon: web_asset color: 4292030255 is_proxy: true host: desktop-%atrium_count_index% target: localhost:8081 - id: 3 - name: Terminal %atrium_count_index% + name: Terminal icon: terminal color: 4292030255 is_proxy: true @@ -28,6 +28,8 @@ apps: # optional : applications served by atrium secured: true login: admin password: %user_password% + roles: + - ADMINS users: - login: admin password: %user_password_hash% diff --git a/instance-scripts/scripts/atrium.sh b/instance-scripts/scripts/atrium.sh index 4644edfbca01081e4ed824a47a7e1681acf9e2e0..b95a734fdba749ec98e56c693c308e16a6030ab6 100644 --- a/instance-scripts/scripts/atrium.sh +++ b/instance-scripts/scripts/atrium.sh @@ -9,7 +9,7 @@ # echo $(scw-userdata user_password) | argon2 $(echo $RANDOM | md5sum | head -c 10) -id -l 32 -e # -export USER_PASSWORD_HASH=$(echo "$(scw-userdata user_password)" | argon2 "$(echo $RANDOM | md5sum | head -c 10)" -id -l 32 -e) +export USER_PASSWORD_HASH=$(echo -n "$(scw-userdata user_password)" | argon2 "$(echo $RANDOM | md5sum | head -c 12)" -id -l 32 -e) mkdir -p /root/atrium/data && mkdir -p /root/atrium/letsencrypt_cache curl https://forge.grandlyon.com/systemes-dinformation/alpha/projects/labo-rust/-/raw/develop/instance-scripts/config-files/atrium.yaml -o root/atrium/atrium.yaml diff --git a/instance-scripts/scripts/ttyd.sh b/instance-scripts/scripts/ttyd.sh index 45b88f534194e5105f07df4612696f4ce4963fba..eeb2c71c13137e14515fced7790b2caba3a97fe3 100644 --- a/instance-scripts/scripts/ttyd.sh +++ b/instance-scripts/scripts/ttyd.sh @@ -5,9 +5,9 @@ # mkdir -p /root/ttyd -curl https://github.com/tsl0922/ttyd/releases/download/1.7.2/ttyd.x86_64 -o root/ttyd/ttyd.x86_64 +curl -k -L -s https://github.com/tsl0922/ttyd/releases/download/1.7.3/ttyd.x86_64 -o root/ttyd/ttyd.x86_64 chmod +x /root/ttyd/ttyd.x86_64 curl https://forge.grandlyon.com/systemes-dinformation/alpha/projects/labo-rust/-/raw/develop/instance-scripts/config-files/ttyd.service -o etc/systemd/system/ttyd.service sed -i "s|%user_password%|$(scw-userdata user_password)|g" /etc/systemd/system/ttyd.service -systemctl enable ttyd.service && systemctl start ttyd.service \ No newline at end of file +systemctl enable ttyd.service && systemctl start ttyd.service