Skip to content

Commit

Permalink
feat: add docker socket volume mount
Browse files Browse the repository at this point in the history
  • Loading branch information
wastrachan committed Feb 17, 2024
1 parent 062d7de commit 7093b6e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ RUN set -eux; \
# Create ansible user with explicit uid
RUN <<EOF
set -eux
groupadd -r docker --gid=999
groupadd -r ansible --gid=1000
useradd -m -u 1000 -g 1000 ansible
useradd -m -u 1000 -g 1000 -G 999 ansible
mkdir -p /home/ansible/.ssh
chown -R ansible:ansible /home/ansible
EOF
Expand All @@ -46,6 +47,7 @@ EOF

VOLUME /app
VOLUME /home/ansible/.ssh
VOLUME /var/run/docker.sock
WORKDIR /app
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/bin/bash"]
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ This project builds a docker image with all of the dependencies required to run

### Environment Variables

| Environment Variable | Description |
| -------------------- | -------------------------------------- |
| `PUID` | User ID of the primary ansible user |
| `PGID` | Group ID for the priamry ansible group |
| Environment Variable | Default | Description |
| -------------------- | ------- | -------------------------------------- |
| `PUID` | `1000` | User ID of the primary ansible user |
| `PGID` | `1000` | Group ID for the priamry ansible group |
| `DOCKERGID` | `999` | Group ID for the docker group |

### Users

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

### Mounts

| Mount | Description |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `/app` | The expected mount path for an ansible project |
| `/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. |
| Mount | Description |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `/app` | The expected mount path for an ansible project |
| `/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. |
| `/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. |

## Usage

Expand All @@ -35,6 +37,7 @@ docker run \
--network host \
-e PUID=${id -u} \
-e PGID=${id -g} \
-e DOCKERGID=${getent group docker | cut -d ':' -f 3} \
--mount type=bind,source=".",target=/app \
--mount type=bind,source="${HOME}/.ssh",target=/home/ansible/.ssh,readonly \
ghcr.io/gamersoutreach/ansible-runner:latest \
Expand Down
4 changes: 4 additions & 0 deletions overlay/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ set -e

PUID="${PUID:-1000}"
PGID="${PGID:-1000}"
DOCKERGID="${DOCKERGID:-999}"

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

# Set the GID of the docker group
sed -i "s/^docker\:x\:999/docker\:x\:$DOCKERGID/" /etc/group

# Set permissions on home folder, excluding .ssh mount
chown $PUID:$PGID /home/ansible
find /home/ansible -mindepth 1 -maxdepth 1 -not -name ".ssh" -exec chown -R $PUID:$PGID {} \;
Expand Down
7 changes: 5 additions & 2 deletions overlay/opt/buildpack/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Match arista.avd collection requirements
# https://github.com/aristanetworks/avd/blob/v4.5.0/ansible_collections/arista/avd/requirements.txt
# Default requirements for all projects
ansible
ansible-pylibssh
ansible-lint

# Match arista.avd collection requirements
# https://github.com/aristanetworks/avd/blob/v4.6.0/ansible_collections/arista/avd/requirements.txt
aristaproto>=0.1.1
cryptography>=38.0.4
cvprac>=1.3.1
deepmerge>=1.1.0
Expand Down
2 changes: 2 additions & 0 deletions overlay/opt/buildpack/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
collections:
- name: ansible.netcommon
version: 6.0.0
source: https://galaxy.ansible.com
- name: arista.avd
version: 4.6.0
source: https://galaxy.ansible.com
- name: community.docker
version: 3.7.0
source: https://galaxy.ansible.com
Expand Down

0 comments on commit 7093b6e

Please sign in to comment.