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

Added scripts configuration

parent 1d1f892d
No related branches found
No related tags found
4 merge requests!6End of development,!5Develop,!4End of development,!3Develop
Pipeline #50437 passed
......@@ -35,6 +35,63 @@ User :
- Username: abc
- Password: <Gitlab Stored>
## Cloud-init
### Create file
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 variable or user-data.
**cloud-init :**
```yaml
write_files:
- content: |
hostname: %atrium_hostname%.daag.alpha.grandlyon.com
debug_mode: false
letsencrypt_email: %atrium_letsencrypt_email%
tls_mode: Auto
apps: # optional : applications served by atrium
- id: 1
name: Code %atrium_count_index%
icon: web_asset
color: 4292030255
is_proxy: true
host: code-%atrium_count_index%
target: localhost:8080
- id: 2
name: Desktop %atrium_count_index%
icon: web_asset
color: 4292030255
is_proxy: true
host: desktop-%atrium_count_index%
target: localhost:8081
path: /root/atrium.yaml
```
**bash command to replaced `%` content :**
```bash
sed -i "s/%atrium_hostname%/$(scw-userdata atrium_hostname)/g" /root/atrium.yaml
sed -i "s/%atrium_letsencrypt_email%/$(scw-userdata atrium_letsencrypt_email)/g" /root/atrium.yaml
sed -i "s/%atrium_count_index%/$(scw-userdata atrium_count_index)/g" /root/atrium.yaml
```
## 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/**
```HCL
user_data = {
atrium_count_index = count.index
atrium_hostname = scaleway_domain_record.subdomain_record[count.index].name
atrium_letsencrypt_email = var.LETSENCRYPT_EMAIL
user_password = var.USER_PASSWORD
cloud-init = file("../instance-scripts/cloud-init.yml") // this is not a variable, but the declaration of cloud-init file.
}
```
## Setup Terraform Locally
First, you must setup 2 local files for your variables :
......@@ -74,7 +131,7 @@ SCW_PROJECT_ID = ""
SCW_ACCESS_KEY = ""
SCW_SECRET_KEY = ""
INSTANCES_COUNT = "2"
ENVIRONMENT = "devrust"
ENVIRONMENT = ""
```
### Terraform init - Gitlab remote tfstate
......@@ -85,9 +142,9 @@ Command should look like :
```bash
export GITLAB_ACCESS_TOKEN=<YOUR-ACCESS-TOKEN>
terraform init \
-backend-config="address=https://forge.grandlyon.com/api/v4/projects/875/terraform/state/devrust" \
-backend-config="lock_address=https://forge.grandlyon.com/api/v4/projects/875/terraform/state/devrust/lock" \
-backend-config="unlock_address=https://forge.grandlyon.com/api/v4/projects/875/terraform/state/devrust/lock" \
-backend-config="address=https://forge.grandlyon.com/api/v4/projects/<project-id>/terraform/state/<tfstate-name>" \
-backend-config="lock_address=https://forge.grandlyon.com/api/v4/projects/<project-id>/terraform/state/<tfstate-name>/lock" \
-backend-config="unlock_address=https://forge.grandlyon.com/api/v4/projects/<project-id>/terraform/state/<tfstate-name>/lock" \
-backend-config="username=xxxxxxx" \
-backend-config="password=$GITLAB_ACCESS_TOKEN" \
-backend-config="lock_method=POST" \
......
......@@ -9,6 +9,9 @@ packages:
- curl
- git
write_files:
#
# Atrium config file
......
#!/bin/bash
#
# Install Atrium
#
mkdir -p /root/atrium/data && mkdir -p /root/atrium/letsencrypt_cache
sed -i "s/%atrium_hostname%/$(scw-userdata atrium_hostname)/g" /root/atrium.yaml
sed -i "s/%atrium_letsencrypt_email%/$(scw-userdata atrium_letsencrypt_email)/g" /root/atrium.yaml
sed -i "s/%atrium_count_index%/$(scw-userdata atrium_count_index)/g" /root/atrium.yaml
mv /root/atrium.yaml /root/atrium/atrium.yaml
chown -Rf 1000:1000 /root/atrium
#
# Run Atrium Container
#
docker run -d --name atrium \
--restart unless-stopped \
--net=host \
-v /root/atrium/atrium.yaml:/app/atrium.yaml \
-v /root/atrium/letsencrypt_cache:/app/letsencrypt_cache \
-v /root/atrium/data:/app/data nicolaspernoud/atrium:latest
#!/bin/bash
#
# Install Code Server
#
# cloud-init execute the bash script before HOME and USER are set.
export HOME=/root
export USER=root
mkdir -p /root/.config/code-server/
sed -i "s/%user_password%/$(scw-userdata user_password)/g" /root/config.yaml
mv /root/config.yaml /root/.config/code-server/config.yaml
curl -fsSL https://code-server.dev/install.sh | sh
#
# Run Code Server
#
sudo systemctl enable --now code-server@$USER
\ No newline at end of file
#!/bin/bash
#
# Install Docker
#
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
\ No newline at end of file
#!/bin/bash
#
# Install Repository
#
git clone https://github.com/NathanRodet/rust-axum-demo /root/rust-axum-demo
\ No newline at end of file
#!/bin/bash
#
# Install Rust
#
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source \"$HOME/.cargo/env\"
\ No newline at end of file
#
# Run Webtop Container
#
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 8081:3000 \
-v /root/webtop:/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
echo "$(scw-userdata user_password)\n$(scw-userdata user_password)" | docker exec -i webtop passwd abc
\ No newline at end of file
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