From d40cccbdb9ce095a32765abf384983904672008f Mon Sep 17 00:00:00 2001 From: thehedhly Date: Wed, 6 Nov 2024 23:15:15 +0100 Subject: [PATCH] Simplify project usage - Add docker-compose file - Update README.md --- README.md | 64 ++++++++++++++++++---------------------------- docker-compose.yml | 43 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 docker-compose.yml diff --git a/README.md b/README.md index 67f941f..47b5bbc 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,31 @@ In accordance with both ansible community projects, __ansible community package_ | ansible community package | | [thehedhly/ansible](https://hub.docker.com/repository/docker/thehedhly/ansible) | | ansible-core | | [thehedhly/ansible-core](https://hub.docker.com/repository/docker/thehedhly/ansible-core) | +## Usage +* Build the ansible or ansible-core docker image, run then attach to the container: +```bash +docker compose run --build --remove-orphans --rm +``` +* Build the ansible or ansible-core docker image, run command without attaching to the container: +```bash +docker compose run --build --remove-orphans --rm +``` +Examples: +```bash +# Build ansible image, run and attach to container +docker compose run --build --remove-orphans --rm ansible +# or +# Build ansible-core image, run and attach to container +docker compose run --build --remove-orphans --rm ansible-core +# or +# Build ansible image, run 'ansible --version' command without attaching to the container +docker compose run --build --remove-orphans --rm ansible ansible --version +# or +# Build ansible-core image, run 'ansible --version' command without attaching to the container +docker compose run --build --remove-orphans --rm ansible-core ansible --version +``` +To use a specefic ansible or ansible-core version, please see [docker-compose.yml](docker-compose.yml) and [list of supported build arguments](#build-arguments). + ## Build arguments | Name | description | default | |------|---------|---------| @@ -28,43 +53,4 @@ In accordance with both ansible community projects, __ansible community package_ | `ANSIBLE_GALAXY_CLI_ROLE_OPTS` | Build's CLI options for installing ansible roles.
Check [ansible-galaxy]() cli documentation for more details. | -v | | `ANSIBLE_USER` | User to set for ansible image. A home directory is setup for the provided user. The default [ansible configuration file](ansible.cfg) for the user is located in his home driectory. | thehedhly | - -## Usage -### Build -`ansible-core` -``` -docker build -t ansible-core . -``` -``` -docker build --build-arg ANSIBLE_INSTALL_REFS=ansible-core== -t ansible-core: . -``` -`ansible community package` -``` -docker build --build-arg ANSIBLE_INSTALL_REFS=ansible -t ansible . -``` -``` -docker build --build-arg ANSIBLE_INSTALL_REFS=ansible== -t ansible: . -``` -#### Run -`ansible-core` -``` -docker run --rm -it ansible-core bash -``` -``` -docker run --rm -it ansible-core: bash -``` -``` -docker run --rm -it --mount type=bind,source=/home//,target=/opt/ --mount type=bind,source=/home//.ssh,target=/home//.ssh,readonly > bash -``` -`ansible community package` -``` -docker run --rm -it ansible bash -``` -``` -docker run --rm -it ansible: bash -``` -``` -docker run --rm -it --mount type=bind,source=/home//,target=/opt/ --mount type=bind,source=/home//.ssh,target=/home//.ssh,readonly > bash -``` - This project was created by [H.Hedhly](https://hedhly.com). diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0017893 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +services: + ansible-core: + build: + context: . + dockerfile: Dockerfile + target: final + args: + ANSIBLE_USER: ${USER} + ANSIBLE_INSTALL_REFS: ansible-core + # ANSIBLE_INSTALL_REFS: ansible-core==2.17.0 + command: /bin/bash + stdin_open: true + tty: true + ansible: + build: + context: . + dockerfile: Dockerfile + target: final + args: + ANSIBLE_USER: ${USER} + ANSIBLE_INSTALL_REFS: ansible + # ANSIBLE_INSTALL_REFS: ansible==10 + command: /bin/bash + stdin_open: true + # environment: + # - ANSIBLE_CONFIG=/opt/my-ansible-project/ansible.cfg # load your own custom ansible.cfg + tty: true + volumes: + - ssh:/home/${USER}/.ssh:ro + # - other:/opt/my-ansible-project:ro +volumes: + ssh: + driver: local + driver_opts: + type: none + device: ~/.ssh + o: bind + # other: + # driver: local + # driver_opts: + # type: none + # device: ~/path/to/ansible-project + # o: bind