tests: support CentOS Docker images.
- namespace & document test accounts in README.md - standardize the password format everywhere, and ensure the passwords differ everywhere. - Add MITOGEN_TEST_DISTRO environment variable.pull/193/head
parent
6aad45748b
commit
f203a91e1a
@ -1,64 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import commands
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
DOCKERFILE = r"""
|
||||
FROM debian:stable
|
||||
RUN apt-get update
|
||||
RUN \
|
||||
apt-get install -y python2.7 openssh-server sudo rsync git strace && \
|
||||
apt-get clean
|
||||
RUN \
|
||||
mkdir /var/run/sshd && \
|
||||
echo '%sudo-nopw ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/001-sudo-nopw && \
|
||||
echo i-am-mitogen-test-docker-image > /etc/sentinel && \
|
||||
groupadd sudo-nopw && \
|
||||
useradd -m has-sudo -G sudo && \
|
||||
useradd -m has-sudo-pubkey -G sudo && \
|
||||
useradd -m has-sudo-nopw -G sudo-nopw && \
|
||||
useradd -m webapp && \
|
||||
( echo 'root:x' | chpasswd; ) && \
|
||||
( echo 'has-sudo:y' | chpasswd; ) && \
|
||||
( echo 'has-sudo-pubkey:y' | chpasswd; ) && \
|
||||
( echo 'has-sudo-nopw:y' | chpasswd; ) && \
|
||||
mkdir ~has-sudo-pubkey/.ssh && \
|
||||
{ echo '#!/bin/bash\nexec strace -ff -o /tmp/pywrap$$.trace python2.7 "$@"' > /usr/local/bin/pywrap; chmod +x /usr/local/bin/pywrap; } && \
|
||||
{ for i in `seq 1 21`; do useradd -s /bin/bash -m mitogen__user$i; done; }
|
||||
|
||||
COPY data/docker/has-sudo-pubkey.key.pub /home/has-sudo-pubkey/.ssh/authorized_keys
|
||||
RUN \
|
||||
chown -R has-sudo-pubkey ~has-sudo-pubkey && \
|
||||
chmod -R go= ~has-sudo-pubkey
|
||||
|
||||
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
|
||||
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
|
||||
|
||||
ENV NOTVISIBLE "in users profile"
|
||||
RUN echo "export VISIBLE=now" >> /etc/profile
|
||||
|
||||
EXPOSE 22
|
||||
CMD ["/usr/sbin/sshd", "-D"]
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def sh(s, *args):
|
||||
if args:
|
||||
s %= tuple(map(commands.mkarg, args))
|
||||
return shlex.split(s)
|
||||
|
||||
|
||||
mydir = os.path.abspath(os.path.dirname(__file__))
|
||||
with tempfile.NamedTemporaryFile(dir=mydir) as dockerfile_fp:
|
||||
dockerfile_fp.write(DOCKERFILE)
|
||||
dockerfile_fp.flush()
|
||||
|
||||
subprocess.check_call(sh('docker build %s -t d2mw/mitogen-test -f %s',
|
||||
mydir,
|
||||
dockerfile_fp.name
|
||||
))
|
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Build the Docker images used for testing.
|
||||
"""
|
||||
|
||||
import commands
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
DEBIAN_DOCKERFILE = r"""
|
||||
FROM debian:stable
|
||||
RUN apt-get update
|
||||
RUN \
|
||||
apt-get install -y python2.7 openssh-server sudo rsync git strace && \
|
||||
apt-get clean
|
||||
"""
|
||||
|
||||
CENTOS_DOCKERFILE = r"""
|
||||
FROM centos:7
|
||||
RUN yum clean all && \
|
||||
yum -y install -y python2.7 openssh-server sudo rsync git strace sudo && \
|
||||
yum clean all && \
|
||||
groupadd sudo
|
||||
|
||||
"""
|
||||
|
||||
DOCKERFILE = r"""
|
||||
RUN \
|
||||
mkdir /var/run/sshd && \
|
||||
echo '%mitogen__sudo_nopw ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/001-mitogen__sudo_nopw && \
|
||||
echo i-am-mitogen-test-docker-image > /etc/sentinel && \
|
||||
groupadd mitogen__sudo_nopw && \
|
||||
useradd -m mitogen__has_sudo -G SUDO_GROUP && \
|
||||
useradd -m mitogen__has_sudo_pubkey -G SUDO_GROUP && \
|
||||
useradd -m mitogen__has_sudo_nopw -G mitogen__sudo_nopw && \
|
||||
useradd -m mitogen__webapp && \
|
||||
( echo 'root:rootpassword' | chpasswd; ) && \
|
||||
( echo 'mitogen__has_sudo:has_sudo_password' | chpasswd; ) && \
|
||||
( echo 'mitogen__has_sudo_pubkey:has_sudo_pubkey_password' | chpasswd; ) && \
|
||||
( echo 'mitogen__has_sudo_nopw:has_sudo_nopw_password' | chpasswd; ) && \
|
||||
mkdir ~mitogen__has_sudo_pubkey/.ssh && \
|
||||
{ echo '#!/bin/bash\nexec strace -ff -o /tmp/pywrap$$.trace python2.7 "$@"' > /usr/local/bin/pywrap; chmod +x /usr/local/bin/pywrap; } && \
|
||||
{ for i in `seq 1 21`; do useradd -s /bin/bash -m mitogen__user$i; done; }
|
||||
|
||||
COPY data/docker/mitogen__has_sudo_pubkey.key.pub /home/mitogen__has_sudo_pubkey/.ssh/authorized_keys
|
||||
RUN \
|
||||
chown -R mitogen__has_sudo_pubkey ~mitogen__has_sudo_pubkey && \
|
||||
chmod -R go= ~mitogen__has_sudo_pubkey
|
||||
|
||||
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
|
||||
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
|
||||
|
||||
ENV NOTVISIBLE "in users profile"
|
||||
RUN echo "export VISIBLE=now" >> /etc/profile
|
||||
|
||||
EXPOSE 22
|
||||
CMD ["/usr/sbin/sshd", "-D"]
|
||||
"""
|
||||
|
||||
|
||||
def sh(s, *args):
|
||||
if args:
|
||||
s %= tuple(map(commands.mkarg, args))
|
||||
return shlex.split(s)
|
||||
|
||||
|
||||
for (distro, wheel, prefix) in (('debian', 'sudo', DEBIAN_DOCKERFILE),
|
||||
('centos', 'wheel', CENTOS_DOCKERFILE)):
|
||||
mydir = os.path.abspath(os.path.dirname(__file__))
|
||||
with tempfile.NamedTemporaryFile(dir=mydir) as dockerfile_fp:
|
||||
dockerfile_fp.write(prefix)
|
||||
dockerfile_fp.write(DOCKERFILE.replace('SUDO_GROUP', wheel))
|
||||
dockerfile_fp.flush()
|
||||
|
||||
subprocess.check_call(sh('docker build %s -t %s -f %s',
|
||||
mydir,
|
||||
'd2mw/mitogen-%s-test' % (distro,),
|
||||
dockerfile_fp.name
|
||||
))
|
Loading…
Reference in New Issue