Добавлена поддержка собственных образов для molecule тестирования
- Созданы пресеты для тестирования с собственными образами: - custom-minimal.yml - минимальный тест (4 хоста) - custom-images.yml - полный тест (все образы) - custom-performance.yml - тест производительности (8 хостов) - Обновлен molecule.yml для поддержки собственных образов - Добавлен скрипт test-custom-images.sh для автоматизации тестирования - Добавлены команды в Makefile: - make custom-images test [minimal|full|performance] - make custom-images check - проверка наличия образов - make custom-images build - сборка всех образов - Поддержка образов: ansible-controller, alt-linux, astra-linux, redos, rhel, centos, alma, rocky Автор: Сергей Антропов Сайт: https://devops.org.ru
This commit is contained in:
57
Makefile
57
Makefile
@@ -864,6 +864,11 @@ help:
|
|||||||
@echo " make presets info - подробная информация о preset'е"
|
@echo " make presets info - подробная информация о preset'е"
|
||||||
@echo " make presets test - запустить тест с preset'ом"
|
@echo " make presets test - запустить тест с preset'ом"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
@echo "🖼️ СОБСТВЕННЫЕ ОБРАЗЫ (AnsibleTemplate):"
|
||||||
|
@echo " make custom-images test [minimal|full|performance] - тест с собственными образами"
|
||||||
|
@echo " make custom-images check - проверить наличие собственных образов"
|
||||||
|
@echo " make custom-images build - собрать все образы для тестирования"
|
||||||
|
@echo ""
|
||||||
@echo "🐳 DOCKER ОБРАЗЫ (Multi-Arch):"
|
@echo "🐳 DOCKER ОБРАЗЫ (Multi-Arch):"
|
||||||
@echo " make docker prepare - подготовка к работе с Docker Hub"
|
@echo " make docker prepare - подготовка к работе с Docker Hub"
|
||||||
@echo " make docker build - собрать все Docker образы (amd64 + arm64)"
|
@echo " make docker build - собрать все Docker образы (amd64 + arm64)"
|
||||||
@@ -921,6 +926,58 @@ help:
|
|||||||
@echo "📖 Подробная справка: make [команда]"
|
@echo "📖 Подробная справка: make [команда]"
|
||||||
@echo "=========================================="
|
@echo "=========================================="
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# КОМАНДЫ ДЛЯ РАБОТЫ С СОБСТВЕННЫМИ ОБРАЗАМИ
|
||||||
|
# =============================================================================
|
||||||
|
custom-images:
|
||||||
|
@case "$(word 2, $(MAKECMDGOALS))" in \
|
||||||
|
test) \
|
||||||
|
echo "🧪 Тестирование с собственными образами AnsibleTemplate..."; \
|
||||||
|
if [ -z "$(word 3, $(MAKECMDGOALS))" ]; then \
|
||||||
|
echo "💡 Использование: make custom-images test [minimal|full|performance]"; \
|
||||||
|
echo "💡 По умолчанию: minimal"; \
|
||||||
|
./scripts/test-custom-images.sh minimal; \
|
||||||
|
else \
|
||||||
|
./scripts/test-custom-images.sh $(word 3, $(MAKECMDGOALS)); \
|
||||||
|
fi;; \
|
||||||
|
check) \
|
||||||
|
echo "🔍 Проверка наличия собственных образов..."; \
|
||||||
|
./scripts/test-custom-images.sh check;; \
|
||||||
|
build) \
|
||||||
|
echo "🔨 Сборка всех образов для тестирования..."; \
|
||||||
|
$(MAKE) docker build;; \
|
||||||
|
*) \
|
||||||
|
echo "🎯 Доступные команды:"; \
|
||||||
|
echo ""; \
|
||||||
|
echo " 🧪 make custom-images test [minimal|full|performance] - тест с собственными образами"; \
|
||||||
|
echo " 💡 minimal - минимальный тест (4 хоста)"; \
|
||||||
|
echo " 💡 full - полный тест (все образы)"; \
|
||||||
|
echo " 💡 performance - тест производительности (8 хостов)"; \
|
||||||
|
echo ""; \
|
||||||
|
echo " 🔍 make custom-images check - проверить наличие собственных образов"; \
|
||||||
|
echo " 💡 Показывает: какие образы есть, какие отсутствуют"; \
|
||||||
|
echo " 💡 Предлагает: команды для сборки отсутствующих образов"; \
|
||||||
|
echo ""; \
|
||||||
|
echo " 🔨 make custom-images build - собрать все образы для тестирования"; \
|
||||||
|
echo " 💡 Выполняет: make docker build"; \
|
||||||
|
echo " 💡 Собирает: все образы AnsibleTemplate"; \
|
||||||
|
echo ""; \
|
||||||
|
echo "💡 Пресеты для тестирования:"; \
|
||||||
|
echo " - custom-minimal.yml - минимальный тест (4 хоста)"; \
|
||||||
|
echo " - custom-images.yml - полный тест (все образы)"; \
|
||||||
|
echo " - custom-performance.yml - тест производительности (8 хостов)"; \
|
||||||
|
echo ""; \
|
||||||
|
echo "💡 Собственные образы:"; \
|
||||||
|
echo " - inecs/ansible-lab:ansible-controller-latest"; \
|
||||||
|
echo " - inecs/ansible-lab:alt-linux-latest"; \
|
||||||
|
echo " - inecs/ansible-lab:astra-linux-latest"; \
|
||||||
|
echo " - inecs/ansible-lab:redos-latest"; \
|
||||||
|
echo " - inecs/ansible-lab:rhel-latest"; \
|
||||||
|
echo " - inecs/ansible-lab:centos-latest"; \
|
||||||
|
echo " - inecs/ansible-lab:alma-latest"; \
|
||||||
|
echo " - inecs/ansible-lab:rocky-latest";; \
|
||||||
|
esac
|
||||||
|
|
||||||
# Пустые цели для совместимости
|
# Пустые цели для совместимости
|
||||||
view create edit show delete lint deploy new advanced list info test build push pull clean prepare update run stop purge clean-builder setup-builder diagnose reset-builder build-image:
|
view create edit show delete lint deploy new advanced list info test build push pull clean prepare update run stop purge clean-builder setup-builder diagnose reset-builder build-image:
|
||||||
@true
|
@true
|
||||||
|
|||||||
@@ -8,9 +8,35 @@ driver:
|
|||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
# Платформы будут созданы динамически через preset файлы
|
# Платформы будут созданы динамически через preset файлы
|
||||||
|
# Поддержка собственных образов AnsibleTemplate
|
||||||
- name: placeholder
|
- name: placeholder
|
||||||
image: ghcr.io/ansible-community/molecule-ubuntu-systemd:jammy
|
image: ghcr.io/ansible-community/molecule-ubuntu-systemd:jammy
|
||||||
pre_build_image: true
|
pre_build_image: true
|
||||||
|
# Собственные образы (будут использоваться через presets)
|
||||||
|
- name: ansible-controller
|
||||||
|
image: inecs/ansible-lab:ansible-controller-latest
|
||||||
|
pre_build_image: true
|
||||||
|
- name: alt-linux
|
||||||
|
image: inecs/ansible-lab:alt-linux-latest
|
||||||
|
pre_build_image: true
|
||||||
|
- name: astra-linux
|
||||||
|
image: inecs/ansible-lab:astra-linux-latest
|
||||||
|
pre_build_image: true
|
||||||
|
- name: redos
|
||||||
|
image: inecs/ansible-lab:redos-latest
|
||||||
|
pre_build_image: true
|
||||||
|
- name: rhel
|
||||||
|
image: inecs/ansible-lab:rhel-latest
|
||||||
|
pre_build_image: true
|
||||||
|
- name: centos
|
||||||
|
image: inecs/ansible-lab:centos-latest
|
||||||
|
pre_build_image: true
|
||||||
|
- name: alma
|
||||||
|
image: inecs/ansible-lab:alma-latest
|
||||||
|
pre_build_image: true
|
||||||
|
- name: rocky
|
||||||
|
image: inecs/ansible-lab:rocky-latest
|
||||||
|
pre_build_image: true
|
||||||
|
|
||||||
provisioner:
|
provisioner:
|
||||||
name: ansible
|
name: ansible
|
||||||
|
|||||||
143
molecule/presets/custom-images.yml
Normal file
143
molecule/presets/custom-images.yml
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
---
|
||||||
|
#description: Пресет для тестирования на собственных образах AnsibleTemplate
|
||||||
|
# Автор: Сергей Антропов
|
||||||
|
# Сайт: https://devops.org.ru
|
||||||
|
|
||||||
|
docker_network: ansible-lab
|
||||||
|
generated_inventory: "{{ molecule_ephemeral_directory }}/inventory/hosts.ini"
|
||||||
|
|
||||||
|
# Собственные образы AnsibleTemplate
|
||||||
|
images:
|
||||||
|
# Debian-based образы
|
||||||
|
ansible-controller: "inecs/ansible-lab:ansible-controller-latest"
|
||||||
|
|
||||||
|
# ALT Linux
|
||||||
|
alt-linux: "inecs/ansible-lab:alt-linux-latest"
|
||||||
|
|
||||||
|
# Astra Linux
|
||||||
|
astra-linux: "inecs/ansible-lab:astra-linux-latest"
|
||||||
|
|
||||||
|
# RedOS
|
||||||
|
redos: "inecs/ansible-lab:redos-latest"
|
||||||
|
|
||||||
|
# RHEL-based образы
|
||||||
|
rhel: "inecs/ansible-lab:rhel-latest"
|
||||||
|
centos: "inecs/ansible-lab:centos-latest"
|
||||||
|
alma: "inecs/ansible-lab:alma-latest"
|
||||||
|
rocky: "inecs/ansible-lab:rocky-latest"
|
||||||
|
|
||||||
|
systemd_defaults:
|
||||||
|
privileged: true
|
||||||
|
command: "/sbin/init"
|
||||||
|
volumes:
|
||||||
|
- "/sys/fs/cgroup:/sys/fs/cgroup:ro"
|
||||||
|
tmpfs: ["/run", "/run/lock"]
|
||||||
|
capabilities: ["SYS_ADMIN"]
|
||||||
|
|
||||||
|
# Описание кластера с собственными образами
|
||||||
|
hosts:
|
||||||
|
# Ansible Controller
|
||||||
|
- name: ansible-controller
|
||||||
|
family: debian
|
||||||
|
groups: [controller, ansible, management]
|
||||||
|
image: "{{ images.ansible-controller }}"
|
||||||
|
publish: ["8080:8080", "8443:8443"]
|
||||||
|
volumes:
|
||||||
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
|
- "{{ molecule_ephemeral_directory }}/ansible:/ansible"
|
||||||
|
|
||||||
|
# ALT Linux серверы
|
||||||
|
- name: alt1
|
||||||
|
family: alt
|
||||||
|
groups: [alt, servers, web]
|
||||||
|
image: "{{ images.alt-linux }}"
|
||||||
|
- name: alt2
|
||||||
|
family: alt
|
||||||
|
groups: [alt, servers, app]
|
||||||
|
image: "{{ images.alt-linux }}"
|
||||||
|
|
||||||
|
# Astra Linux серверы
|
||||||
|
- name: astra1
|
||||||
|
family: astra
|
||||||
|
groups: [astra, servers, web]
|
||||||
|
image: "{{ images.astra-linux }}"
|
||||||
|
- name: astra2
|
||||||
|
family: astra
|
||||||
|
groups: [astra, servers, app]
|
||||||
|
image: "{{ images.astra-linux }}"
|
||||||
|
|
||||||
|
# RedOS серверы
|
||||||
|
- name: redos1
|
||||||
|
family: redos
|
||||||
|
groups: [redos, servers, web]
|
||||||
|
image: "{{ images.redos }}"
|
||||||
|
- name: redos2
|
||||||
|
family: redos
|
||||||
|
groups: [redos, servers, app]
|
||||||
|
image: "{{ images.redos }}"
|
||||||
|
|
||||||
|
# RHEL серверы
|
||||||
|
- name: rhel1
|
||||||
|
family: rhel
|
||||||
|
groups: [rhel, servers, web]
|
||||||
|
image: "{{ images.rhel }}"
|
||||||
|
- name: rhel2
|
||||||
|
family: rhel
|
||||||
|
groups: [rhel, servers, app]
|
||||||
|
image: "{{ images.rhel }}"
|
||||||
|
|
||||||
|
# CentOS серверы
|
||||||
|
- name: centos1
|
||||||
|
family: centos
|
||||||
|
groups: [centos, servers, web]
|
||||||
|
image: "{{ images.centos }}"
|
||||||
|
- name: centos2
|
||||||
|
family: centos
|
||||||
|
groups: [centos, servers, app]
|
||||||
|
image: "{{ images.centos }}"
|
||||||
|
|
||||||
|
# AlmaLinux серверы
|
||||||
|
- name: alma1
|
||||||
|
family: alma
|
||||||
|
groups: [alma, servers, web]
|
||||||
|
image: "{{ images.alma }}"
|
||||||
|
- name: alma2
|
||||||
|
family: alma
|
||||||
|
groups: [alma, servers, app]
|
||||||
|
image: "{{ images.alma }}"
|
||||||
|
|
||||||
|
# Rocky Linux серверы
|
||||||
|
- name: rocky1
|
||||||
|
family: rocky
|
||||||
|
groups: [rocky, servers, web]
|
||||||
|
image: "{{ images.rocky }}"
|
||||||
|
- name: rocky2
|
||||||
|
family: rocky
|
||||||
|
groups: [rocky, servers, app]
|
||||||
|
image: "{{ images.rocky }}"
|
||||||
|
|
||||||
|
# База данных на разных ОС
|
||||||
|
- name: db-rhel
|
||||||
|
family: rhel
|
||||||
|
groups: [database, rhel, db]
|
||||||
|
image: "{{ images.rhel }}"
|
||||||
|
publish: ["5432:5432", "3306:3306"]
|
||||||
|
- name: db-centos
|
||||||
|
family: centos
|
||||||
|
groups: [database, centos, db]
|
||||||
|
image: "{{ images.centos }}"
|
||||||
|
publish: ["5433:5432", "3307:3306"]
|
||||||
|
|
||||||
|
# Load balancer на ALT Linux
|
||||||
|
- name: lb-alt
|
||||||
|
family: alt
|
||||||
|
groups: [loadbalancer, haproxy, alt]
|
||||||
|
image: "{{ images.alt-linux }}"
|
||||||
|
publish: ["80:80", "443:443"]
|
||||||
|
|
||||||
|
# Мониторинг на Astra Linux
|
||||||
|
- name: monitor-astra
|
||||||
|
family: astra
|
||||||
|
groups: [monitoring, prometheus, astra]
|
||||||
|
image: "{{ images.astra-linux }}"
|
||||||
|
publish: ["9090:9090", "3000:3000"]
|
||||||
54
molecule/presets/custom-minimal.yml
Normal file
54
molecule/presets/custom-minimal.yml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
#description: Минимальный пресет для тестирования собственных образов (4 хоста)
|
||||||
|
# Автор: Сергей Антропов
|
||||||
|
# Сайт: https://devops.org.ru
|
||||||
|
|
||||||
|
docker_network: ansible-lab-minimal
|
||||||
|
generated_inventory: "{{ molecule_ephemeral_directory }}/inventory/hosts.ini"
|
||||||
|
|
||||||
|
# Собственные образы AnsibleTemplate (минимальный набор)
|
||||||
|
images:
|
||||||
|
ansible-controller: "inecs/ansible-lab:ansible-controller-latest"
|
||||||
|
alt-linux: "inecs/ansible-lab:alt-linux-latest"
|
||||||
|
rhel: "inecs/ansible-lab:rhel-latest"
|
||||||
|
centos: "inecs/ansible-lab:centos-latest"
|
||||||
|
|
||||||
|
systemd_defaults:
|
||||||
|
privileged: true
|
||||||
|
command: "/sbin/init"
|
||||||
|
volumes:
|
||||||
|
- "/sys/fs/cgroup:/sys/fs/cgroup:ro"
|
||||||
|
tmpfs: ["/run", "/run/lock"]
|
||||||
|
capabilities: ["SYS_ADMIN"]
|
||||||
|
|
||||||
|
# Минимальный кластер (4 хоста)
|
||||||
|
hosts:
|
||||||
|
# Ansible Controller
|
||||||
|
- name: ansible-controller
|
||||||
|
family: debian
|
||||||
|
groups: [controller, ansible, management]
|
||||||
|
image: "{{ images.ansible-controller }}"
|
||||||
|
volumes:
|
||||||
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
|
- "{{ molecule_ephemeral_directory }}/ansible:/ansible"
|
||||||
|
|
||||||
|
# ALT Linux сервер
|
||||||
|
- name: alt-server
|
||||||
|
family: alt
|
||||||
|
groups: [alt, servers, web]
|
||||||
|
image: "{{ images.alt-linux }}"
|
||||||
|
publish: ["80:80"]
|
||||||
|
|
||||||
|
# RHEL сервер
|
||||||
|
- name: rhel-server
|
||||||
|
family: rhel
|
||||||
|
groups: [rhel, servers, app]
|
||||||
|
image: "{{ images.rhel }}"
|
||||||
|
publish: ["8080:8080"]
|
||||||
|
|
||||||
|
# CentOS сервер
|
||||||
|
- name: centos-server
|
||||||
|
family: centos
|
||||||
|
groups: [centos, servers, db]
|
||||||
|
image: "{{ images.centos }}"
|
||||||
|
publish: ["5432:5432"]
|
||||||
101
molecule/presets/custom-performance.yml
Normal file
101
molecule/presets/custom-performance.yml
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
---
|
||||||
|
#description: Пресет для тестирования производительности на собственных образах (8 хостов)
|
||||||
|
# Автор: Сергей Антропов
|
||||||
|
# Сайт: https://devops.org.ru
|
||||||
|
|
||||||
|
docker_network: ansible-lab-performance
|
||||||
|
generated_inventory: "{{ molecule_ephemeral_directory }}/inventory/hosts.ini"
|
||||||
|
|
||||||
|
# Собственные образы AnsibleTemplate для тестирования производительности
|
||||||
|
images:
|
||||||
|
ansible-controller: "inecs/ansible-lab:ansible-controller-latest"
|
||||||
|
alt-linux: "inecs/ansible-lab:alt-linux-latest"
|
||||||
|
astra-linux: "inecs/ansible-lab:astra-linux-latest"
|
||||||
|
rhel: "inecs/ansible-lab:rhel-latest"
|
||||||
|
centos: "inecs/ansible-lab:centos-latest"
|
||||||
|
alma: "inecs/ansible-lab:alma-latest"
|
||||||
|
rocky: "inecs/ansible-lab:rocky-latest"
|
||||||
|
|
||||||
|
systemd_defaults:
|
||||||
|
privileged: true
|
||||||
|
command: "/sbin/init"
|
||||||
|
volumes:
|
||||||
|
- "/sys/fs/cgroup:/sys/fs/cgroup:ro"
|
||||||
|
tmpfs: ["/run", "/run/lock"]
|
||||||
|
capabilities: ["SYS_ADMIN"]
|
||||||
|
|
||||||
|
# Кластер для тестирования производительности
|
||||||
|
hosts:
|
||||||
|
# Ansible Controller
|
||||||
|
- name: ansible-controller
|
||||||
|
family: debian
|
||||||
|
groups: [controller, ansible, management]
|
||||||
|
image: "{{ images.ansible-controller }}"
|
||||||
|
volumes:
|
||||||
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
|
- "{{ molecule_ephemeral_directory }}/ansible:/ansible"
|
||||||
|
|
||||||
|
# Web серверы на разных ОС
|
||||||
|
- name: web-alt
|
||||||
|
family: alt
|
||||||
|
groups: [web, alt, performance]
|
||||||
|
image: "{{ images.alt-linux }}"
|
||||||
|
publish: ["80:80", "443:443"]
|
||||||
|
environment:
|
||||||
|
- NGINX_WORKER_PROCESSES=4
|
||||||
|
- NGINX_WORKER_CONNECTIONS=1024
|
||||||
|
|
||||||
|
- name: web-rhel
|
||||||
|
family: rhel
|
||||||
|
groups: [web, rhel, performance]
|
||||||
|
image: "{{ images.rhel }}"
|
||||||
|
publish: ["8080:80", "8443:443"]
|
||||||
|
environment:
|
||||||
|
- NGINX_WORKER_PROCESSES=4
|
||||||
|
- NGINX_WORKER_CONNECTIONS=1024
|
||||||
|
|
||||||
|
# App серверы на разных ОС
|
||||||
|
- name: app-centos
|
||||||
|
family: centos
|
||||||
|
groups: [app, centos, performance]
|
||||||
|
image: "{{ images.centos }}"
|
||||||
|
publish: ["8081:8080"]
|
||||||
|
environment:
|
||||||
|
- JAVA_OPTS="-Xmx2g -Xms1g"
|
||||||
|
|
||||||
|
- name: app-alma
|
||||||
|
family: alma
|
||||||
|
groups: [app, alma, performance]
|
||||||
|
image: "{{ images.alma }}"
|
||||||
|
publish: ["8082:8080"]
|
||||||
|
environment:
|
||||||
|
- JAVA_OPTS="-Xmx2g -Xms1g"
|
||||||
|
|
||||||
|
# Database серверы на разных ОС
|
||||||
|
- name: db-rocky
|
||||||
|
family: rocky
|
||||||
|
groups: [database, rocky, performance]
|
||||||
|
image: "{{ images.rocky }}"
|
||||||
|
publish: ["5432:5432"]
|
||||||
|
environment:
|
||||||
|
- POSTGRES_SHARED_BUFFERS=256MB
|
||||||
|
- POSTGRES_EFFECTIVE_CACHE_SIZE=1GB
|
||||||
|
|
||||||
|
- name: db-astra
|
||||||
|
family: astra
|
||||||
|
groups: [database, astra, performance]
|
||||||
|
image: "{{ images.astra-linux }}"
|
||||||
|
publish: ["5433:5432"]
|
||||||
|
environment:
|
||||||
|
- POSTGRES_SHARED_BUFFERS=256MB
|
||||||
|
- POSTGRES_EFFECTIVE_CACHE_SIZE=1GB
|
||||||
|
|
||||||
|
# Load balancer на ALT Linux
|
||||||
|
- name: lb-alt
|
||||||
|
family: alt
|
||||||
|
groups: [loadbalancer, haproxy, alt, performance]
|
||||||
|
image: "{{ images.alt-linux }}"
|
||||||
|
publish: ["80:80", "443:443", "8404:8404"]
|
||||||
|
environment:
|
||||||
|
- HAPROXY_MAXCONN=4096
|
||||||
|
- HAPROXY_NBTHREAD=4
|
||||||
231
scripts/test-custom-images.sh
Executable file
231
scripts/test-custom-images.sh
Executable file
@@ -0,0 +1,231 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Скрипт для тестирования собственных образов AnsibleTemplate
|
||||||
|
# Автор: Сергей Антропов
|
||||||
|
# Сайт: https://devops.org.ru
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Цвета для вывода
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Функция для вывода сообщений
|
||||||
|
log() {
|
||||||
|
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
success() {
|
||||||
|
echo -e "${GREEN}✅ $1${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
warning() {
|
||||||
|
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
echo -e "${RED}❌ $1${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Проверка наличия Docker
|
||||||
|
check_docker() {
|
||||||
|
log "Проверка Docker..."
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
error "Docker не установлен!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
success "Docker доступен"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Проверка наличия образов
|
||||||
|
check_images() {
|
||||||
|
log "Проверка наличия собственных образов..."
|
||||||
|
|
||||||
|
local images=(
|
||||||
|
"inecs/ansible-lab:ansible-controller-latest"
|
||||||
|
"inecs/ansible-lab:alt-linux-latest"
|
||||||
|
"inecs/ansible-lab:astra-linux-latest"
|
||||||
|
"inecs/ansible-lab:redos-latest"
|
||||||
|
"inecs/ansible-lab:rhel-latest"
|
||||||
|
"inecs/ansible-lab:centos-latest"
|
||||||
|
"inecs/ansible-lab:alma-latest"
|
||||||
|
"inecs/ansible-lab:rocky-latest"
|
||||||
|
)
|
||||||
|
|
||||||
|
local missing_images=()
|
||||||
|
|
||||||
|
for image in "${images[@]}"; do
|
||||||
|
if ! docker image inspect "$image" &> /dev/null; then
|
||||||
|
missing_images+=("$image")
|
||||||
|
else
|
||||||
|
success "Образ $image найден"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ${#missing_images[@]} -gt 0 ]; then
|
||||||
|
warning "Отсутствующие образы:"
|
||||||
|
for image in "${missing_images[@]}"; do
|
||||||
|
echo " - $image"
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
echo "Для сборки образов выполните:"
|
||||||
|
echo " make docker build"
|
||||||
|
echo ""
|
||||||
|
echo "Или соберите отдельные образы:"
|
||||||
|
for image in "${missing_images[@]}"; do
|
||||||
|
# Маппинг образов на имена для сборки
|
||||||
|
case "$image" in
|
||||||
|
"inecs/ansible-lab:ansible-controller-latest")
|
||||||
|
echo " make docker build-image IMAGE=ansible-controller"
|
||||||
|
;;
|
||||||
|
"inecs/ansible-lab:alt-linux-latest")
|
||||||
|
echo " make docker build-image IMAGE=alt-linux"
|
||||||
|
;;
|
||||||
|
"inecs/ansible-lab:astra-linux-latest")
|
||||||
|
echo " make docker build-image IMAGE=astra-linux"
|
||||||
|
;;
|
||||||
|
"inecs/ansible-lab:redos-latest")
|
||||||
|
echo " make docker build-image IMAGE=redos"
|
||||||
|
;;
|
||||||
|
"inecs/ansible-lab:rhel-latest")
|
||||||
|
echo " make docker build-image IMAGE=rhel"
|
||||||
|
;;
|
||||||
|
"inecs/ansible-lab:centos-latest")
|
||||||
|
echo " make docker build-image IMAGE=centos"
|
||||||
|
;;
|
||||||
|
"inecs/ansible-lab:alma-latest")
|
||||||
|
echo " make docker build-image IMAGE=alma"
|
||||||
|
;;
|
||||||
|
"inecs/ansible-lab:rocky-latest")
|
||||||
|
echo " make docker build-image IMAGE=rocky"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo " # Неизвестный образ: $image"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
success "Все образы найдены"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Тестирование с минимальным пресетом
|
||||||
|
test_minimal() {
|
||||||
|
log "Тестирование с минимальным пресетом (custom-minimal)..."
|
||||||
|
|
||||||
|
if [ -f "molecule/presets/custom-minimal.yml" ]; then
|
||||||
|
log "Запуск molecule test с пресетом custom-minimal..."
|
||||||
|
if molecule test --scenario-name custom-minimal; then
|
||||||
|
success "Тест с custom-minimal прошел успешно"
|
||||||
|
else
|
||||||
|
error "Тест с custom-minimal завершился с ошибкой"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "Файл molecule/presets/custom-minimal.yml не найден"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Тестирование с полным пресетом
|
||||||
|
test_full() {
|
||||||
|
log "Тестирование с полным пресетом (custom-images)..."
|
||||||
|
|
||||||
|
if [ -f "molecule/presets/custom-images.yml" ]; then
|
||||||
|
log "Запуск molecule test с пресетом custom-images..."
|
||||||
|
if molecule test --scenario-name custom-images; then
|
||||||
|
success "Тест с custom-images прошел успешно"
|
||||||
|
else
|
||||||
|
error "Тест с custom-images завершился с ошибкой"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "Файл molecule/presets/custom-images.yml не найден"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Тестирование производительности
|
||||||
|
test_performance() {
|
||||||
|
log "Тестирование производительности (custom-performance)..."
|
||||||
|
|
||||||
|
if [ -f "molecule/presets/custom-performance.yml" ]; then
|
||||||
|
log "Запуск molecule test с пресетом custom-performance..."
|
||||||
|
if molecule test --scenario-name custom-performance; then
|
||||||
|
success "Тест производительности прошел успешно"
|
||||||
|
else
|
||||||
|
error "Тест производительности завершился с ошибкой"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "Файл molecule/presets/custom-performance.yml не найден"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Очистка после тестов
|
||||||
|
cleanup() {
|
||||||
|
log "Очистка после тестов..."
|
||||||
|
|
||||||
|
# Остановка и удаление контейнеров
|
||||||
|
docker ps -a --filter "name=molecule" --format "{{.Names}}" | xargs -r docker rm -f 2>/dev/null || true
|
||||||
|
|
||||||
|
# Удаление сетей
|
||||||
|
docker network ls --filter "name=ansible-lab" --format "{{.Name}}" | xargs -r docker network rm 2>/dev/null || true
|
||||||
|
|
||||||
|
success "Очистка завершена"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Основная функция
|
||||||
|
main() {
|
||||||
|
log "🚀 Тестирование собственных образов AnsibleTemplate"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
# Проверки
|
||||||
|
check_docker
|
||||||
|
|
||||||
|
if ! check_images; then
|
||||||
|
error "Не все образы найдены. Завершение."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Выбор типа тестирования
|
||||||
|
case "${1:-minimal}" in
|
||||||
|
"minimal")
|
||||||
|
test_minimal
|
||||||
|
;;
|
||||||
|
"full")
|
||||||
|
test_full
|
||||||
|
;;
|
||||||
|
"performance")
|
||||||
|
test_performance
|
||||||
|
;;
|
||||||
|
"all")
|
||||||
|
test_minimal && test_full && test_performance
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Использование: $0 [minimal|full|performance|all]"
|
||||||
|
echo ""
|
||||||
|
echo " minimal - минимальный тест (4 хоста)"
|
||||||
|
echo " full - полный тест (все образы)"
|
||||||
|
echo " performance - тест производительности (8 хостов)"
|
||||||
|
echo " all - все тесты"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Очистка
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
success "🎉 Тестирование завершено успешно!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Обработка сигналов
|
||||||
|
trap cleanup EXIT INT TERM
|
||||||
|
|
||||||
|
# Запуск
|
||||||
|
main "$@"
|
||||||
Reference in New Issue
Block a user