Skip to content

Commit 9437cce

Browse files
authored
Merge pull request #29 from ppodgorsek/issue-28
Issue #28 - Replace the base image with an Ansible AWX execution envi…
2 parents e56c7d1 + 1193634 commit 9437cce

File tree

3 files changed

+58
-53
lines changed

3 files changed

+58
-53
lines changed

Containerfile

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
FROM quay.io/podman/stable:v5.6
1+
FROM docker.io/ppodgorsek/ansible-awx-ee:24.6.1.4
22

33
LABEL authors="Paul Podgorsek"
44
LABEL description="An agent for Azure Pipelines, with Ansible, git, Helm + kubectl, Java, Maven, .Net, Podman (Docker) + Buildah, PostgreSQL, Python 3 and Terraform enabled."
55

6+
ENV AGENT_GROUP_ID="1000"
7+
ENV AGENT_USER_ID="1000"
68
ENV AGENT_USER_NAME="podman"
79
ENV AGENT_WORK_DIR="/opt/pipeline-agent"
810

@@ -11,14 +13,7 @@ ENV AZURE_DEVOPS_AGENT_POOL="Default"
1113
ENV AZURE_DEVOPS_AGENT_NAME=""
1214
ENV AZURE_DEVOPS_AGENT_VERSION="4.264.2"
1315

14-
ENV ANSIBLE_COLLECTION_AWS_VERSION="10.1.2"
15-
ENV ANSIBLE_COLLECTION_AZURE_VERSION="v3.11.0"
16-
ENV ANSIBLE_COLLECTION_GCP_VERSION="v1.10.2"
1716
ENV DOTNET_VERSION="10.0"
18-
ENV HELM_VERSION="v3.19.0"
19-
ENV JAVA_VERSION="21"
20-
ENV POSTGRESQL_VERSION="18"
21-
ENV TERRAFORM_VERSION="1.13.5"
2217

2318
# Agent capabilities
2419
ENV ansible="enabled"
@@ -31,40 +26,72 @@ ENV maven="enabled"
3126
ENV postgresql="enabled"
3227
ENV terraform="enabled"
3328

29+
USER root
30+
3431
# Don't include container-selinux and remove directories used by DNF that are just taking up space.
3532
RUN dnf upgrade -y > /dev/null \
33+
&& dnf reinstall -y shadow-utils \
3634
&& dnf install -y \
3735
--exclude container-selinux \
3836
automake \
3937
buildah \
4038
# Install dependencies for cryptography due to https://github.com/pyca/cryptography/issues/5771
4139
cargo \
42-
curl \
4340
dnf-plugins-core \
4441
dotnet-sdk-${DOTNET_VERSION} \
42+
fuse-overlayfs \
4543
gcc \
4644
gcc-c++ \
4745
git \
48-
java-${JAVA_VERSION}-openjdk \
4946
make \
5047
maven \
51-
openssl \
5248
openssl-devel \
5349
podman-docker \
5450
python3 \
5551
python3-devel \
5652
python3-pip \
5753
rust \
58-
unzip \
5954
wget \
6055
which \
6156
zip \
6257
&& dnf clean all \
6358
&& rm -rf /var/cache /var/log/dnf* /var/log/yum.*
6459

60+
# Podman
61+
62+
RUN groupadd --gid ${AGENT_GROUP_ID} ${AGENT_USER_NAME} \
63+
&& useradd --gid ${AGENT_GROUP_ID} --uid ${AGENT_USER_ID} ${AGENT_USER_NAME} \
64+
&& echo ${AGENT_USER_NAME}:10000:5000 > /etc/subuid \
65+
&& echo ${AGENT_USER_NAME}:10000:5000 > /etc/subgid
66+
67+
VOLUME /var/lib/containers
68+
VOLUME /home/${AGENT_USER_NAME}/.local/share/containers
69+
70+
ADD https://raw.githubusercontent.com/containers/image_build/main/podman/containers.conf /etc/containers/containers.conf
71+
ADD https://raw.githubusercontent.com/containers/image_build/main/podman/podman-containers.conf /home/${AGENT_USER_NAME}/.config/containers/containers.conf
72+
73+
RUN chown ${AGENT_USER_ID}:${AGENT_GROUP_ID} -R /home/${AGENT_USER_NAME}
74+
75+
# chmod containers.conf and adjust storage.conf to enable Fuse storage.
76+
RUN chmod 644 /etc/containers/containers.conf \
77+
&& sed -i -e 's|^#mount_program|mount_program|g' \
78+
-e '/additionalimage.*/a "/var/lib/shared",' \
79+
-e 's|^mountopt[[:space:]]*=.*$|mountopt = "nodev,fsync=0"|g' \
80+
/etc/containers/storage.conf \
81+
&& mkdir -p /var/lib/shared/overlay-images \
82+
/var/lib/shared/overlay-layers \
83+
/var/lib/shared/vfs-images \
84+
/var/lib/shared/vfs-layers \
85+
&& touch /var/lib/shared/overlay-images/images.lock \
86+
&& touch /var/lib/shared/overlay-layers/layers.lock \
87+
&& touch /var/lib/shared/vfs-images/images.lock \
88+
&& touch /var/lib/shared/vfs-layers/layers.lock
89+
90+
ENV _CONTAINERS_USERNS_CONFIGURED=""
91+
6592
# Create directories for the agent files
6693
RUN mkdir ${AGENT_WORK_DIR} \
67-
&& chown -R ${AGENT_USER_NAME}:${AGENT_USER_NAME} ${AGENT_WORK_DIR} \
94+
&& chown -R ${AGENT_USER_ID}:${AGENT_GROUP_ID} ${AGENT_WORK_DIR} \
6895
\
6996
# Download and unpack tarball
7097
&& curl -L https://download.agent.dev.azure.com/agent/${AZURE_DEVOPS_AGENT_VERSION}/vsts-agent-${AGENT_PLATFORM:-linux-x64}-${AZURE_DEVOPS_AGENT_VERSION}.tar.gz -o /tmp/agent.tar.gz \
@@ -79,39 +106,7 @@ RUN sh ${AGENT_WORK_DIR}/bin/installdependencies.sh
79106
COPY scripts/configure-and-run-agent.sh ${AGENT_WORK_DIR}/configure-and-run-agent.sh
80107

