Skip to content

Commit 5019bae

Browse files
authored
submodules #1
submodules
2 parents 45ed950 + 51806eb commit 5019bae

File tree

100 files changed

+2584
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2584
-275
lines changed

.github/workflows/docs.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
9+
jobs:
10+
build-deploy:
11+
name: Build and deploy docs
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
22+
- name: Cache dependencies
23+
uses: actions/cache@v2
24+
with:
25+
path: ~/.cache/pip
26+
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
27+
restore-keys: |
28+
${{ runner.os }}-pip-
29+
${{ runner.os }}-
30+
31+
- name: Install dependencies
32+
working-directory: docs
33+
run: make install
34+
35+
- name: Build and deploy to GitHub Pages
36+
working-directory: docs
37+
run: make deploy

.github/workflows/terrascan.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: terrascan
2+
on:
3+
push:
4+
branches: [ master ]
5+
pull_request:
6+
7+
jobs:
8+
tfsec:
9+
runs-on: ${{ matrix.os }}
10+
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest]
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
name: Checkout source code
18+
19+
- name: Run Terrascan
20+
id: terrascan
21+
uses: tenable/terrascan-action@main
22+
with:
23+
iac_type: 'terraform'
24+
iac_version: 'v14'
25+
policy_type: 'aws'
26+
only_warn: true
27+
sarif_upload: true
28+
29+
- uses: github/codeql-action/upload-sarif@v3
30+
if: github.ref == 'refs/heads/master'
31+
with:
32+
sarif_file: terrascan.sarif

.github/workflows/tfsec.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: tfsec
2+
on:
3+
push:
4+
branches: [ master ]
5+
pull_request:
6+
7+
jobs:
8+
tflint:
9+
runs-on: ${{ matrix.os }}
10+
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest]
14+
15+
steps:
16+
- uses: actions/setup-go@v5
17+
name: Setup Go
18+
with:
19+
go-version: '1.22.2'
20+
21+
- uses: actions/checkout@v4
22+
name: Checkout source code
23+
24+
- name: Install dependencies
25+
run: |
26+
go install github.com/aquasecurity/tfsec/cmd/tfsec@latest
27+
28+
- name: Run tfsec
29+
run: tfsec --soft-fail --format sarif --out tfsec.sarif
30+
31+
- uses: github/codeql-action/upload-sarif@v3
32+
if: github.ref == 'refs/heads/master'
33+
with:
34+
sarif_file: tfsec.sarif

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ terraform.rc
3838
.terraform*
3939

4040
logs
41+
.ssh/
42+
dev/

README.md

+9-95
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,23 @@
22

