Skip to content

Commit

Permalink
Setup Runtipi (#54)
Browse files Browse the repository at this point in the history
* Setup Runtipi

* Upgrade README.md

* Add configuration Runtipi

* Upgrade oracle images

* Fix stratup script
  • Loading branch information
filippolmt authored Aug 20, 2024
1 parent 6502c64 commit 8e368ad
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 64 deletions.
73 changes: 62 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
# Terraform OCI Free Tier

This repository provides Terraform configurations for deploying resources in Oracle Cloud Infrastructure (OCI) Free Tier.
This repository provides Terraform configurations for deploying resources in the Oracle Cloud Infrastructure (OCI) Free Tier.

## Table of Contents

- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Usage](#usage)
- [Files](#files)
- [License](#license)
- [Terraform OCI Free Tier](#terraform-oci-free-tier)
- [Table of Contents](#table-of-contents)
- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Usage](#usage)
- [Files](#files)
- [RunTipi Configuration](#runtipi-configuration)
- [License](#license)
- [Requirements](#requirements)
- [Providers](#providers)
- [Modules](#modules)
- [Resources](#resources)
- [Inputs](#inputs)
- [Outputs](#outputs)

## Prerequisites

- [Terraform](https://www.terraform.io/downloads.html) installed on your local machine.
- Oracle Cloud Infrastructure (OCI) account.
- [Terraform](https://developer.hashicorp.com/terraform/install) or [OpenTofu](https://opentofu.org/docs/intro/install/) installed on your local machine.
- An Oracle Cloud Infrastructure (OCI) account.
- OCI CLI configured with your credentials.

## Setup
Expand All @@ -26,31 +35,49 @@ This repository provides Terraform configurations for deploying resources in Ora

2. **Configure your variables**:
Copy the `terraform.tfvars.template` to `terraform.tfvars` and fill in the required variables.
By default, the `install_runtipi` variable is set to `true`, which will trigger the installation of RunTipi. If you do not wish to install RunTipi, set this variable to `false`.
```bash
cp terraform.tfvars.template terraform.tfvars
```

3. **Initialize Terraform**:
3. **Initialize Terraform or OpenTofu**:
Depending on the tool you are using, run:
```bash
terraform init
```
or
```bash
tofu init
```

## Usage

1. **Plan the deployment**:
```bash
terraform plan
```
or
```bash
tofu plan
```

2. **Apply the deployment**:
```bash
terraform apply
```
or
```bash
tofu apply
```

3. **Destroy the deployment**:
```bash
terraform destroy
```
or
```bash
tofu destroy
```

## Files

Expand All @@ -62,7 +89,30 @@ This repository provides Terraform configurations for deploying resources in Ora
- `.github/workflows/`: Contains GitHub Actions workflows for CI/CD.
- `documentation.yml`: Workflow for generating documentation.
- `tfsec.yml`: Workflow for running TFsec security scans.
- `scripts/startup.sh`: Script for initial setup and configuration.
- `scripts/startup.sh`: Script for initial setup and configuration. By default, this script installs RunTipi unless the `install_runtipi` variable is set to `false`.

## RunTipi Configuration

If `install_runtipi` is set to `true`, the setup script will install RunTipi and configure the local network for running applications within the local domain. Follow these steps to correctly configure RunTipi:

1. **Access RunTipi via Public IP**:
- Install AdGuard from the RunTipi apps.
- In the "Network Interface" section, add the IP `127.0.0.1` and ensure the system is also reachable from the internet.
- Add a valid DNS or any DNS by modifying the `hosts` file if needed.

2. **Configure DNS Resolution for VPN Network**:
- Access the RunTipi dashboard and follow this guide for DNS resolution within the VPN network: [RunTipi DNS Resolution Guide](https://runtipi.io/docs/guides/local-certificate#dns-resolution).
- Configure the IP to `172.18.0.254`, which is the IP set for Traefik.

3. **Configure WireGuard**:
- Install and configure WireGuard by adding a public IP or DNS.
- Set a password and configure the AdGuard IP to `172.18.0.253`.
- Restart RunTipi.

4. **Disable Internet Access**:
- Once AdGuard is configured and running, you can disable internet access to ensure that applications are only reachable within the local network.

Once these steps are complete, you will be able to use the local network without the applications being accessible externally.

## License

Expand Down Expand Up @@ -114,8 +164,9 @@ No modules.
| <a name="input_availability_domain_number"></a> [availability\_domain\_number](#input\_availability\_domain\_number) | The availability domain number | `number` | `1` | no |
| <a name="input_compartment_ocid"></a> [compartment\_ocid](#input\_compartment\_ocid) | The OCID of the compartment | `string` | n/a | yes |
| <a name="input_fault_domain"></a> [fault\_domain](#input\_fault\_domain) | The fault domain to deploy to | `string` | `"FAULT-DOMAIN-2"` | no |
| <a name="input_install_runtipi"></a> [install\_runtipi](#input\_install\_runtipi) | Install Homeserver Runtipi refs: https://runtipi.io/ | `bool` | `true` | no |
| <a name="input_instance_display_name"></a> [instance\_display\_name](#input\_instance\_display\_name) | The display name of the instance | `string` | `"DockerHost"` | no |
| <a name="input_instance_image_ocid"></a> [instance\_image\_ocid](#input\_instance\_image\_ocid) | The OCID of the image to use for the instance | `map(any)` | <pre>{<br> "af-johannesburg-1": "ocid1.image.oc1.af-johannesburg-1.aaaaaaaax333o2ycfo3kez6e2lcw5twqdrkfqrumo6hs3iwhdf27gnnbrx5a",<br> "ap-chuncheon-1": "ocid1.image.oc1.ap-chuncheon-1.aaaaaaaac45fgllwh5rdl2chkf6xte2yjvqbtlaz7zkhrxs2pcmnlzjbfs5a",<br> "ap-hyderabad-1": "ocid1.image.oc1.ap-hyderabad-1.aaaaaaaapmowuredsvjoajp2hxhrxxvk4zx6wlpoedptn2vn4jc67i4yzqqq",<br> "ap-melbourne-1": "ocid1.image.oc1.ap-melbourne-1.aaaaaaaa5ottxpbcv44udrgaivtibl2kclq267g347mhkmxf7sukwe6rlowa",<br> "ap-mumbai-1": "ocid1.image.oc1.ap-mumbai-1.aaaaaaaaq3emfywi6i7oyi5bzd4o2p4wqw3gq6l4r4wj5qd3azsicfq33iea",<br> "ap-osaka-1": "ocid1.image.oc1.ap-osaka-1.aaaaaaaalkf7sczol3b2u3e4g365cb44vh2hlwv4y45p4sumobi2nxbrftzq",<br> "ap-seoul-1": "ocid1.image.oc1.ap-seoul-1.aaaaaaaazsuvtlhqoe67xqgeazq62ykipstgv5ct3i62zfzezxd4tpgcaq2q",<br> "ap-singapore-1": "ocid1.image.oc1.ap-singapore-1.aaaaaaaapptlp7yb5s6regbd77w2qylyi6d7brnnt3qm5vlmutgiq5jxfb4q",<br> "ap-sydney-1": "ocid1.image.oc1.ap-sydney-1.aaaaaaaazltimyhsp3vogaujtizcsyauvz3avzyqwdbf7l3jcujj76vzpcna",<br> "ap-tokyo-1": "ocid1.image.oc1.ap-tokyo-1.aaaaaaaahomava4u6ud4ztzysq3bnn6iktkyfvsthrvs4gjemkacfgpr53yq",<br> "ca-montreal-1": "ocid1.image.oc1.ca-montreal-1.aaaaaaaa25pkd4hksfm4ryuvj7eendqoo4hel4flpe2lmhlgs3rkw34sam2q",<br> "ca-toronto-1": "ocid1.image.oc1.ca-toronto-1.aaaaaaaafrhto7vi2lae4i5gki234znbj6i7iiodhychrxnmnzzkkscq45ua",<br> "eu-amsterdam-1": "ocid1.image.oc1.eu-amsterdam-1.aaaaaaaamwi2yxo5mbwbxydz5it4talwzkzfknywqcxuopi3suu575eu2rja",<br> "eu-frankfurt-1": "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaapg6sk4uypeope6rsjdqgemtp7v4wu45din3eub47vfpwdjoymadq",<br> "eu-madrid-1": "ocid1.image.oc1.eu-madrid-1.aaaaaaaaeoin77kq4jly4myzy7ap63iwmf6razdlftoyxvk7o2bcxnlyx56a",<br> "eu-marseille-1": "ocid1.image.oc1.eu-marseille-1.aaaaaaaai5mwzo3turcncrh5zk2zbewqa7sn6fh26v74hosswed2zjuquj2q",<br> "eu-milan-1": "ocid1.image.oc1.eu-milan-1.aaaaaaaasxksyjw24lp77uzemfqu2gtyledmksymjjom7m7d4koizg3goiza",<br> "eu-paris-1": "ocid1.image.oc1.eu-paris-1.aaaaaaaagbmz6kz2it6ft64dgf7kvoevdy53soejx5ucudd5zwoifcavyh5q",<br> "eu-stockholm-1": "ocid1.image.oc1.eu-stockholm-1.aaaaaaaast4rypafl2kho2g7nbqaec5tv3xdj4e5b6iuqdieurcionly2jna",<br> "eu-zurich-1": "ocid1.image.oc1.eu-zurich-1.aaaaaaaajoochdylix7hfdf3e3kfsynhaztz5rtl3gacz6ke6ugw56icmuxa",<br> "il-jerusalem-1": "ocid1.image.oc1.il-jerusalem-1.aaaaaaaaa2gspnrm6jdmxv4xqffjnvc5bu7xtmzptotcm2aygkvq3etwukkq",<br> "me-abudhabi-1": "ocid1.image.oc1.me-abudhabi-1.aaaaaaaaghp5mezfrznk7yx5mfu5d75evrltrukaehkxzfmwlwn3vd47pxna",<br> "me-dubai-1": "ocid1.image.oc1.me-dubai-1.aaaaaaaaxmqbxvp3tpa5rbp2swhfrmcbqok5vjhqhmqj6kmoy2c4j3olcgoq",<br> "me-jeddah-1": "ocid1.image.oc1.me-jeddah-1.aaaaaaaa3o55xjoxggxzo3ufvzzyfpa26dx5fehernulxoctdir45hazyylq",<br> "mx-monterrey-1": "ocid1.image.oc1.mx-monterrey-1.aaaaaaaaeasnsvrmjtnp2sa2emq2x63ixfdpq36mouj5qnz54x3yrsidiidq",<br> "mx-queretaro-1": "ocid1.image.oc1.mx-queretaro-1.aaaaaaaawiewa5mlk7ty5ycfeqr77islx5ziiqm434kc35spf3ntazc6qahq",<br> "sa-bogota-1": "ocid1.image.oc1.sa-bogota-1.aaaaaaaa4ogdfogwycxaxqhrngfd65rvahy4tcvjda2pgqggbfccjfpsvm6q",<br> "sa-santiago-1": "ocid1.image.oc1.sa-santiago-1.aaaaaaaanrhvodnakgpu7f44w6oytaltc7x6pn6zirgri3ckyubcemlhpmxq",<br> "sa-saopaulo-1": "ocid1.image.oc1.sa-saopaulo-1.aaaaaaaax4w5f5dsgxbsnu2c6iuf6wbwtfekrisjrzb6a77nlun75ap33vbq",<br> "sa-valparaiso-1": "ocid1.image.oc1.sa-valparaiso-1.aaaaaaaauwwidibcvn4kts3qmhy4qqxjuaa32fanvqlziv2vc2zyeaw4gmva",<br> "sa-vinhedo-1": "ocid1.image.oc1.sa-vinhedo-1.aaaaaaaalcyxi2by47atkj5pgmiwe3yiq4fe62i3nyhuqchgwmdtrfnxnhba",<br> "uk-cardiff-1": "ocid1.image.oc1.uk-cardiff-1.aaaaaaaalkuehgqztca5mog32zcnhfnwx4xyn5pymvtcog2xbpcqfppdxxfa",<br> "uk-london-1": "ocid1.image.oc1.uk-london-1.aaaaaaaadoqxyuecpc7z2oilbsorxypr4ssvkrvcsqnyoo5lciiel66wpsca",<br> "us-ashburn-1": "ocid1.image.oc1.iad.aaaaaaaagxazxgs5mz5xglwm5i7a7pdphiu7f3h2u6njatz6akisfxdgjmwq",<br> "us-chicago-1": "ocid1.image.oc1.us-chicago-1.aaaaaaaazn6piezti3khlsminniokag5cs7jiu3csqdiib3ex2jqv76qx3cq",<br> "us-phoenix-1": "ocid1.image.oc1.phx.aaaaaaaafuu7f34bb6gzgbkif6nz5vhibhop4zugjjma723uhc562mplgfza",<br> "us-sanjose-1": "ocid1.image.oc1.us-sanjose-1.aaaaaaaaapli23rbdkhfdejmayyckf7kfelei5ofn54jiunf7tcvpfsl4nuq"<br>}</pre> | no |
| <a name="input_instance_image_ocid"></a> [instance\_image\_ocid](#input\_instance\_image\_ocid) | The OCID of the image to use for the instance | `map(any)` | <pre>{<br> "af-johannesburg-1": "ocid1.image.oc1.af-johannesburg-1.aaaaaaaa7xnljvdm5kpk4m7zt7spaqyb3qjikwitnzpoebw7ggamy4exzv7a",<br> "ap-chuncheon-1": "ocid1.image.oc1.ap-chuncheon-1.aaaaaaaaqlcsenyb566zfbppypis3wnpdi5wzgvh6ni4njx6ni3b54h2f46a",<br> "ap-hyderabad-1": "ocid1.image.oc1.ap-hyderabad-1.aaaaaaaauqklehbg4utigurndarajxvpcrlokn7doqm2ctwplxqsni76wkza",<br> "ap-melbourne-1": "ocid1.image.oc1.ap-melbourne-1.aaaaaaaaxttpznd6kgln75wmdtalxmh374dc7vryk6ogxy4odv7ah5oh4coa",<br> "ap-mumbai-1": "ocid1.image.oc1.ap-mumbai-1.aaaaaaaaroeqq2dbas6jtuyszivuul4z2kec2fytvefcx4yn6nmxo2dmgo5a",<br> "ap-osaka-1": "ocid1.image.oc1.ap-osaka-1.aaaaaaaaslgmmzf52mm5i6fnyeudflxyfpdopd34vezjngyac7r4k4zvsxza",<br> "ap-seoul-1": "ocid1.image.oc1.ap-seoul-1.aaaaaaaamflo2tuozxfqsfe2ouyldnliqzzbzdnjgixjchsyl36zhz6ued5q",<br> "ap-singapore-1": "ocid1.image.oc1.ap-singapore-1.aaaaaaaazmtpusw5a62d2ohooa4q3nu3atfpv2hrldek72d3l5ikmghardsq",<br> "ap-sydney-1": "ocid1.image.oc1.ap-sydney-1.aaaaaaaaerkvnleaqrw5ugplx3k2el5l4pz4rr3exfbjna6ryj5fylocmnma",<br> "ap-tokyo-1": "ocid1.image.oc1.ap-tokyo-1.aaaaaaaal3hqdorzbtai6mc4bwggjshnog7u4i3xj7jz3v4xtimlmmkqy7ya",<br> "ca-montreal-1": "ocid1.image.oc1.ca-montreal-1.aaaaaaaaun5fmmveoxeebsdnbs3dp3llsfmf3ol657aa7d3bshvnacxa45eq",<br> "ca-toronto-1": "ocid1.image.oc1.ca-toronto-1.aaaaaaaauzynkrnddymm7346qpdzemhwqfigibq655ufdywbewpv2n4kmhtq",<br> "eu-amsterdam-1": "ocid1.image.oc1.eu-amsterdam-1.aaaaaaaal3y4fa7lj6deamse4m4ukkznfeoywb5h6r2y6qdwdqynh2rkx5tq",<br> "eu-frankfurt-1": "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaylcz7y7w6uolelzd6ruexuqkufkqqgg2nrr6xnvhtukysuolzv4q",<br> "eu-madrid-1": "ocid1.image.oc1.eu-madrid-1.aaaaaaaaw7wlmoprvzhu5ogyw6zjgdkclgyjidubfh2kzi27ns5tsl4agwcq",<br> "eu-marseille-1": "ocid1.image.oc1.eu-marseille-1.aaaaaaaao7fvqbnna7orz4xnnpv3vlitdnnmesnz4gk5pzgvfcxgmadmoc4q",<br> "eu-milan-1": "ocid1.image.oc1.eu-milan-1.aaaaaaaafofjducrv2pz7kj7thpbty2hyv37dtxce3x6cp5rwf2cngi7flva",<br> "eu-paris-1": "ocid1.image.oc1.eu-paris-1.aaaaaaaaqnoet4akmzpatmorbqio4srukhrd434xh6kg37jp6f4hdlt5mbiq",<br> "eu-stockholm-1": "ocid1.image.oc1.eu-stockholm-1.aaaaaaaavni5omi3qljq5umzlymbzxdczn3cmvgnfwb4tdfsls6qyehlv43q",<br> "eu-zurich-1": "ocid1.image.oc1.eu-zurich-1.aaaaaaaaswipxdoxr6pwu2mjk6lff5r4prkmuhufucw5kjaf7446ksx37d7q",<br> "il-jerusalem-1": "ocid1.image.oc1.il-jerusalem-1.aaaaaaaadzptbcjtrf7tx5sejgc7onb47u5ckrvakivyk6d2lueukm4uumsq",<br> "me-abudhabi-1": "ocid1.image.oc1.me-abudhabi-1.aaaaaaaaocrezb6kjxfj6ksp6xqpq2rvdxujxfk7sjrvcyjtavjs4eyzy4na",<br> "me-dubai-1": "ocid1.image.oc1.me-dubai-1.aaaaaaaaiiykp2iuznxgzrcrm2ln6o5nhfpfwuzlmwkvnmwgrzv747wfhowq",<br> "me-jeddah-1": "ocid1.image.oc1.me-jeddah-1.aaaaaaaaaicrqlmq7qfk7gh2dnw5ett3z5qqwzof7kzt7mwij6fmwzqhi22a",<br> "mx-monterrey-1": "ocid1.image.oc1.mx-monterrey-1.aaaaaaaaxqkk6akz7d2d356dk742kxq53kkfemewtlun6gj5jceeaddu2tkq",<br> "mx-queretaro-1": "ocid1.image.oc1.mx-queretaro-1.aaaaaaaakty7iicnprrzzdv7mr5onnbigbq6i4vaudobx3x6ya34uryrrmqa",<br> "sa-bogota-1": "ocid1.image.oc1.sa-bogota-1.aaaaaaaagpfqtybbtm5pikjd6qivrjd6d7p7y556rystirdayle6n3nxdzoa",<br> "sa-santiago-1": "ocid1.image.oc1.sa-santiago-1.aaaaaaaan4ex5fu662bmizpkpu3vxalty7j6waowogwmebiyijhiomin2yja",<br> "sa-saopaulo-1": "ocid1.image.oc1.sa-saopaulo-1.aaaaaaaaeor33zqzryd3smqgyg2arr4whsuobbtlwzxazovoto5vjnckaacq",<br> "sa-valparaiso-1": "ocid1.image.oc1.sa-valparaiso-1.aaaaaaaafj5y2dbizrqlr44ytyxukkejp3heuork3whgdec7h5sw3ckw7whq",<br> "sa-vinhedo-1": "ocid1.image.oc1.sa-vinhedo-1.aaaaaaaahwildebomq43h7xaufnbkgx6n2qvn5kihndcvkzmjy3vhwaqx5ka",<br> "uk-cardiff-1": "ocid1.image.oc1.uk-cardiff-1.aaaaaaaak55bg7dku2z3smbb3nczyj6jwmhlashfazcc3iemqmbwyjthic5a",<br> "uk-london-1": "ocid1.image.oc1.uk-london-1.aaaaaaaantzj7ujtr5wcojxtgc76oveoq5xcz7egczd56x67wivib3hfak3q",<br> "us-ashburn-1": "ocid1.image.oc1.iad.aaaaaaaai42i6avvfxqawj3bjl5uzhlyq5lqkqhbeg4lpo5corvwqgnvrloq",<br> "us-chicago-1": "ocid1.image.oc1.us-chicago-1.aaaaaaaazcw4u4fboyq5t33t7dj3jbwqvgy4jbkgxfmtxs2xxdnczshdhusa",<br> "us-phoenix-1": "ocid1.image.oc1.phx.aaaaaaaativnqm7keyzvvmetzp5cxlavfk5xyylt6w2epbjjjwmkv6xijnbq",<br> "us-sanjose-1": "ocid1.image.oc1.us-sanjose-1.aaaaaaaaouu2iwsejzxx3mqrczvmcx3az4jcnztjoysn3whf2oxamob22jqq"<br>}</pre> | no |
| <a name="input_instance_shape"></a> [instance\_shape](#input\_instance\_shape) | The shape of the instance | `string` | `"VM.Standard.A1.Flex"` | no |
| <a name="input_instance_shape_boot_volume_size_in_gbs"></a> [instance\_shape\_boot\_volume\_size\_in\_gbs](#input\_instance\_shape\_boot\_volume\_size\_in\_gbs) | The size of the boot volume in GBs | `string` | `"50"` | no |
| <a name="input_instance_shape_config_memory_in_gbs"></a> [instance\_shape\_config\_memory\_in\_gbs](#input\_instance\_shape\_config\_memory\_in\_gbs) | The amount of memory in GBs for the instance | `string` | `"24"` | no |
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ resource "oci_core_instance" "instance" {
ssh_authorized_keys = var.ssh_public_key
user_data = base64encode(templatefile("${path.module}/scripts/startup.sh", {
ADDITIONAL_SSH_PUB_KEY = var.additional_ssh_public_key,
INSTALL_RUNTIPI = var.install_runtipi,
}))
}

Expand Down
80 changes: 73 additions & 7 deletions scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg file vim -y
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" |
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

# Add user to docker group
sudo usermod -aG docker ubuntu
Expand All @@ -28,14 +26,82 @@ fi
MNT_DIR=/mnt/data

sudo mkdir -p $MNT_DIR
grep -q "$MNT_DIR" /etc/fstab || echo "/dev/sdb $MNT_DIR ext4 defaults,nofail 0 2" >>/etc/fstab
grep -q "$MNT_DIR" /etc/fstab || echo "/dev/sdb $MNT_DIR ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab

DISK_IS_FORMATTED=$(sudo file -s /dev/sdb | grep -c "ext4 filesystem data")

if [ "$DISK_IS_FORMATTED" -eq 0 ]; then
sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb
fi

sudo mount -a
FSTAB_ENTRY="/dev/sdb $MNT_DIR ext4 defaults,nofail 0 2"

# Verifica se l'entry esiste già in /etc/fstab
if ! grep -qF "$FSTAB_ENTRY" /etc/fstab; then
echo "$FSTAB_ENTRY" | sudo tee -a /etc/fstab
sudo mount -a
fi

# Tenta di montare il disco fino a 20 volte se non è già montato
MAX_ATTEMPTS=20
ATTEMPT=1
MOUNT_SUCCESS=false

while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
if mountpoint -q $MNT_DIR; then
MOUNT_SUCCESS=true
break
fi

# Se non è montato, prova a montare
sudo mount -a

# Attendere 1 secondo tra i tentativi
sleep 1
ATTEMPT=$((ATTEMPT + 1))
done

if [ "$MOUNT_SUCCESS" = true ]; then
echo "Disk mounted successfully after $ATTEMPT attempts." | sudo tee -a /var/log/mount.log
else
echo "Mounting disk failed after $MAX_ATTEMPTS attempts." | sudo tee -a /var/log/mount.log
exit 1
fi

# Install Runtipi
if [ ! -d $MNT_DIR/runtipi ] && [ "${INSTALL_RUNTIPI}" == "true" ]; then

sudo chown -R ubuntu:ubuntu $MNT_DIR
cd $MNT_DIR || exit
curl -L https://setup.runtipi.io | sudo bash

# Create docker-compose files configuration for Runtipi
RUNTIPI_CONFIG_FILE=$MNT_DIR/runtipi/user-config/tipi-compose.yml
if [ ! -f $RUNTIPI_CONFIG_FILE ]; then
sudo tee "$RUNTIPI_CONFIG_FILE" <<EOL >/dev/null
services:
runtipi-reverse-proxy:
networks:
tipi_main_network:
ipv4_address: 172.18.0.254
networks:
tipi_main_network:
driver: bridge
ipam:
config:
- subnet: 172.18.0.0/16
EOL
fi

# Create docker-compose files configuration for AdGuard
AD_GUARD_COMPOSE_FILE=$MNT_DIR/runtipi/user-config/adguard/docker-compose.yml
if [ ! -f $AD_GUARD_COMPOSE_FILE ]; then
sudo mkdir -p $MNT_DIR/runtipi/user-config/adguard
sudo tee "$AD_GUARD_COMPOSE_FILE" <<EOL >/dev/null
services:
adguard:
networks:
tipi_main_network:
ipv4_address: 172.18.0.253
EOL
fi
fi
Loading

0 comments on commit 8e368ad

Please sign in to comment.