2 Commits

Author SHA1 Message Date
d5bad0b1cc testing 2023-12-08 20:06:48 -05:00
91de9d05ac testing 2023-12-05 21:55:52 -05:00
13 changed files with 177 additions and 177 deletions

View File

@@ -8,17 +8,11 @@ on:
jobs: jobs:
homelab-ci: homelab-ci:
runs-on: macos-13 runs-on: macos-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
with:
detached: true
limit-access-to-actor: true
- name: Cache Vagrant boxes - name: Cache Vagrant boxes
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
@@ -27,23 +21,19 @@ jobs:
restore-keys: | restore-keys: |
${{ runner.os }}-vagrant- ${{ runner.os }}-vagrant-
- name: Install Tools
run: brew install nmap tree
- name: Install VirtualBox
run: brew install --cask virtualbox
- name: Install Vagrant
run: brew install --cask vagrant
- name: Install Ansible - name: Install Ansible
run: brew install ansible run: brew install ansible@7
- name: Software Versions - name: Software Versions
run: | run: |
printf "VirtualBox "; vboxmanage --version printf "VirtualBox "
vboxmanage --version
vagrant --version vagrant --version
export PATH="/usr/local/opt/ansible@7/bin:$PATH"
ansible --version ansible --version
- name: Vagrant Up with Dockerbox Playbook - name: Vagrant Up with Dockerbox Playbook
run: ./scripts/github-vagrant.sh run: |
export PATH="/usr/local/opt/ansible@7/bin:$PATH"
PLAYBOOK=dockerbox vagrant up
vagrant ssh -c "docker ps"

3
Vagrantfile vendored
View File

@@ -36,7 +36,6 @@ Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |vbox| config.vm.provider :virtualbox do |vbox|
vbox.cpus = VAGRANT_CPUS vbox.cpus = VAGRANT_CPUS
vbox.memory = VAGRANT_MEM vbox.memory = VAGRANT_MEM
vbox.gui = true
end end
# Provision with Ansible # Provision with Ansible
@@ -44,6 +43,6 @@ Vagrant.configure("2") do |config|
ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles" ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles"
ansible.compatibility_mode = "2.0" ansible.compatibility_mode = "2.0"
ansible.playbook = "dev/" + PLAYBOOK + ".yml" ansible.playbook = "dev/" + PLAYBOOK + ".yml"
ansible.raw_arguments = ["--diff", "-vvvv"] ansible.raw_arguments = ["--diff"]
end end
end end

View File

@@ -5,8 +5,10 @@
- host_vars/dockerbox.yml - host_vars/dockerbox.yml
roles: roles:
- base - base
- docker
- mariadb
- traefik
- nextcloud
- proxy - proxy
- mariadb
- docker
# - nextcloud
# - jenkins
# - prometheus
# - nginx

View File

@@ -10,6 +10,9 @@ root_gpgkeys:
# proxy # proxy
proxy: proxy:
servers: servers:
# This exposes over 0.0.0.0:443 instead of 127.0.0.1:8443
#- domain: traefik.local.krislamo.org
# proxy_pass: https://127.0.0.1:8443
- domain: cloud.local.krislamo.org - domain: cloud.local.krislamo.org
proxy_pass: http://127.0.0.1:8000 proxy_pass: http://127.0.0.1:8000
@@ -23,26 +26,45 @@ docker_compose_deploy:
# Traefik # Traefik
- name: traefik - name: traefik
url: https://github.com/krislamo/traefik url: https://github.com/krislamo/traefik
version: d62bd06b37ecf0993962b0449a9d708373f9e381 version: e03268af4cf942c47cba66c2112628dbcad1b756
path: docker-compose.web.yml
enabled: true enabled: true
accept_newhostkey: true # Consider verifying manually instead accept_newhostkey: true
trusted_keys: trusted_keys:
- FBF673CEEC030F8AECA814E73EDA9C3441EDA925 - FBF673CEEC030F8AECA814E73EDA9C3441EDA925
env: env:
DASHBOARD: true ENABLE: true
# Nextcloud # Nextcloud
- name: nextcloud - name: nextcloud
url: https://github.com/krislamo/nextcloud url: https://git.krislamo.org/kris/nextcloud
version: fe6d349749f178e91ae7ff726d557f48ebf84356 version: a2e38cec703839211e11dc8347b4cdd62fa6f24d
enabled: true
env: env:
DATA: ./data DATA: ./data
# traefik
traefik:
ENABLE: true
# nextcloud # nextcloud
nextcloud: #nextcloud_version: stable
DOMAIN: cloud.local.krislamo.org #nextcloud_admin: admin
DB_PASSWD: password #nextcloud_pass: password
ADMIN_PASSWD: password #nextcloud_domain: cloud.local.krislamo.org
#nextcloud_dbversion: latest
#nextcloud_dbpass: password
# jenkins
jenkins_version: lts
jenkins_domain: jenkins.local.krislamo.org
# prometheus (includes grafana)
prom_version: latest
prom_domain: prom.local.krislamo.org
grafana_version: latest
grafana_domain: grafana.local.krislamo.org
prom_targets: "['10.0.2.15:9100']"
# nginx
nginx_domain: nginx.local.krislamo.org
nginx_name: staticsite
nginx_repo_url: https://git.krislamo.org/kris/example-website/
nginx_auth: admin:$apr1$T1l.BCFz$Jyg8msXYEAUi3LLH39I9d1 # admin:admin
nginx_version: latest

