Refactor everything
This commit is contained in:
parent
2e100d290f
commit
3f2e60becf
69 changed files with 366 additions and 281 deletions
|
|
@ -1,2 +0,0 @@
|
|||
skip_list:
|
||||
- var-naming[no-role-prefix]
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
hosts: local-dev
|
||||
roles:
|
||||
- common
|
||||
|
||||
- acme-dns
|
||||
- coder
|
||||
- faas
|
||||
|
|
|
|||
|
|
@ -2,5 +2,9 @@
|
|||
- name: Run roles for node001
|
||||
hosts: node001
|
||||
roles:
|
||||
- mailcow
|
||||
- minecraft-2
|
||||
- common
|
||||
|
||||
- role: mailcow
|
||||
tags: [mailcow, mail, communication]
|
||||
- role: minecraft_2
|
||||
tags: [minecraft-2, minecraft, games]
|
||||
|
|
|
|||
|
|
@ -2,24 +2,47 @@
|
|||
- name: Run roles for node002
|
||||
hosts: node002
|
||||
roles:
|
||||
- acme-dns
|
||||
- authentik
|
||||
- coder
|
||||
- faas
|
||||
- forgejo
|
||||
- forgejo-runner
|
||||
- harbor
|
||||
- healthcheck
|
||||
- homebox
|
||||
- influxdb
|
||||
- jellyfin
|
||||
- synapse
|
||||
- tandoor
|
||||
- telegraf
|
||||
- tinytinyrss
|
||||
- umami
|
||||
- uptime-kuma
|
||||
- watchtower
|
||||
- webdis
|
||||
- wiki-js
|
||||
- woodpecker
|
||||
- common
|
||||
|
||||
- role: acme_dns
|
||||
tags: [acme-dns, certificates]
|
||||
- role: authentik
|
||||
tags: [authentik, authentication]
|
||||
- role: coder
|
||||
tags: [coder, development]
|
||||
- role: faas
|
||||
tags: [faas]
|
||||
- role: forgejo
|
||||
tags: [forgejo, git, development]
|
||||
- role: forgejo_runner
|
||||
tags: [forgejo-runner, ci, development]
|
||||
- role: harbor
|
||||
tags: [harbor, registry, development]
|
||||
- role: healthcheck
|
||||
tags: [healthcheck, monitoring]
|
||||
- role: homebox
|
||||
tags: [homebox, inventory]
|
||||
- role: influxdb
|
||||
tags: [influxdb, sensors, monitoring]
|
||||
- role: jellyfin
|
||||
tags: [jellyfin, media]
|
||||
- role: synapse
|
||||
tags: [synapse, matrix, communication]
|
||||
- role: tandoor
|
||||
tags: [tandoor, recipes]
|
||||
- role: telegraf
|
||||
tags: [telegraf, monitoring]
|
||||
- role: tinytinyrss
|
||||
tags: [tinytinyrss, news]
|
||||
- role: umami
|
||||
tags: [umami, analytics]
|
||||
- role: uptime_kuma
|
||||
tags: [uptime-kuma, monitoring]
|
||||
- role: watchtower
|
||||
tags: [watchtower]
|
||||
- role: webdis
|
||||
tags: [webdis]
|
||||
- role: wiki_js
|
||||
tags: [wiki-js]
|
||||
- role: woodpecker
|
||||
tags: [woodpecker, ci, development]
|
||||
|
|
|
|||
|
|
@ -2,4 +2,7 @@
|
|||
- name: Run roles for node003
|
||||
hosts: node003
|
||||
roles:
|
||||
- minio
|
||||
- common
|
||||
|
||||
- role: minio
|
||||
tags: [minio, storage]
|
||||
|
|
|
|||
31
_ansible/roles/acme_dns/tasks/main.yml
Normal file
31
_ansible/roles/acme_dns/tasks/main.yml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
- name: Set common facts
|
||||
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
||||
|
||||
- name: Deploy {{ svc.name }}
|
||||
vars:
|
||||
svc: "{{ acme_dns_svc }}"
|
||||
env: "{{ acme_dns_env }}"
|
||||
compose: "{{ acme_dns_compose }}"
|
||||
block:
|
||||
- name: Import prepare tasks for common service
|
||||
ansible.builtin.import_tasks: tasks/prepare-common-service.yml
|
||||
|
||||
- name: Setting the service config path
|
||||
ansible.builtin.set_fact:
|
||||
config_path: "{{ (service_path, 'config') | path_join }}"
|
||||
|
||||
- name: Create a service-config directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ config_path }}"
|
||||
state: directory
|
||||
mode: "0700"
|
||||
|
||||
- name: Template config
|
||||
ansible.builtin.template:
|
||||
src: config.cfg.j2
|
||||
dest: "{{ (config_path, 'config.cfg') | path_join }}"
|
||||
mode: "0600"
|
||||
|
||||
- name: Import start tasks for common service
|
||||
ansible.builtin.import_tasks: tasks/start-common-service.yml
|
||||
31
_ansible/roles/acme_dns/templates/config.cfg.j2
Normal file
31
_ansible/roles/acme_dns/templates/config.cfg.j2
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
[general]
|
||||
listen = "0.0.0.0:53"
|
||||
protocol = "both"
|
||||
domain = "{{ svc.domain }}"
|
||||
nsname = "{{ svc.domain }}"
|
||||
nsadmin = "{{ svc.nsadmin }}"
|
||||
records = [
|
||||
"{{ svc.domain }}. A {{ svc.records.a }}",
|
||||
"{{ svc.domain }}. NS {{ svc.domain }}.",
|
||||
]
|
||||
debug = false
|
||||
|
||||
[database]
|
||||
engine = "postgres"
|
||||
connection = "postgres://{{ svc.db.user }}:{{ svc.db.pass }}@{{ svc.db.host }}/{{ svc.db.db }}"
|
||||
|
||||
[api]
|
||||
ip = "0.0.0.0"
|
||||
disable_registration = false
|
||||
port = "{{ svc.port }}"
|
||||
tls = "none"
|
||||
corsorigins = [
|
||||
"*"
|
||||
]
|
||||
use_header = true
|
||||
header_name = "X-Forwarded-For"
|
||||
|
||||
[logconfig]
|
||||
loglevel = "info"
|
||||
logtype = "stdout"
|
||||
logformat = "text"
|
||||
27
_ansible/roles/acme_dns/vars/main.yml
Normal file
27
_ansible/roles/acme_dns/vars/main.yml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
acme_dns_svc:
|
||||
domain: acme.serguzim.me
|
||||
name: acme-dns
|
||||
port: 80
|
||||
nsadmin: "{{ admin_email | regex_replace('@', '.') }}"
|
||||
records:
|
||||
a: "{{ ansible_facts.default_ipv4.address }}"
|
||||
db:
|
||||
host: "{{ postgres.host }}"
|
||||
port: "{{ postgres.port }}"
|
||||
user: "{{ vault_acmedns.db.user }}"
|
||||
pass: "{{ vault_acmedns.db.pass }}"
|
||||
db: acme_dns
|
||||
|
||||
acme_dns_compose:
|
||||
watchtower: true
|
||||
monitoring: true
|
||||
image: joohoi/acme-dns
|
||||
volumes:
|
||||
- ./config:/etc/acme-dns:ro
|
||||
file:
|
||||
services:
|
||||
app:
|
||||
ports:
|
||||
- "53:53"
|
||||
- 53:53/udp
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
---
|
||||
- name: Set common facts
|
||||
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
||||
|
||||
- name: Deploy {{ svc.name }}
|
||||
tags:
|
||||
- authentik
|
||||
- authentication
|
||||
vars:
|
||||
svc: "{{ authentik_svc }}"
|
||||
env: "{{ authentik_env }}"
|
||||
compose: "{{ authentik_compose }}"
|
||||
block:
|
||||
- name: Import tasks to deploy common service
|
||||
ansible.builtin.import_tasks: tasks/deploy-common-service.yml
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
svc:
|
||||
authentik_svc:
|
||||
domain: auth.serguzim.me
|
||||
name: authentik
|
||||
port: 9000
|
||||
|
|
@ -10,7 +10,7 @@ svc:
|
|||
user: "{{ vault_authentik.db.user }}"
|
||||
pass: "{{ vault_authentik.db.pass }}"
|
||||
|
||||
svc_env:
|
||||
authentik_env:
|
||||
AUTHENTIK_SECRET_KEY: "{{ vault_authentik.secret_key }}"
|
||||
|
||||
AUTHENTIK_EMAIL__HOST: "{{ mailer.host }}"
|
||||
|
|
@ -31,10 +31,9 @@ svc_env:
|
|||
AUTHENTIK_POSTGRESQL__USER: "{{ svc.db.user }}"
|
||||
AUTHENTIK_POSTGRESQL__PASSWORD: "{{ svc.db.pass }}"
|
||||
|
||||
compose:
|
||||
authentik_compose:
|
||||
watchtower: false
|
||||
image: ghcr.io/goauthentik/server:{{ svc.image_tag }}
|
||||
env: true
|
||||
file:
|
||||
services:
|
||||
app:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
---
|
||||
- name: Set common facts
|
||||
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
||||
|
||||
- name: Deploy {{ svc.name }}
|
||||
vars:
|
||||
svc: "{{ caddy_svc }}"
|
||||
env: "{{ caddy_env }}"
|
||||
compose: "{{ caddy_compose }}"
|
||||
- name: Deploy {{ svc.name }}
|
||||
tags:
|
||||
- caddy
|
||||
- reverse_proxy
|
||||
- webserver
|
||||
block:
|
||||
- name: Import tasks to deploy common service
|
||||
ansible.builtin.import_tasks: tasks/deploy-common-service.yml
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
---
|
||||
- name: Set common facts
|
||||
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
||||
|
||||
- name: Deploy {{ svc.name }}
|
||||
tags:
|
||||
- coder
|
||||
vars:
|
||||
svc: "{{ coder_svc }}"
|
||||
env: "{{ coder_env }}"
|
||||
compose: "{{ coder_compose }}"
|
||||
block:
|
||||
- name: Import tasks to deploy common service
|
||||
ansible.builtin.import_tasks: tasks/deploy-common-service.yml
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
svc:
|
||||
coder_svc:
|
||||
domain: coder.serguzim.me
|
||||
additional_domains:
|
||||
- "*.coder.serguzim.me"
|
||||
|
|
@ -12,7 +12,7 @@ svc:
|
|||
ssh_port: 22
|
||||
ssh_port_alt: 3022
|
||||
|
||||
svc_env:
|
||||
coder_env:
|
||||
CODER_ADDRESS: "0.0.0.0:7080"
|
||||
CODER_ACCESS_URL: https://{{ svc.domain }}
|
||||
CODER_WILDCARD_ACCESS_URL: "*.{{ svc.domain }}"
|
||||
|
|
@ -23,10 +23,9 @@ svc_env:
|
|||
CODER_OIDC_CLIENT_ID: "{{ vault_coder.oidc_client.id }}"
|
||||
CODER_OIDC_CLIENT_SECRET: "{{ vault_coder.oidc_client.secret }}"
|
||||
|
||||
compose:
|
||||
coder_compose:
|
||||
watchtower: true
|
||||
image: ghcr.io/coder/coder:latest
|
||||
env: true
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
file:
|
||||
|
|
|
|||
7
_ansible/roles/common/handlers/main.yml
Normal file
7
_ansible/roles/common/handlers/main.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
- name: Reload caddy
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose exec app sh -c "caddy validate --config /etc/caddy/Caddyfile && caddy reload --config /etc/caddy/Caddyfile"
|
||||
chdir: "{{ caddy_path }}"
|
||||
when: "'local-dev' != inventory_hostname"
|
||||
changed_when: true
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
---
|
||||
- name: Set common facts
|
||||
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
||||
|
||||
- name: Deploy {{ svc.name }}
|
||||
tags:
|
||||
- faas
|
||||
vars:
|
||||
svc: "{{ faas_svc }}"
|
||||
block:
|
||||
- name: Import tasks to template the site and functions for the reverse proxy
|
||||
ansible.builtin.import_tasks: tasks/steps/template-site-config.yml
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
svc:
|
||||
faas_svc:
|
||||
name: faas
|
||||
domain: faas.serguzim.me
|
||||
docker_host: host.docker.internal
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
---
|
||||
- name: Set common facts
|
||||
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
||||
|
||||
- name: Deploy {{ svc.name }}
|
||||
tags:
|
||||
- forgejo
|
||||
- git
|
||||
vars:
|
||||
svc: "{{ forgejo_svc }}"
|
||||
env: "{{ forgejo_env }}"
|
||||
compose: "{{ forgejo_compose }}"
|
||||
block:
|
||||
- name: Import tasks to deploy common service
|
||||
ansible.builtin.import_tasks: tasks/deploy-common-service.yml
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
svc:
|
||||
forgejo_svc:
|
||||
domain: git.serguzim.me
|
||||
name: forgejo
|
||||
port: 3000
|
||||
|
|
@ -10,7 +10,7 @@ svc:
|
|||
ssh_port: 22
|
||||
ssh_port_alt: 3022
|
||||
|
||||
svc_env:
|
||||
forgejo_env:
|
||||
FORGEJO__database__DB_TYPE: postgres
|
||||
FORGEJO__database__HOST: "{{ svc.db.host }}:{{ svc.db.port }}"
|
||||
FORGEJO__database__NAME: forgejo
|
||||
|
|
@ -78,10 +78,9 @@ svc_env:
|
|||
FORGEJO__other__SHOW_FOOTER_VERSION: true
|
||||
FORGEJO__other__SHOW_FOOTER_TEMPLATE_LOAD_TIME: false
|
||||
|
||||
compose:
|
||||
forgejo_compose:
|
||||
watchtower: true
|
||||
image: codeberg.org/forgejo/forgejo:1.21
|
||||
env: true
|
||||
volumes:
|
||||
- data:/data
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
|
|
|
|||
81
_ansible/roles/forgejo_runner/files/config.yml
Normal file
81
_ansible/roles/forgejo_runner/files/config.yml
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
log:
|
||||
# The level of logging, can be trace, debug, info, warn, error, fatal
|
||||
level: info
|
||||
|
||||
runner:
|
||||
# Where to store the registration result.
|
||||
file: /data/.runner
|
||||
# Execute how many tasks concurrently at the same time.
|
||||
capacity: 1
|
||||
# Extra environment variables to run jobs.
|
||||
#envs:
|
||||
# A_TEST_ENV_NAME_1: a_test_env_value_1
|
||||
# A_TEST_ENV_NAME_2: a_test_env_value_2
|
||||
# Extra environment variables to run jobs from a file.
|
||||
# It will be ignored if it's empty or the file doesn't exist.
|
||||
#env_file: .env
|
||||
# The timeout for a job to be finished.
|
||||
# Please note that the Forgejo instance also has a timeout (3h by default) for the job.
|
||||
# So the job could be stopped by the Forgejo instance if it's timeout is shorter than this.
|
||||
timeout: 3h
|
||||
# Whether skip verifying the TLS certificate of the Forgejo instance.
|
||||
insecure: false
|
||||
# The timeout for fetching the job from the Forgejo instance.
|
||||
fetch_timeout: 5s
|
||||
# The interval for fetching the job from the Forgejo instance.
|
||||
fetch_interval: 2s
|
||||
# The labels of a runner are used to determine which jobs the runner can run, and how to run them.
|
||||
# Like: ["macos-arm64:host", "ubuntu-latest:docker://node:16-bullseye", "ubuntu-22.04:docker://node:16-bullseye"]
|
||||
# If it's empty when registering, it will ask for inputting labels.
|
||||
# If it's empty when execute `deamon`, will use labels in `.runner` file.
|
||||
labels: []
|
||||
|
||||
cache:
|
||||
# Enable cache server to use actions/cache.
|
||||
enabled: true
|
||||
# The directory to store the cache data.
|
||||
# If it's empty, the cache data will be stored in $HOME/.cache/actcache.
|
||||
dir: ""
|
||||
# The host of the cache server.
|
||||
# It's not for the address to listen, but the address to connect from job containers.
|
||||
# So 0.0.0.0 is a bad choice, leave it empty to detect automatically.
|
||||
host: ""
|
||||
# The port of the cache server.
|
||||
# 0 means to use a random available port.
|
||||
port: 0
|
||||
|
||||
container:
|
||||
# Specifies the network to which the container will connect.
|
||||
# Could be host, bridge or the name of a custom network.
|
||||
# If it's empty, create a network automatically.
|
||||
network: ""
|
||||
# Whether to create networks with IPv6 enabled. Requires the Docker daemon to be set up accordingly.
|
||||
# Only takes effect if "network" is set to "".
|
||||
enable_ipv6: false
|
||||
# Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).
|
||||
privileged: false
|
||||
# And other options to be used when the container is started (eg, --add-host=my.forgejo.url:host-gateway).
|
||||
options:
|
||||
# The parent directory of a job's working directory.
|
||||
# If it's empty, /workspace will be used.
|
||||
workdir_parent:
|
||||
# Volumes (including bind mounts) can be mounted to containers. Glob syntax is supported, see https://github.com/gobwas/glob
|
||||
# You can specify multiple volumes. If the sequence is empty, no volumes can be mounted.
|
||||
# For example, if you only allow containers to mount the `data` volume and all the json files in `/src`, you should change the config to:
|
||||
# valid_volumes:
|
||||
# - data
|
||||
# - /src/*.json
|
||||
# If you want to allow any volume, please use the following configuration:
|
||||
# valid_volumes:
|
||||
# - '**'
|
||||
valid_volumes: []
|
||||
# overrides the docker client host with the specified one.
|
||||
# If it's empty, act_runner will find an available docker host automatically.
|
||||
# If it's "-", act_runner will find an available docker host automatically, but the docker host won't be mounted to the job containers and service containers.
|
||||
# If it's not empty or "-", the specified docker host will be used. An error will be returned if it doesn't work.
|
||||
docker_host: ""
|
||||
|
||||
host:
|
||||
# The parent directory of a job's working directory.
|
||||
# If it's empty, $HOME/.cache/act/ will be used.
|
||||
workdir_parent:
|
||||
42
_ansible/roles/forgejo_runner/tasks/main.yml
Normal file
42
_ansible/roles/forgejo_runner/tasks/main.yml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
- name: Set common facts
|
||||
ansible.builtin.import_tasks: tasks/set-default-facts.yml
|
||||
|
||||
- name: Deploy {{ svc.name }}
|
||||
vars:
|
||||
svc: "{{ forgejo_runner_svc }}"
|
||||
env: "{{ forgejo_runner_env }}"
|
||||
compose: "{{ forgejo_runner_compose }}"
|
||||
block:
|
||||
- name: Import tasks to create service directory
|
||||
ansible.builtin.import_tasks: tasks/steps/create-service-directory.yml
|
||||
- name: Import tasks to template docker compose file
|
||||
ansible.builtin.import_tasks: tasks/steps/template-docker-compose.yml
|
||||
|
||||
- name: Copy the config
|
||||
ansible.builtin.copy:
|
||||
src: config.yml
|
||||
dest: "{{ (service_path, 'config.yml') | path_join }}"
|
||||
mode: "0755"
|
||||
|
||||
- name: Check if service.env already exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ (service_path, 'service.env') | path_join }}"
|
||||
register: env_file
|
||||
|
||||
- name: Import tasks to prompt for the registration token
|
||||
ansible.builtin.import_tasks: tasks/prompt-registration-token.yml
|
||||
when: not env_file.stat.exists or force_forgejo_runner_registration | default(False)
|
||||
|
||||
- name: Import tasks create a service.env file
|
||||
ansible.builtin.import_tasks: tasks/steps/template-service-env.yml
|
||||
- name: Import start tasks for common service
|
||||
ansible.builtin.import_tasks: tasks/start-common-service.yml
|
||||
|
||||
- name: Register runner
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose run --rm -it app sh -c
|
||||
'forgejo-runner register --no-interactive --token ${FORGEJO_RUNNER_REGISTRATION_TOKEN} --instance ${FORGEJO_INSTANCE_URL}'
|
||||
chdir: "{{ service_path }}"
|
||||
when: not env_file.stat.exists or force_forgejo_runner_registration | default(False)
|
||||
changed_when: true # "when" checks enough. We are sure to change something here.
|
||||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue