This commit is contained in:
jakubknczny 2021-12-01 12:00:43 +01:00
parent 82ea598428
commit ecde2afa60
8 changed files with 144 additions and 24 deletions

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM hashicorp/terraform:latest
COPY init-db init-db
COPY init-server init-server
COPY main.tf main.tf
ENTRYPOINT terraform init && terraform apply -var="token=${token}" -auto-approve

View File

View File

@ -1,18 +0,0 @@
#cloud-config
users:
- name: kk
groups: users, admin
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDlRnEXhUu2ObVokroMosX0k0xIdpFTdo2d15MmJYnTBPzDtAl7H1JLt5uthhsvfVYNjxncHn6EoSom+yhH3NhZiapunqtqLgd1QXpBdp3nWiyXFT9OPZRnZaeZxho/kFj5w8EAzPejQOHiqmqzI86yMM0sIPC4yOOBxltryevO8YhFRz8QVcU3RAQakUKa0mmewbrF+wJp/FpoYICSzd3plTHcBs7L6uUqz49y3Ut+Lwaf5/YQ7Zc+oXWLIzVxlR4nneWB8ltcOEscRaRE+oChsziZ+5GgG5yeD7TvgOBlAUQxnk02gA1A2yiiCFuTSew2DriKZoSqDa28oyKuFLid2NOJn9V+bMREWkHa1lk7i8RUz6H3ugqv0TLHv0+grbKDrCf8yWrRp+EVb4Zb3WOdoROkPmn01lHKrsNMOuBBcFgmMKDl6+AQ4vtwAFl6q9GyTMnnkTgK1fJlzsfQPXCcABELVWbodFsvHfJdggEVTo39T4p3jReip/QdzAIvuYbRLDwi33M8M3fyLhaEAMxHuO6DQ5ZHEz+cqL9EP700nUsfi4Rh5wG0LdiCFmGrUr85/K1ni0N2cb4RT6PhxAuM6bUUvYJykhT5a5NiyR/ytjR5HsW0S+V+dli4IZkr3+uVngWEUCB4Tai9VFlzYkGTYCSNwLEI3rZ3KtLZ480nxw== jakkon6@st.amu.edu.pl
packages:
- fail2ban
- ufw
package_update: true
package_upgrade: true
runcmd:
- "wget https://git.wmi.amu.edu.pl/s470607/code-server-test/raw/branch/master/setup.sh"
- "chmod +x setup.sh"
- "bash setup.sh"
- "reboot"

36
cloud-init-db Normal file
View File

@ -0,0 +1,36 @@
#cloud-config
packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
write_files:
- path: /root/docker-compose.yml
content: |
version: '3.9'
services:
db:
image: mysql:8
restart: always
ports:
- "10.0.1.2:3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=gitea
- MYSQL_DATABASE=gitea
volumes:
- ./mysql:/var/lib/mysql
runcmd:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- apt-get update -y
- apt-get install -y docker-ce docker-ce-cli containerd.io
- curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- systemctl start docker
- systemctl enable docker
- cd /root/ && docker-compose up -d

44
cloud-init-sv Normal file
View File

@ -0,0 +1,44 @@
#cloud-config
packages:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
write_files:
- path: /root/docker-compose.yml
content: |
version: '3.9'
services:
server:
image: gitea/gitea:1.15.6
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=10.0.1.2:3306
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=gitea
restart: always
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"
runcmd:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- apt-get update -y
- apt-get install -y docker-ce docker-ce-cli containerd.io
- curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- systemctl start docker
- systemctl enable docker
- cd /root/ && docker-compose up -d

4
deploy.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
docker build -t gitea .
docker run -e token="$1" gitea

55
main.tf Normal file
View File

@ -0,0 +1,55 @@
terraform {
required_providers {
hc = {
source = "hetznercloud/hcloud"
version = "1.32.1"
}
}
}
variable "token" {
type = string
}
provider "hc" {
token = var.token
}
resource "hc_sv" "ubuntu" {
name = "jk-test1"
image = "ubuntu-20.04"
server_type = "cpx11"
network {
network_id = hc_network.network.id
}
user_data = file("cloud-init-sv")
depends_on = [
hc_sv.mysql
]
}
resource "hc_sv" "mysql" {
name = "jk-test2"
image = "ubuntu-20.04"
server_type = "cpx11"
user_data = file("cloud-init-db")
network {
network_id = hc_network.network.id
}
}
resource "hc_network" "network" {
name = "jk-test3"
ip_range = "10.0.1.0/24"
}
resource "hc_network_subnet" "subnet" {
network_id = hc_network.network.id
type = "cloud"
network_zone = "eu-central"
ip_range = "10.0.1.0/24"
}

View File

@ -1,6 +0,0 @@
#!/bin/bash
curl -fOL https://github.com/cdr/code-server/releases/download/v3.12.0/code-server_3.12.0_amd64.deb
dpkg -i code-server_3.12.0_amd64.deb
systemctl enable --now code-server@kk