View File

@@ -22,7 +22,7 @@
# Root check # Root check
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
echo "[ERROR]: Please run this script as root" echo "[ERROR]: Please run script as root"
exit 1 exit 1
fi fi
@@ -41,8 +41,8 @@ function ssh_connect {
printf "[INFO]: Starting new vagrant SSH tunnel on PID " printf "[INFO]: Starting new vagrant SSH tunnel on PID "
sudo -u "$USER" ssh -fNT -i "$PRIVATE_KEY" \ sudo -u "$USER" ssh -fNT -i "$PRIVATE_KEY" \
-L 22:localhost:22 \ -L 22:localhost:22 \
-L 80:"$HOST_IP":80 \ -L 80:localhost:80 \
-L 443:"$HOST_IP":443 \ -L 443:localhost:443 \
-L 8443:localhost:8443 \ -L 8443:localhost:8443 \
-o UserKnownHostsFile=/dev/null \ -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \ -o StrictHostKeyChecking=no \
@@ -51,7 +51,7 @@ function ssh_connect {
pgrep -f "$MATCH_PATTERN" pgrep -f "$MATCH_PATTERN"
;; ;;
*) *)
echo "[INFO]: Declined to start a new vagrant SSH tunnel" echo "[INFO]: Delined to start a new vagrant SSH tunnel"
exit 0 exit 0
;; ;;
esac esac
@@ -64,7 +64,7 @@ PRIVATE_KEY="$(find .vagrant -name "private_key" 2>/dev/null | sort)"
if [ "$(echo "$PRIVATE_KEY" | wc -l)" -gt 1 ]; then if [ "$(echo "$PRIVATE_KEY" | wc -l)" -gt 1 ]; then
while IFS= read -r KEYFILE; do while IFS= read -r KEYFILE; do
if ! ssh-keygen -l -f "$KEYFILE" &>/dev/null; then if ! ssh-keygen -l -f "$KEYFILE" &>/dev/null; then
echo "[ERROR]: The SSH key '$KEYFILE' is not valid. Are your virtual machines running?" echo "[ERROR]: The SSH key '$KEYFILE' is not valid. Is your virtual machines running?"
exit 1 exit 1
fi fi
echo "[CHECK]: Valid key at $KEYFILE" echo "[CHECK]: Valid key at $KEYFILE"
@@ -78,7 +78,7 @@ else
fi fi
# Grab first IP or use whatever HOST_IP_FIELD is set to and check that the guest is up # Grab first IP or use whatever HOST_IP_FIELD is set to and check that the guest is up
HOST_IP="$(sudo -u "$SUDO_USER" vagrant ssh -c "hostname -I | cut -d' ' -f${HOST_IP_FIELD:-1}" "${1:-default}" 2>/dev/null)" HOST_IP="$(vagrant ssh -c "hostname -I | cut -d' ' -f${HOST_IP_FIELD:-1}" "${1:-default}" 2>/dev/null)"
if [ -z "$HOST_IP" ]; then if [ -z "$HOST_IP" ]; then
echo "[ERROR]: Failed to find ${1:-default}'s IP" echo "[ERROR]: Failed to find ${1:-default}'s IP"
exit 1 exit 1

View File

