-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
90 lines (75 loc) · 2.3 KB
/
Dockerfile
File metadata and controls
90 lines (75 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Dockerfile for testing Ansible WordPress Enterprise role
# Supports both Ubuntu and RHEL-based distributions
ARG BASE_IMAGE=ubuntu:22.04
FROM ${BASE_IMAGE}
LABEL maintainer="Thomas Vincent <thomasvincent@users.noreply.github.com>"
LABEL description="Docker image for testing WordPress Enterprise Ansible role"
LABEL version="1.0.0"
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
# Install system dependencies based on OS family
RUN if [ -f /etc/debian_version ]; then \
apt-get update && \
apt-get install -y --no-install-recommends \
python3 \
python3-pip \
python3-apt \
sudo \
systemd \
systemd-sysv \
curl \
wget \
ca-certificates \
gnupg \
lsb-release \
openssh-server && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*; \
elif [ -f /etc/redhat-release ]; then \
yum install -y \
python3 \
python3-pip \
sudo \
systemd \
curl \
wget \
ca-certificates \
openssh-server && \
yum clean all; \
fi
# Install Ansible and required collections
RUN pip3 install --no-cache-dir \
ansible>=2.14 \
ansible-lint \
molecule \
molecule-plugins[docker] \
pytest \
pytest-testinfra \
yamllint
# Install Ansible collections
RUN ansible-galaxy collection install community.general && \
ansible-galaxy collection install community.mysql && \
ansible-galaxy collection install ansible.posix
# Create ansible user with sudo privileges
RUN useradd -m -s /bin/bash ansible && \
echo "ansible ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ansible && \
chmod 0440 /etc/sudoers.d/ansible
# Setup SSH for testing
RUN mkdir -p /var/run/sshd && \
ssh-keygen -A
# Create workspace
WORKDIR /workspace
# Copy role files
COPY . /workspace/
# Set proper permissions
RUN chown -R ansible:ansible /workspace
# Switch to ansible user
USER ansible
# Set working directory
WORKDIR /workspace
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD python3 --version && ansible --version || exit 1
CMD ["/bin/bash"]