Skip to content

Commit 7093b6e

Browse files
committed
feat: add docker socket volume mount
1 parent 062d7de commit 7093b6e

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ RUN set -eux; \
1919
# Create ansible user with explicit uid
2020
RUN <<EOF
2121
set -eux
22+
groupadd -r docker --gid=999
2223
groupadd -r ansible --gid=1000
23-
useradd -m -u 1000 -g 1000 ansible
24+
useradd -m -u 1000 -g 1000 -G 999 ansible
2425
mkdir -p /home/ansible/.ssh
2526
chown -R ansible:ansible /home/ansible
2627
EOF
@@ -46,6 +47,7 @@ EOF
4647

4748
VOLUME /app
4849
VOLUME /home/ansible/.ssh
50+
VOLUME /var/run/docker.sock
4951
WORKDIR /app
5052
ENTRYPOINT ["/docker-entrypoint.sh"]
5153
CMD ["/bin/bash"]

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ This project builds a docker image with all of the dependencies required to run
66

77
### Environment Variables
88

9-
| Environment Variable | Description |
10-
| -------------------- | -------------------------------------- |
11-
| `PUID` | User ID of the primary ansible user |
12-
| `PGID` | Group ID for the priamry ansible group |
9+
| Environment Variable | Default | Description |
10+
| -------------------- | ------- | -------------------------------------- |
11+
| `PUID` | `1000` | User ID of the primary ansible user |
12+
| `PGID` | `1000` | Group ID for the priamry ansible group |
13+
| `DOCKERGID` | `999` | Group ID for the docker group |
1314

1415
### Users
1516

@@ -19,10 +20,11 @@ This project builds a docker image with all of the dependencies required to run
1920

2021
### Mounts
2122

22-
| Mount | Description |
23-
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
24-
| `/app` | The expected mount path for an ansible project |
25-
| `/home/ansible/.ssh` | The default ansible user's SSH Directory. Private keys can be mounted inside of this directory for use by ansible-playbook during runs. |
23+
| Mount | Description |
24+
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
25+
| `/app` | The expected mount path for an ansible project |
26+
| `/home/ansible/.ssh` | The default ansible user's SSH Directory. Private keys can be mounted inside of this directory for use by ansible-playbook during runs. |
27+
| `/var/run/docker.sock` | This container supports access to the host's docker daemon for testing purposes. Optionally mount the docker socket if you require this. |
2628

2729
## Usage
2830

@@ -35,6 +37,7 @@ docker run \
3537
--network host \
3638
-e PUID=${id -u} \
3739
-e PGID=${id -g} \
40+
-e DOCKERGID=${getent group docker | cut -d ':' -f 3} \
3841
--mount type=bind,source=".",target=/app \
3942
--mount type=bind,source="${HOME}/.ssh",target=/home/ansible/.ssh,readonly \
4043
ghcr.io/gamersoutreach/ansible-runner:latest \

overlay/docker-entrypoint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ set -e
33

44
PUID="${PUID:-1000}"
55
PGID="${PGID:-1000}"
6+
DOCKERGID="${DOCKERGID:-999}"
67

78
# Set UID/GID of ansible user
89
sed -i "s/^ansible\:x\:1000\:1000/ansible\:x\:$PUID\:$PGID/" /etc/passwd
910
sed -i "s/^ansible\:x\:1000/ansible\:x\:$PGID/" /etc/group
1011

12+
# Set the GID of the docker group
13+
sed -i "s/^docker\:x\:999/docker\:x\:$DOCKERGID/" /etc/group
14+
1115
# Set permissions on home folder, excluding .ssh mount
1216
chown $PUID:$PGID /home/ansible
1317
find /home/ansible -mindepth 1 -maxdepth 1 -not -name ".ssh" -exec chown -R $PUID:$PGID {} \;

overlay/opt/buildpack/requirements.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# Match arista.avd collection requirements
2-
# https://github.com/aristanetworks/avd/blob/v4.5.0/ansible_collections/arista/avd/requirements.txt
1+
# Default requirements for all projects
32
ansible
43
ansible-pylibssh
54
ansible-lint
5+
6+
# Match arista.avd collection requirements
7+
# https://github.com/aristanetworks/avd/blob/v4.6.0/ansible_collections/arista/avd/requirements.txt
8+
aristaproto>=0.1.1
69
cryptography>=38.0.4
710
cvprac>=1.3.1
811
deepmerge>=1.1.0

overlay/opt/buildpack/requirements.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
collections:
33
- name: ansible.netcommon
44
version: 6.0.0
5+
source: https://galaxy.ansible.com
56
- name: arista.avd
67
version: 4.6.0
8+
source: https://galaxy.ansible.com
79
- name: community.docker
810
version: 3.7.0
911
source: https://galaxy.ansible.com

0 commit comments

Comments
 (0)