@@ -17,10 +17,6 @@
line: "bind-address = {{ ansible_facts.docker0.ipv4.address }}" line: "bind-address = {{ ansible_facts.docker0.ipv4.address }}"
notify: restart_mariadb notify: restart_mariadb
- name: Flush handlers to ensure MariaDB restarts immediately
ansible.builtin.meta: flush_handlers
tags: restart_mariadb
- name: Allow database connections from Docker - name: Allow database connections from Docker
community.general.ufw: community.general.ufw:
rule: allow rule: allow

View File

@@ -1 +1,11 @@
nextcloud_name: nextcloud # container names
nextcloud_container: nextcloud
nextcloud_dbcontainer: "{{ nextcloud_container }}-db"
# database settings
nextcloud_dbname: "{{ nextcloud_container }}"
nextcloud_dbuser: "{{ nextcloud_dbname }}"
# host mounts
nextcloud_root: "/opt/{{ nextcloud_container }}/public_html"
nextcloud_dbroot: "/opt/{{ nextcloud_container }}/database"

View File

@@ -1,25 +0,0 @@
- name: Set Nextcloud's Trusted Proxy
ansible.builtin.command: >
docker exec --user www-data "{{ nextcloud_name }}"
php occ config:system:set trusted_proxies 0 --value="{{ traefik_name }}"
register: nextcloud_trusted_proxy
changed_when: "nextcloud_trusted_proxy.stdout == 'System config value trusted_proxies => 0 set to string ' ~ traefik_name"
listen: install_nextcloud
- name: Set Nextcloud's Trusted Domain
ansible.builtin.command: >
docker exec --user www-data "{{ nextcloud_name }}"
php occ config:system:set trusted_domains 0 --value="{{ nextcloud.DOMAIN }}"
register: nextcloud_trusted_domains
changed_when: "nextcloud_trusted_domains.stdout == 'System config value trusted_domains => 0 set to string ' ~ nextcloud.DOMAIN"
listen: install_nextcloud
- name: Preform Nextcloud database maintenance
ansible.builtin.command: >
docker exec --user www-data "{{ nextcloud_name }}" {{ item }}
loop:
- "php occ maintenance:mode --on"
- "php occ db:add-missing-indices"
- "php occ db:convert-filecache-bigint"
- "php occ maintenance:mode --off"
listen: install_nextcloud

View File