33
Infra for utilizing Hetzner low-cost VPS and Docker containers, wrapped in [Coolify](https://coolify.io) as an all-in-one PaaS, to self-host your own applications, databases, or services.
44

5-
<p align="center">
6-
<img src="public/01_infra-diagram.png" width="600" alt="Infrastructure Diagram">
7-
</p>
8-
5+
![infra_diagram](./docs/docs/public/01_infra_diagram.svg)
96

107
## Prerequisites
118

129
Before you begin, ensure you have the following:
1310

14-
- [Hetzner](https://hetzner.cloud/?ref=Ix9xCKNxJriM) Cloud account
11+
- [Hetzner Cloud account](https://hetzner.cloud/?ref=Ix9xCKNxJriM)
1512
- [Terraform](https://www.terraform.io/downloads.html)
1613
- [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)
17-
18-
## Deployment Steps
19-
20-
### 1. Generate Hetzner API Token
21-
22-
Create new project in Hetzner [console](https://console.hetzner.cloud/projects)
23-
24-
Obtain API token from Hetzner console that will be used by Terraform to interact with the platform.
25-
Navigate to your project and click on SECURITY > API TOKENS > GENERATE API (give read/write access)
26-
27-
Paste API token in the `.auto.tfvars`. This will overwrite default values in `variables.tf` file.
28-
29-
### 2. Configure infrastructure
30-
31-
Choose how many servers you want to have in your cluster. For a minimum, you can create and deploy on your controller, but this is not recommended. Read more about possible configurations and how to use Coolify in the official docs. There is also the possibility to use workers in swarm mode, and you can put a load balancer in front of your cluster. For now, you need to configure lb yourself, but in future Coolify releases, this will be automated. This can get complex as you want to be.
32-
33-
```shell
34-
hcloud_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
35-
36-
location_list = ["fsn1", "nbg1", "hel1"]
37-
instances_coolify_controler = "1"
38-
instances_coolify_worker = "2"
39-
server_type_coolify_controler = "cx21"
40-
server_type_coolify_worker = "cx21"
41-
os_type = "debian-12"
42-
public_net = true
43-
```
44-
45-
### 3. Initialize and Apply Terraform
46-
47-
Initialize Terraform and apply the configuration:
48-
49-
```shell
50-
cd hetzner-infra
51-
terraform init --upgrade
52-
terraform validate
53-
terraform apply
54-
```
55-
56-
### 4. Define hosts and run ansible playbook
57-
58-
In your `inventory/hosts` file, specify the IP addresses of your newly created servers obtained from Terraform output, or alternatively, verify them in the Hetzner Cloud console
59-
60-
```shell
61-
[coolify-controler]
62-
49.13.73.3
63-
64-
[coolify-worker]
65-
91.107.208.20
66-
128.140.0.112
67-
```
68-
69-
Run playbook:
70-
```shell
71-
cd ansible
72-
ansible-playbook playbooks/playbook_install_coolify.yml
73-
```
74-
Ansible playbook automates the installation of Coolify on controller hosts. It configures common dependencies and enhances system security on both controller and workers hosts:
75-
76-
- Updates package lists and upgrades all packages to ensure the system is up to date.
77-
- Installs necessary dependencies including UFW and Fail2Ban for enhancing system security.
78-
- Sets up UFW to allow specific incoming traffic and enables it for added security.
79-
- Configures Fail2Ban to prevent unauthorized access attempts by banning malicious IP addresses.
80-
- Implements SSH hardening measures to secure remote access to the system.
81-
- Installs Coolify on controller hosts and configures it to listen on specific ports.
82-
- Configures worker hosts to allow incoming traffic on specified ports required for Coolify operation
83-
.
84-
### 5. Open UI:
85-
86-
When Ansible finishes, Coolify's UI will be available at:
87-
88-
```shell
89-
CONTROLER_SERVER_IP:8000
90-
```
91-
92-
Now is the time to configure Coolify. Add your private key that Terraform created, use workers private IPs and add the workers to your cluster. Consult the [documentation](https://coolify.io/docs/) for futher steps.
93-
94-
## 6. SSH into server
95-
96-
Terraform creates SSH private and public keys that are added to Hetzner and servers. They are also used by Ansible. Be careful with keys, you don't want to lose them.
97-
98-
If needed, you can ssh into the server with the following command:
9914

100-
```shell
101-
ssh root@<server-ip> -i ~/.ssh/self_hosted_hetzner_key.pem
102-
```
15+
This second iteration offers more granular control over the infrastructure that is created.
16+
It abstracts components into modules that can be reused and imported as source.
10317

104-
### 7. Destroy infrastructure
18+
Benefits include the ability to change infrastructure components in place, targeting specific components.
19+
For example, in earlier iterations, you might not have known which server would be destroyed.
10520

106-
To destroy the infrastructure run the following command:
21+
Old code is available in the [old_config branch](https://github.com/Ujstor/self-hosting-infrastructure-cluster/tree/old_config)
10722

108-
```shell
109-
terraform destroy
110-
```
23+
***Check [docs](ujstor.github.io/self-hosting-infrastructure-cluster) for more detailed info.***
24+
Docs are work in progress.

ansible/ansible.cfg

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[defaults]
22
inventory = inventory/hosts
33

4-
private_key_file = ~/.ssh/self_hosted_hetzner_key.pem
4+
private_key_file = ../prod/.ssh/coolify_cluster_prod_key.pem
55
host_key_checking = False
6-
remote_user = root
6+
remote_user = root
7+
8+

ansible/inventory/hosts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[coolify-controler]
2-
49.13.73.3
2+
168.119.50.26
33

44
[coolify-worker]
5-
91.107.208.20
6-
128.140.0.112
5+
195.201.34.199
6+
37.27.11.186
7+
49.12.97.239
8+

ansible/playbooks/playbook_install_coolify.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
rule: allow
4545
port: "{{ item }}"
4646
loop:
47-
- 6001
47+
- 6001

ansible/playbooks/roles/common/tasks/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ansible.posix.authorized_key:
1212
user: root
1313
state: present
14-
key: "{{ lookup('file', '~/.ssh/self_hosted_hetzner_key.pub') }}"
14+
key: "{{ lookup('file', '../../../../../prod/.ssh/coolify_cluster_prod_key.pub') }}"
1515

1616
- name: Install required packages
1717
ansible.builtin.package:

docs/Makefile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.PHONY: docs
2+
3+
default: install
4+
5+
all: install build
6+
7+
8+
h help:
9+
@grep '^[a-z]' Makefile
10+
11+
12+
install:
13+
pip install pip --upgrade
14+
pip install -r requirements.txt
15+
16+
upgrade:
17+
pip install pip --upgrade
18+
pip install -r requirements.txt --upgrade
19+
20+
21+
s serve:
22+
mkdocs serve --strict
23+
24+
25+
b build:
26+
mkdocs build --strict
27+
28+
d deploy:
29+
mkdocs gh-deploy --strict --force

docs/custom_theme/main.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% extends "base.html" %}
2+
3+
{% block libs %}
4+
{{ super() }}
5+
<script defer data-domain="ujstor.github.io/self-hosting-infrastructure-cluster" src="https://analytics.ujstor.com/js/script.js"></script>
6+
{% endblock %}

docs/docs/index.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Self hosting infrastructure cluster
2+
3+
Infra for utilizing Hetzner low-cost VPS and Docker containers, wrapped in [Coolify](https://coolify.io) as an all-in-one PaaS, to self-host your own applications, databases, or services.
4+
5+
![diagram](./public/01_infra_diagram.svg)
6+
7+
## Prerequisites
8+
9+
Before you begin, ensure you have the following:
10+
11+
- [Hetzner Cloud account](https://hetzner.cloud/?ref=Ix9xCKNxJriM)
12+
- [Terraform](https://www.terraform.io/downloads.html)
13+
- [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html)

0 commit comments

Comments
 (0)