Skip to content

Commit ee21c17

Browse files
Merge pull request #344 from shanemcd/refactored-dockerfile
Refactor Dockerfile and entryoint Reviewed-by: https://github.com/apps/ansible-zuul
2 parents f70ff01 + 56f14a3 commit ee21c17

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

Dockerfile

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
FROM centos:7
22

3-
ADD https://github.com/krallin/tini/releases/download/v0.14.0/tini /tini
3+
ADD https://github.com/krallin/tini/releases/download/v0.18.0/tini /bin/tini
4+
ADD utils/entrypoint.sh /bin/entrypoint
5+
ADD demo/project /runner/project
6+
ADD demo/env /runner/env
7+
ADD demo/inventory /runner/inventory
48

59
# Install Ansible Runner
6-
RUN yum -y install epel-release && \
7-
yum -y install ansible python-psutil python-pip python-docutils bubblewrap bzip2 python-crypto openssh openssh-clients git && \
8-
localedef -c -i en_US -f UTF-8 en_US.UTF-8 && \
9-
chmod +x /tini && \
10-
pip install --no-cache-dir wheel pexpect psutil python-daemon && \
11-
rm -rf /var/cache/yum
10+
RUN yum-config-manager --add-repo https://releases.ansible.com/ansible-runner/ansible-runner.el7.repo && \
11+
yum install -y epel-release && yum install -y python-pip ansible-runner bubblewrap sudo rsync && \
12+
pip install --no-cache-dir ansible && \
13+
localedef -c -i en_US -f UTF-8 en_US.UTF-8 && \
14+
chmod +x /bin/tini /bin/entrypoint && rm -rf /var/cache/yum
1215

13-
ENV LANG=en_US.UTF-8 \
14-
LANGUAGE=en_US:en \
15-
LC_ALL=en_US.UTF-8
16+
# In OpenShift, container will run as a random uid number and gid 0. Make sure things
17+
# are writeable by the root group.
18+
RUN mkdir -p /runner/inventory /runner/project /runner/artifacts /runner/.ansible/tmp && \
19+
chmod -R g+w /runner && chgrp -R root /runner && \
20+
chmod g+w /etc/passwd
1621

1722
VOLUME /runner/inventory
1823
VOLUME /runner/project
1924
VOLUME /runner/artifacts
20-
ENTRYPOINT ["/tini", "--"]
21-
WORKDIR /
25+
26+
ENV LANG=en_US.UTF-8
27+
ENV LANGUAGE=en_US:en
28+
ENV LC_ALL=en_US.UTF-8
2229
ENV RUNNER_BASE_COMMAND=ansible-playbook
23-
CMD /entrypoint.sh
30+
ENV HOME=/runner
2431

25-
ADD utils/entrypoint.sh /entrypoint.sh
26-
ADD demo/project /runner/project
27-
ADD demo/env /runner/env
28-
ADD demo/inventory /runner/inventory
29-
ADD dist/ansible_runner-1.3.4-py2.py3-none-any.whl /ansible_runner-1.3.4-py2.py3-none-any.whl
30-
# In OpenShift, container will run as a random uid number and gid 0. Make sure things
31-
# are writeable by the root group.
32-
RUN chmod 755 /entrypoint.sh && chmod -R g+w /runner && chgrp -R root /runner && \
33-
chmod g+w /etc/passwd && \
34-
pip install --no-cache-dir /ansible_runner-1.3.4-py2.py3-none-any.whl
32+
WORKDIR /runner
33+
34+
ENTRYPOINT ["entrypoint"]
35+
CMD ["ansible-runner", "run", "/runner"]

utils/entrypoint.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
# that doesn't exist in /etc/passwd, but Ansible module utils
55
# require a named user. So if we're in OpenShift, we need to make
66
# one before Ansible runs.
7-
if [ `id -u` -ge 500 ]; then
8-
echo "runner:x:`id -u`:`id -g`:,,,:/runner:/bin/bash" > /tmp/passwd
9-
cat /tmp/passwd >> /etc/passwd
10-
rm /tmp/passwd
7+
if [ `id -u` -ge 500 ] || [ -z "${CURRENT_UID}" ]; then
8+
9+
cat << EOF > /tmp/passwd
10+
root:x:0:0:root:/root:/bin/bash
11+
runner:x:`id -u`:`id -g`:,,,:/runner:/bin/bash
12+
EOF
13+
14+
cat /tmp/passwd > /etc/passwd
15+
rm /tmp/passwd
1116
fi
12-
ansible-runner run /runner
17+
18+
exec tini -- "${@}"

0 commit comments

Comments
 (0)