@@ -1,62 +1,109 @@
- name: Install MySQL module for Ansible - name: Create Nextcloud network
ansible.builtin.apt: community.general.docker_network:
name: python3-pymysql name: "{{ nextcloud_container }}"
state: present
- name: Create Nextcloud database - name: Start Nextcloud's database container
community.mysql.mysql_db: community.general.docker_container:
name: "{{ nextcloud.DB_NAME | default('nextcloud') }}" name: "{{ nextcloud_dbcontainer }}"
state: present image: mariadb:{{ nextcloud_dbversion }}
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Create Nextcloud database user
community.mysql.mysql_user:
name: "{{ nextcloud.DB_USER | default('nextcloud') }}"
password: "{{ nextcloud.DB_PASSWD }}"
host: '%'
state: present
priv: "{{ nextcloud.DB_NAME | default('nextcloud') }}.*:ALL"
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Start Nextcloud service and enable on boot
ansible.builtin.service:
name: "{{ docker_compose_service }}@{{ nextcloud_name }}"
state: started state: started
enabled: true restart_policy: always
when: nextcloud.ENABLE | default('false') volumes: "{{ nextcloud_dbroot }}:/var/lib/mysql"
networks_cli_compatible: true
networks:
- name: "{{ nextcloud_container }}"
env:
MYSQL_RANDOM_ROOT_PASSWORD: "true"
MYSQL_DATABASE: "{{ nextcloud_dbname }}"
MYSQL_USER: "{{ nextcloud_dbuser }}"
MYSQL_PASSWORD: "{{ nextcloud_dbpass }}"
- name: Start Nextcloud container
community.general.docker_container:
name: "{{ nextcloud_container }}"
image: nextcloud:{{ nextcloud_version }}
state: started
restart_policy: always
volumes: "{{ nextcloud_root }}:/var/www/html"
networks_cli_compatible: true
networks:
- name: "{{ nextcloud_container }}"
- name: traefik
env:
PHP_MEMORY_LIMIT: 1024M
labels:
traefik.http.routers.nextcloud.rule: "Host(`{{ nextcloud_domain }}`)"
traefik.http.routers.nextcloud.entrypoints: websecure
traefik.http.routers.nextcloud.tls.certresolver: letsencrypt
traefik.http.routers.nextcloud.middlewares: "securehttps@file,nextcloud-webdav"
traefik.http.middlewares.nextcloud-webdav.redirectregex.regex: "https://(.*)/.well-known/(card|cal)dav"
traefik.http.middlewares.nextcloud-webdav.redirectregex.replacement: "https://${1}/remote.php/dav/"
traefik.http.middlewares.nextcloud-webdav.redirectregex.permanent: "true"
traefik.docker.network: traefik
traefik.enable: "true"
- name: Grab Nextcloud database container information
community.general.docker_container_info:
name: "{{ nextcloud_dbcontainer }}"
register: nextcloud_dbinfo
- name: Grab Nextcloud container information - name: Grab Nextcloud container information
community.general.docker_container_info: community.general.docker_container_info:
name: "{{ nextcloud_name }}" name: "{{ nextcloud_container }}"
register: nextcloud_info register: nextcloud_info
- name: Wait for Nextcloud to become available - name: Wait for Nextcloud to become available
ansible.builtin.wait_for: ansible.builtin.wait_for:
host: "{{ nextcloud_info.container.NetworkSettings.Networks.traefik.IPAddress }}" host: "{{ nextcloud_info.container.NetworkSettings.Networks.traefik.IPAddress }}"
delay: 10
port: 80 port: 80
- name: Check Nextcloud status - name: Check Nextcloud status
ansible.builtin.command: > ansible.builtin.command: "docker exec --user www-data {{ nextcloud_container }}
docker exec --user www-data "{{ nextcloud_name }}" php occ status php occ status"
register: nextcloud_status register: nextcloud_status
changed_when: false args:
removes: "{{ nextcloud_root }}/config/CAN_INSTALL"
- name: Wait for Nextcloud database to become available
ansible.builtin.wait_for:
host: "{{ nextcloud_dbinfo.container.NetworkSettings.Networks.nextcloud.IPAddress }}"
port: 3306
- name: Install Nextcloud - name: Install Nextcloud
ansible.builtin.command: > ansible.builtin.command: 'docker exec --user www-data {{ nextcloud_container }}
docker exec --user www-data {{ nextcloud_name }}
php occ maintenance:install php occ maintenance:install
--database "mysql" --database "mysql"
--database-host "{{ nextcloud.DB_HOST | default('host.docker.internal') }}" --database-host "{{ nextcloud_dbcontainer }}"
--database-name "{{ nextcloud.DB_NAME | default('nextcloud') }}" --database-name "{{ nextcloud_dbname }}"
--database-user "{{ nextcloud.DB_USER | default('nextcloud') }}" --database-user "{{ nextcloud_dbuser }}"
--database-pass "{{ nextcloud.DB_PASSWD }}" --database-pass "{{ nextcloud_dbpass }}"
--admin-user "{{ nextcloud.ADMIN_USER | default('admin') }}" --admin-user "{{ nextcloud_admin }}"
--admin-pass "{{ nextcloud.ADMIN_PASSWD }}" --admin-pass "{{ nextcloud_pass }}"'
register: nextcloud_install register: nextcloud_install
when: nextcloud_status.stderr[:26] == "Nextcloud is not installed" when:
changed_when: nextcloud_install.stdout == "Nextcloud was successfully installed" - nextcloud_status.stdout[:26] == "Nextcloud is not installed"
notify: install_nextcloud - nextcloud_domain is defined
- name: Set Nextcloud's Trusted Proxy
ansible.builtin.command: 'docker exec --user www-data {{ nextcloud_container }}
php occ config:system:set trusted_proxies 0
--value="{{ traefik_name }}"'
when: nextcloud_install.changed
- name: Set Nextcloud's Trusted Domain
ansible.builtin.command: 'docker exec --user www-data {{ nextcloud_container }}
php occ config:system:set trusted_domains 0
--value="{{ nextcloud_domain }}"'
when: nextcloud_install.changed
- name: Preform Nextcloud database maintenance
ansible.builtin.command: "docker exec --user www-data {{ nextcloud_container }} {{ item }}"
loop:
- "php occ maintenance:mode --on"
- "php occ db:add-missing-indices"
- "php occ db:convert-filecache-bigint"
- "php occ maintenance:mode --off"
when: nextcloud_install.changed
- name: Install Nextcloud background jobs cron - name: Install Nextcloud background jobs cron
ansible.builtin.cron: ansible.builtin.cron:
@@ -64,3 +111,8 @@
minute: "*/5" minute: "*/5"
job: "/usr/bin/docker exec -u www-data nextcloud /usr/local/bin/php -f /var/www/html/cron.php" job: "/usr/bin/docker exec -u www-data nextcloud /usr/local/bin/php -f /var/www/html/cron.php"
user: root user: root
- name: Remove Nextcloud's CAN_INSTALL file
ansible.builtin.file:
path: "{{ nextcloud_root }}/config/CAN_INSTALL"
state: absent