81108
# Grant the correct permissions
82-
RUN chown ${AGENT_USER_NAME}:${AGENT_USER_NAME} ${AGENT_WORK_DIR}/configure-and-run-agent.sh
83-
84-
# Install the latest version of Ansible, along with the collections for major cloud providers
85-
RUN pip3 install ansible --upgrade \
86-
&& pip3 install cryptography --upgrade \
87-
&& pip3 install -r https://raw.githubusercontent.com/ansible-collections/amazon.aws/${ANSIBLE_COLLECTION_AWS_VERSION}/requirements.txt \
88-
# azure-iot-hub relies on the outdated uamqp library, which doesn't work with recent Python versions
89-
&& curl https://raw.githubusercontent.com/ansible-collections/azure/${ANSIBLE_COLLECTION_AZURE_VERSION}/requirements.txt | grep -ivE "azure-iot-hub|azure-mgmt-iothub" > azure-requirements.txt \
90-
&& pip3 install -r azure-requirements.txt \
91-
&& pip3 install -r https://raw.githubusercontent.com/ansible-collections/google.cloud/${ANSIBLE_COLLECTION_GCP_VERSION}/requirements.txt
92-
93-
# Kubernetes & Helm
94-
COPY conf/kubernetes.repo /etc/yum.repos.d/kubernetes.repo
95-
RUN dnf install -y kubectl \
96-
&& dnf clean all \
97-
&& pip3 install kubernetes \
98-
&& curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/${HELM_VERSION}/scripts/get-helm-3 \
99-
&& chmod 700 get_helm.sh \
100-
&& ./get_helm.sh --version ${HELM_VERSION} \
101-
&& rm -f get_helm.sh \
102-
&& helm plugin install https://github.com/databus23/helm-diff
103-
104-
# PostgreSQL
105-
RUN dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-43-x86_64/pgdg-fedora-repo-latest.noarch.rpm \
106-
&& dnf install -y postgresql${POSTGRESQL_VERSION} \
107-
&& dnf clean all \
108-
&& pip3 install psycopg2-binary
109-
110-
# Terraform
111-
# Official documentation: https://developer.hashicorp.com/terraform/install
112-
RUN dnf config-manager addrepo --from-repofile=https://rpm.releases.hashicorp.com/fedora/hashicorp.repo \
113-
&& dnf install -y terraform-${TERRAFORM_VERSION}* \
114-
&& dnf clean all
109+
RUN chown ${AGENT_USER_ID}:${AGENT_GROUP_ID} ${AGENT_WORK_DIR}/configure-and-run-agent.sh
115110

116111
USER ${AGENT_USER_NAME}
117112

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [Changing the name of the agent pool](#changing-agent-pool-name)
99
* [Initialising a self-hosted agent pool via the placeholder mode](#placeholder-mode)
1010
* [Overriding the agent name](#overriding-agent-name)
11+
* [Running Ansible](#running-ansible)
1112
* [Running the image on different platforms](#platforms)
1213
* [Azure Container Apps](#platform-azure-container-apps)
1314
* [Please contribute!](#please-contribute)
@@ -129,6 +130,22 @@ docker run --rm \
129130
docker.io/ppodgorsek/azure-pipelines-agent:<version>
130131
```
131132

133+
<a name="running-ansible"></a>
134+
135+
### Running Ansible
136+
137+
When running Ansible in your build pipeline, remember to install the relevant Ansible collections, for example:
138+
139+
```yml
140+
- script: |
141+
cd $(Pipeline.Workspace)/$(INFRASTRUCTURE_AS_CODE_PATH)/
142+
143+
ansible-galaxy install -r collections/requirements.yml
144+
145+
ansible-playbook CHANGEME-playbook.yml -i inventories/CHANGEME/hosts
146+
displayName: Ansible
147+
```
148+
132149
<a name="platforms"></a>
133150
134151
## Running the image on different platforms

conf/kubernetes.repo

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)