View File

@@ -1 +0,0 @@
cached_dhparams_pem: /vagrant/scratch/dhparams.pem

View File

@@ -10,19 +10,6 @@
state: started state: started
enabled: true enabled: true
- name: Check for cached dhparams.pem file
ansible.builtin.stat:
path: "{{ cached_dhparams_pem }}"
register: dhparams_file
- name: Copy cached dhparams.pem to /etc/ssl/
ansible.builtin.copy:
src: "{{ cached_dhparams_pem }}"
dest: /etc/ssl/dhparams.pem
mode: "600"
remote_src: true
when: dhparams_file.stat.exists
- name: Generate DH Parameters - name: Generate DH Parameters
community.crypto.openssl_dhparam: community.crypto.openssl_dhparam:
path: /etc/ssl/dhparams.pem path: /etc/ssl/dhparams.pem

View File

@@ -21,6 +21,20 @@
loop: "{{ traefik_external }}" loop: "{{ traefik_external }}"
when: traefik_external is defined when: traefik_external is defined
- name: Install Traefik's docker-compose file
ansible.builtin.template:
src: docker-compose.yml.j2
dest: "{{ traefik_root }}/docker-compose.yml"
mode: 0400
notify: restart_traefik
- name: Install Traefik's docker-compose variables
ansible.builtin.template:
src: compose-env.j2
dest: "{{ traefik_root }}/.env"
mode: 0400
notify: restart_traefik
- name: Install static Traefik configuration - name: Install static Traefik configuration
ansible.builtin.template: ansible.builtin.template:
src: traefik.yml.j2 src: traefik.yml.j2
@@ -28,9 +42,8 @@
mode: 0400 mode: 0400
notify: restart_traefik notify: restart_traefik
- name: Start Traefik service and enable on boot - name: Start and enable Traefik service
ansible.builtin.service: ansible.builtin.service:
name: "{{ docker_compose_service }}@{{ traefik_name }}" name: "{{ docker_compose_service }}@{{ traefik_name }}"
state: started state: started
enabled: true enabled: true
when: traefik.ENABLED | default('false')

View File

@@ -1,45 +0,0 @@
#!/bin/bash
# Defaults
TIMEOUT=600
ELAPSED=0
INITIAL_SLEEP=60
SLEEP_DURATION=30
SSH_AVAILABLE=0
DEBUG_ID="[homelab-ci]"
# Run Vagrant Up in the background
PLAYBOOK=dockerbox vagrant up &
VAGRANT_UP_PID=$!
# Initial delay
echo "$DEBUG_ID Waiting for VM to start..."
sleep $INITIAL_SLEEP
# Loop until timeout or breaks
while [[ $ELAPSED -lt $TIMEOUT ]]; do
VAGRANT_SSH_CONFIG=$(mktemp)
vagrant ssh-config > "$VAGRANT_SSH_CONFIG"
echo "$DEBUG_ID SSH config at $VAGRANT_SSH_CONFIG"
cat "$VAGRANT_SSH_CONFIG"
echo "$DEBUG_ID Vagrant status"
vagrant status
# SSH attempt
set -x
ssh -vvv -F "$VAGRANT_SSH_CONFIG" default 'cat /etc/os-release' && set +x; break \
|| echo "$DEBUG_ID SSH connection failed, retrying in $SLEEP_DURATION seconds..."
set +x
# Sleep and start again
sleep $SLEEP_DURATION
((ELAPSED+=SLEEP_DURATION))
done
# Success?
if [[ $SSH_AVAILABLE -ne 1 ]]; then
echo "$DEBUG_ID Timeout reached without successful SSH connection."
fi
# Ensure the Vagrant up process completes
wait $VAGRANT_UP_PID