From b9e417f4129c2136b69f85b80a4b6a2c43cff034 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 20:04:53 +0700 Subject: [PATCH 1/9] Support config persistent --- Dockerfile | 22 ++++++++++++++++++++++ entrypoint.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 2c49017..6e0be36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -92,6 +92,19 @@ RUN mkdir -p /etc/apt/keyrings && \ RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* +# # Create the configuration directories inside the container +# RUN mkdir -p /root/.aws /root/.azure /root/.kube /root/.terraform.d/plugins /root/.config/helm /root/.ansible +# RUN mkdir -p /config/.aws /config/.azure /config/.kube /config/.terraform.d/plugins /config/.config/helm /config/.ansible + +# # Set up symlinks (this assumes that the configuration folder is mounted to /config) +# RUN ln -s /config/.aws /root/.aws && \ +# ln -s /config/.azure /root/.azure && \ +# ln -s /config/.kube /root/.kube && \ +# ln -s /config/.terraform.d/plugins /root/.terraform.d/plugins && \ +# ln -s /config/.helm /root/.config/helm && \ +# ln -s /config/.ansible /root/.ansible && \ +# ln -s /config/.gitconfig /root/.gitconfig + # Set the working directory WORKDIR /root @@ -103,5 +116,14 @@ RUN chmod +x /root/samples/run_sample.sh ENV DEBIAN_FRONTEND teletype ENV TZ="" +# Copy the entrypoint script into the container +COPY entrypoint.sh /usr/local/bin/entrypoint.sh + +# Make the entrypoint script executable +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Set the entrypoint to the entrypoint script +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + # Define the default command to run when the container starts CMD ["/bin/bash"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..fd0dbaa --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +CONFIG_DIR=/config + +# Function to create symlink if source exists +create_symlink() { + local src=$1 + local dest=$2 + if [ -e "$src" ]; then + ln -sf "$src" "$dest" + echo "Symlink created: $src -> $dest" + fi +} + +# Check if the /config directory exists and is not empty +if [ -d "$CONFIG_DIR" ] ; then + echo "Custom configuration directory detected. Setting up symlinks..." + + # TODO: Check and only create if folder does not exist + # mkdir -p /root/.aws /root/.azure /root/.kube /root/.terraform.d/plugins /root/.config/helm /root/.ansible + mkdir -p /config/.aws \ + /config/.azure \ + /config/.kube \ + /config/.terraform.d/ \ + /config/.config/helm \ + /config/.ansible + + create_symlink "$CONFIG_DIR/.aws" "/root/.aws" + create_symlink "$CONFIG_DIR/.azure" "/root/.azure" + create_symlink "$CONFIG_DIR/.kube" "/root/.kube" + create_symlink "$CONFIG_DIR/.terraform.d/" "/root/.terraform.d/" + create_symlink "$CONFIG_DIR/.helm" "/root/.config/helm" + create_symlink "$CONFIG_DIR/.ansible" "/root/.ansible" + create_symlink "$CONFIG_DIR/.gitconfig" "/root/.gitconfig" +else + echo "No custom configuration directory detected. Using default configurations..." +fi + +# Execute the provided command +exec "$@" From c9cd4077b0f1ef40caf33b01ecf74a5ccf2bc947 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 20:10:46 +0700 Subject: [PATCH 2/9] Update az cli doc --- docs/usage/azurecli_usage.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/usage/azurecli_usage.md b/docs/usage/azurecli_usage.md index 9efbb6b..3565e20 100644 --- a/docs/usage/azurecli_usage.md +++ b/docs/usage/azurecli_usage.md @@ -22,8 +22,11 @@ docker exec -it my_devops_toolkit /bin/bash ```bash docker run --rm -it tungbq/devops-toolkit:latest + +# Login with AZ CLI +az login --use-device-code ## To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code to authenticate -az login + # List all resource groups az group list ``` From 69a06d10afe98612923f3581602bf5b6008701d8 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 21:24:05 +0700 Subject: [PATCH 3/9] document the run mode support --- README.md | 12 ++++++---- docs/usage/run_mode.md | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 docs/usage/run_mode.md diff --git a/README.md b/README.md index 03aeeec..fe9dc5c 100644 --- a/README.md +++ b/README.md @@ -43,22 +43,26 @@ _NOTE_: In the following section, we use the latest tag in the documentation, bu ## Quick start 🔥 +- Use latest tag + ```bash -# Use latest tag docker run --network host -it --rm tungbq/devops-toolkit:latest +``` -# Use specific tag +- Use specific tag + +```bash docker run --network host -it --rm tungbq/devops-toolkit:0.1.0 ``` ## Demo 📺 -Check out the full sample and instruction at [**samples**](./samples/) - ```bash docker run --network host --rm tungbq/devops-toolkit:latest samples/run_sample.sh ``` +Check out the full sample and instruction at [**samples**](./samples/) + ## Getting started 📖 ### Pull the official image from Docker Hub diff --git a/docs/usage/run_mode.md b/docs/usage/run_mode.md new file mode 100644 index 0000000..ed08b5a --- /dev/null +++ b/docs/usage/run_mode.md @@ -0,0 +1,52 @@ +# DevOps toolkit run mode + +The DevOps Toolkit image can be run in various modes. See [docker/container/run](https://docs.docker.com/reference/cli/docker/container/run/) for more information. Check the document below for further details. + +## Run option + +Command: `docker run tungbq/devops-toolkit:`, some of the common options can be used in any combination: + +- `-it`: Interactive mode. +- `--rm`: Remove the container after it completes (Ctrl + C or container exit event). +- `--network host`: Use the host (VM) network. +- `--name `: Assign a name to the container (e.g: `--name demo001`). +- `-v :/config`: Mount a config folder on the host to the container. This allows reusing configurations in the container, like AWS and Azure login sessions (e.g: `-v ~/devops-toolkit-config:/config`, `-v /tmp/devops-toolkit-config-01:/config`). + +## Example + +- Run the image in interactive mode: + +```bash +docker run -it --rm tungbq/devops-toolkit:latest +``` + +- Run a specific tag of the toolkit: + +```bash +docker run -it --rm tungbq/devops-toolkit:0.1.0 +``` + +- Run the image with host network and remove the container after it completes: + +```bash +docker run --network host -it --rm tungbq/devops-toolkit:latest +``` + +- Run the image with default configuration and keep the container: + +```bash +docker run --network host -it tungbq/devops-toolkit:latest +``` + +- Run the image with default configuration, specify the container name, and keep the container: + +```bash +docker run --network host -it --name demo001 tungbq/devops-toolkit:latest +``` + +- Run the image and mount the configuration from the host, and remove the container after it completes: + +```bash +mkdir -p ~/devops-toolkit-config # or other location you want to store the configuration +docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest +``` From 5d7506468ce40fb2b2fa01c57be8583c4c0d9a90 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 21:45:34 +0700 Subject: [PATCH 4/9] New feature document.part1 --- README.md | 17 +++++++++++------ entrypoint.sh | 51 +++++++++++++++++++++++++++------------------------ 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index fe9dc5c..29354e5 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ - **Regular Updates**: Weekly checks and updates for core tools ensure the toolkit's reliability and security. - **Sample code**: Includes sample code demonstrating the usage of various tools available in the toolkit. - **Support for Build Variants**: Enables users to customize the toolkit by building it with their preferred versions of each tool. +- **Support Configuration Reusable**: Mounts a config folder on the host to the container.This allows reusing configurations in the container, like AWS and Azure login sessions, ... ## Prerequisites 🔓 @@ -36,8 +37,8 @@ Below is the versioning strategy for the repository and DockerHub: - Repository: `vX.Y.Z`, for example: `v1.2.3` - DockerHub: `X.Y.Z`, for example: `1.2.3`. (Usage: `docker pull tungbq/devops-toolkit:1.2.3`) - Tagging description: - - Specific tag (e.g., v0.1.0, v0.2.3): Contains the latest tooling version and repository features at the time this repository is tagged. - - In addition to that, we offer the latest tag on DockerHub (latest): Contains the latest tooling version and repository features inside the toolkit, which will be built and updated on a weekly basis. + - Specific tag (e.g., `0.1.0`, `0.2.3`): Contains the latest tooling version and repository features at the time this repository is tagged. + - In addition to that, we offer the latest tag on DockerHub (`latest`): Contains the latest tooling version and repository features inside the toolkit, which will be built and updated on a weekly basis. _NOTE_: In the following section, we use the latest tag in the documentation, but you can specify your desired tag based on your needs. @@ -46,19 +47,20 @@ _NOTE_: In the following section, we use the latest tag in the documentation, bu - Use latest tag ```bash -docker run --network host -it --rm tungbq/devops-toolkit:latest +# NOTE: You can replace '~/devops-toolkit-config' path with the desired config folder oin your VM +docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest ``` - Use specific tag ```bash -docker run --network host -it --rm tungbq/devops-toolkit:0.1.0 +docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:0.1.0 ``` ## Demo 📺 ```bash -docker run --network host --rm tungbq/devops-toolkit:latest samples/run_sample.sh +docker run --network host --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest samples/run_sample.sh ``` Check out the full sample and instruction at [**samples**](./samples/) @@ -87,7 +89,7 @@ Once you have the image ready, you can start using the toolkit with the followin - Start devops-toolkit container ```bash -docker run --network host -it --rm tungbq/devops-toolkit:latest +docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest ``` - Now we are in the docker container terminal, let's explore it @@ -104,6 +106,9 @@ root@docker-desktop:~# kubectl version Client Version: v1.29.3 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 +root@docker-desktop:~# aws configure +root@docker-desktop:~# az login --use-device-code + # ... more command as your needed ``` diff --git a/entrypoint.sh b/entrypoint.sh index fd0dbaa..64adcd5 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,36 +4,39 @@ CONFIG_DIR=/config # Function to create symlink if source exists create_symlink() { - local src=$1 - local dest=$2 - if [ -e "$src" ]; then - ln -sf "$src" "$dest" - echo "Symlink created: $src -> $dest" - fi + local src=$1 + local dest=$2 + if [ -e "$src" ]; then + ln -sf "$src" "$dest" + echo "Symlink created: $src -> $dest" + fi } # Check if the /config directory exists and is not empty -if [ -d "$CONFIG_DIR" ] ; then - echo "Custom configuration directory detected. Setting up symlinks..." +if [ -d "$CONFIG_DIR" ]; then + echo "Custom configuration directory detected. Setting up symlinks..." - # TODO: Check and only create if folder does not exist - # mkdir -p /root/.aws /root/.azure /root/.kube /root/.terraform.d/plugins /root/.config/helm /root/.ansible - mkdir -p /config/.aws \ - /config/.azure \ - /config/.kube \ - /config/.terraform.d/ \ - /config/.config/helm \ - /config/.ansible + # TODO: Check and only create if folder does not exist + ## config mount point + mkdir -p /config/.aws \ + /config/.azure \ + /config/.kube \ + /config/.terraform.d \ + /config/.config/helm \ + /config/.ansible - create_symlink "$CONFIG_DIR/.aws" "/root/.aws" - create_symlink "$CONFIG_DIR/.azure" "/root/.azure" - create_symlink "$CONFIG_DIR/.kube" "/root/.kube" - create_symlink "$CONFIG_DIR/.terraform.d/" "/root/.terraform.d/" - create_symlink "$CONFIG_DIR/.helm" "/root/.config/helm" - create_symlink "$CONFIG_DIR/.ansible" "/root/.ansible" - create_symlink "$CONFIG_DIR/.gitconfig" "/root/.gitconfig" + ## root container path + mkdir -p /root/.config/ + + create_symlink "$CONFIG_DIR/.aws" "/root/.aws" + create_symlink "$CONFIG_DIR/.azure" "/root/.azure" + create_symlink "$CONFIG_DIR/.kube" "/root/.kube" + create_symlink "$CONFIG_DIR/.terraform.d" "/root/.terraform.d" + create_symlink "$CONFIG_DIR/.config/helm" "/root/.config/helm" + create_symlink "$CONFIG_DIR/.ansible" "/root/.ansible" + create_symlink "$CONFIG_DIR/.gitconfig" "/root/.gitconfig" else - echo "No custom configuration directory detected. Using default configurations..." + echo "No custom configuration directory detected. Using default configurations..." fi # Execute the provided command From 97382b1dd41f7643a52c9dadb879215fd0949cd9 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 22:59:57 +0700 Subject: [PATCH 5/9] New feature document.part2 --- README.md | 69 +++++++++++++++++++++-------------- docs/usage/ansible_usage.md | 8 ++-- docs/usage/awscli_usage.md | 12 +----- docs/usage/azurecli_usage.md | 16 +------- docs/usage/python_usage.md | 6 +-- docs/usage/run_mode.md | 6 +-- docs/usage/terraform_usage.md | 2 +- 7 files changed, 55 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 29354e5..d2a062a 100644 --- a/README.md +++ b/README.md @@ -46,21 +46,26 @@ _NOTE_: In the following section, we use the latest tag in the documentation, bu - Use latest tag -```bash -# NOTE: You can replace '~/devops-toolkit-config' path with the desired config folder oin your VM -docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest -``` + ```bash + mkdir ~/.devops-toolkit-config + docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest + ``` + + _NOTE_: + + - Note: You can replace `~/.devops-toolkit-config` with any desired folder path on your VM. + - Remove the `-v ~/.devops-toolkit-config:/config` option if you do not wish to store configurations on the host (not recommended for configuration reuse). - Use specific tag -```bash -docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:0.1.0 -``` + ```bash + docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:0.1.0 + ``` ## Demo 📺 ```bash -docker run --network host --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest samples/run_sample.sh +docker run --network host --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest samples/run_sample.sh ``` Check out the full sample and instruction at [**samples**](./samples/) @@ -88,35 +93,45 @@ Once you have the image ready, you can start using the toolkit with the followin - Start devops-toolkit container -```bash -docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest -``` + ```bash + docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest + ``` - Now we are in the docker container terminal, let's explore it -```bash -root@docker-desktop:~# python3 --version -Python 3.12.2 + ```bash + root@docker-desktop:~# python3 --version + Python 3.12.2 -root@docker-desktop:~# terraform --version -Terraform v1.7.5 -on linux_amd64 + root@docker-desktop:~# terraform --version + Terraform v1.7.5 + on linux_amd64 -root@docker-desktop:~# kubectl version -Client Version: v1.29.3 -Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 + root@docker-desktop:~# kubectl version + Client Version: v1.29.3 + Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 -root@docker-desktop:~# aws configure -root@docker-desktop:~# az login --use-device-code + root@docker-desktop:~# aws configure + root@docker-desktop:~# az login --use-device-code -# ... more command as your needed -``` + # ... more command as your needed + ``` + +## User Guide 📖 + +Explore the comprehensive guide below to gain insight into the detailed utilization of every tool within the toolkit. -## User guide 📖 +- Preparation of Configuration Folder on the Host + (It's recommended to mount a config folder from the host into the container for reuse. Skip this step if you do not intend to reuse configurations.) -Explore the comprehensive guide below to gain insight into the detailed utilization of every tool within the toolkit + ```bash + mkdir ~/.devops-toolkit-config + # NOTE: It's recommended to use `~/.devops-toolkit-config` but any folder name on the host can be used. + # For example: /tmp/.demo-config01. Update your `docker run ...` command accordingly. + ``` -- [**DevOps toolkit user guide**](./docs/usage/README.md) +- For detailed instructions on using specific tools, refer to: [**DevOps toolkit specific tool user guide**](./docs/usage/README.md) +- For instructions on common run modes, visit [**DevOps toolkit common run mode**](./docs/usage/run_mode.md) ## The DevOps Toolkit Core 🧰 diff --git a/docs/usage/ansible_usage.md b/docs/usage/ansible_usage.md index 08e36e1..a13052a 100644 --- a/docs/usage/ansible_usage.md +++ b/docs/usage/ansible_usage.md @@ -18,7 +18,7 @@ docker exec -it my_devops_toolkit /bin/bash ## Use case 1: Run Ansible sample code provided in the container ```bash -docker run --rm --network host -it tungbq/devops-toolkit:latest +docker run --rm --network host -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest # You now in the container terminal ansible-playbook samples/ansible/check_os.yml @@ -27,7 +27,7 @@ ansible-playbook samples/ansible/check_os.yml ## Use case 2: Clone external code inside container ```bash -docker run --rm --network host -it tungbq/devops-toolkit:latest +docker run --rm --network host -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest # You now in the container terminal # Now run your cloned script @@ -45,7 +45,7 @@ Clone the code to the host then mount to container ```bash # Given that we have code somewhere in you machine -docker run --rm -v "$(pwd)":/root/ansible_workspace --network host -it tungbq/devops-toolkit:latest +docker run --rm -v "$(pwd)":/root/ansible_workspace --network host -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest # Run the ansible code as usual ``` @@ -55,7 +55,7 @@ Clone the code to the host then mount code and `.ssh` folder to container ```bash # Given that we have code somewhere in you machine -docker run --rm -v ~/.ssh:/root/.ssh -v "$(pwd)":/root/ansible_workspace --network host -it tungbq/devops-toolkit:latest +docker run --rm -v ~/.ssh:/root/.ssh -v "$(pwd)":/root/ansible_workspace --network host -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest # Run the ansible code as usual ``` diff --git a/docs/usage/awscli_usage.md b/docs/usage/awscli_usage.md index a1959c2..d1db7d1 100644 --- a/docs/usage/awscli_usage.md +++ b/docs/usage/awscli_usage.md @@ -22,7 +22,7 @@ docker exec -it my_devops_toolkit /bin/bash ## Use case 1: Configure credentials and list S3 bucket with awscli ```bash -docker run --rm --network host -it tungbq/devops-toolkit:latest +docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest ############################################### # Now we are in the docker container terminal # ############################################### @@ -42,16 +42,6 @@ Default region name [None]: xxxxxxxx Default output format [None]: xxxxxxxx ``` -## Use case 2: Using AWS config from the host - -Mount the `.aws` when running toolkit container - -```bash -docker run --rm --network host -it -v ~/.aws:/root/.aws tungbq/devops-toolkit:latest -# List bucket -aws s3 ls -``` - ## Troubleshooting - For any issues, check [this reference](../troubleshooting/TROUBLESHOOTING.md) diff --git a/docs/usage/azurecli_usage.md b/docs/usage/azurecli_usage.md index 3565e20..de3b560 100644 --- a/docs/usage/azurecli_usage.md +++ b/docs/usage/azurecli_usage.md @@ -21,7 +21,7 @@ docker exec -it my_devops_toolkit /bin/bash ## Use case 1: Az login and run command ```bash -docker run --rm -it tungbq/devops-toolkit:latest +docker run --rm -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest # Login with AZ CLI az login --use-device-code @@ -31,23 +31,9 @@ az login --use-device-code az group list ``` -## Use case 2: Using Azure config from the host - -Mount the `.azure` folder from host when running toolkit container - -```bash -docker run --rm -it -v ~/.azure:/root/.azure tungbq/devops-toolkit:latest -############################################### -# Now we are in the docker container terminal # -############################################### -# List all resource groups -az group list -``` - Sample Result ```bash -➜ ~ docker run --rm -it -v ~/.azure:/root/.azure tungbq/devops-toolkit:latest root@f097467db632:~# az group list [ { diff --git a/docs/usage/python_usage.md b/docs/usage/python_usage.md index 9047b65..8d80551 100644 --- a/docs/usage/python_usage.md +++ b/docs/usage/python_usage.md @@ -19,7 +19,7 @@ docker exec -it my_devops_toolkit /bin/bash ## Use case 1: Run python sample code provided in the container ```bash -docker run --rm --network host -it tungbq/devops-toolkit:latest +docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest # You now in the container terminal python3 samples/python/rectangle_area_calculator.py ``` @@ -27,7 +27,7 @@ python3 samples/python/rectangle_area_calculator.py ## Use case 2: Clone external code inside container ```bash -docker run --rm --network host -it tungbq/devops-toolkit:latest +docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest # You now in the container terminal # Clone code mkdir python_workspace @@ -48,7 +48,7 @@ Clone the code to the host then mount to container ```bash # Given that we have code somewhere in you machine -docker run --rm -v "$(pwd)":/root/python_workspace --network host -it tungbq/devops-toolkit:latest +docker run --rm -v "$(pwd)":/root/python_workspace --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest # Run the python code as usual ``` diff --git a/docs/usage/run_mode.md b/docs/usage/run_mode.md index ed08b5a..7d507bd 100644 --- a/docs/usage/run_mode.md +++ b/docs/usage/run_mode.md @@ -10,7 +10,7 @@ Command: `docker run tungbq/devops-toolkit:`, some of the common - `--rm`: Remove the container after it completes (Ctrl + C or container exit event). - `--network host`: Use the host (VM) network. - `--name `: Assign a name to the container (e.g: `--name demo001`). -- `-v :/config`: Mount a config folder on the host to the container. This allows reusing configurations in the container, like AWS and Azure login sessions (e.g: `-v ~/devops-toolkit-config:/config`, `-v /tmp/devops-toolkit-config-01:/config`). +- `-v :/config`: Mount a config folder on the host to the container. This allows reusing configurations in the container, like AWS and Azure login sessions (e.g: `-v ~/.devops-toolkit-config:/config`, `-v /tmp/devops-toolkit-config-01:/config`). ## Example @@ -47,6 +47,6 @@ docker run --network host -it --name demo001 tungbq/devops-toolkit:latest - Run the image and mount the configuration from the host, and remove the container after it completes: ```bash -mkdir -p ~/devops-toolkit-config # or other location you want to store the configuration -docker run --network host -it --rm -v ~/devops-toolkit-config:/config tungbq/devops-toolkit:latest +mkdir -p ~/.devops-toolkit-config # or other location you want to store the configuration +docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest ``` diff --git a/docs/usage/terraform_usage.md b/docs/usage/terraform_usage.md index e213d29..d2ac276 100644 --- a/docs/usage/terraform_usage.md +++ b/docs/usage/terraform_usage.md @@ -52,7 +52,7 @@ Clone the code to the host then mount to container ```bash # Given that we have code somewhere in you machine -docker run --rm -v "$(pwd)":/root/terraform_workspace --network host -it tungbq/devops-toolkit:latest +docker run --rm -v "$(pwd)":/root/terraform_workspace -v ~/.devops-toolkit-config:/config --network host -it tungbq/devops-toolkit:latest # Run the terraform code as usual ``` From 73f2b8fe1e587c3484aa9170e8c4b7f1c52df227 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 23:08:46 +0700 Subject: [PATCH 6/9] New feature document.part3 --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d2a062a..af1d89c 100644 --- a/README.md +++ b/README.md @@ -51,17 +51,17 @@ _NOTE_: In the following section, we use the latest tag in the documentation, bu docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest ``` - _NOTE_: - - - Note: You can replace `~/.devops-toolkit-config` with any desired folder path on your VM. - - Remove the `-v ~/.devops-toolkit-config:/config` option if you do not wish to store configurations on the host (not recommended for configuration reuse). - - Use specific tag ```bash docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:0.1.0 ``` + _NOTE_: + + - Note: You can replace `~/.devops-toolkit-config` with any desired folder path on your VM. + - Remove the `-v ~/.devops-toolkit-config:/config` option if you do not wish to store configurations on the host (not recommended for configuration reuse). + ## Demo 📺 ```bash @@ -121,15 +121,14 @@ Once you have the image ready, you can start using the toolkit with the followin Explore the comprehensive guide below to gain insight into the detailed utilization of every tool within the toolkit. -- Preparation of Configuration Folder on the Host - (It's recommended to mount a config folder from the host into the container for reuse. Skip this step if you do not intend to reuse configurations.) +- Prepare configuration folder on the Host (Skip this step if you do not intend to reuse configurations.) ```bash mkdir ~/.devops-toolkit-config - # NOTE: It's recommended to use `~/.devops-toolkit-config` but any folder name on the host can be used. - # For example: /tmp/.demo-config01. Update your `docker run ...` command accordingly. ``` + _NOTE:_ We are using `~/.devops-toolkit-config` to store toolkit configurations, but you can choose any folder name on the host. + - For detailed instructions on using specific tools, refer to: [**DevOps toolkit specific tool user guide**](./docs/usage/README.md) - For instructions on common run modes, visit [**DevOps toolkit common run mode**](./docs/usage/run_mode.md) From 31469e974547eadddc43f31aea98dd134ec1f572 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 23:17:05 +0700 Subject: [PATCH 7/9] New feature document.part4 --- docs/usage/helm_usage.md | 4 +--- docs/usage/kubectl_usage.md | 5 ++--- docs/usage/terraform_usage.md | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/usage/helm_usage.md b/docs/usage/helm_usage.md index 473e478..aec7397 100644 --- a/docs/usage/helm_usage.md +++ b/docs/usage/helm_usage.md @@ -21,10 +21,8 @@ docker exec -it my_devops_toolkit /bin/bash ## Use case 1: Deploy an application with Helm -Mount the `.kube/config` file from the host to container (or other kubeconfig files you had) - ```bash -docker run --rm --network host -it -v ~/.kube/config:/root/.kube/config tungbq/devops-toolkit:latest +docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest ############################################### # Now we are in the docker container terminal # ############################################### diff --git a/docs/usage/kubectl_usage.md b/docs/usage/kubectl_usage.md index 07a7a5e..ed222ed 100644 --- a/docs/usage/kubectl_usage.md +++ b/docs/usage/kubectl_usage.md @@ -15,12 +15,12 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` -## Use case 1: Use kubeconfig from the host +## Use case 1: Use kube config from the host Mount the `.kube/config` file from the host to container ```bash -docker run --rm --network host -it -v ~/.kube/config:/root/.kube/config tungbq/devops-toolkit:latest +docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest ############################################### # Now we are in the docker container terminal # ############################################### @@ -38,7 +38,6 @@ kubectl get deployment Sample Result ```bash -➜ ~ docker run --rm --network host -it -v ~/.kube/config:/root/.kube/config tungbq/devops-toolkit:latest root@docker-desktop:~# kubectl get nodes NAME STATUS ROLES AGE VERSION kind-control-plane Ready control-plane 21m v1.29.2 diff --git a/docs/usage/terraform_usage.md b/docs/usage/terraform_usage.md index d2ac276..d8141da 100644 --- a/docs/usage/terraform_usage.md +++ b/docs/usage/terraform_usage.md @@ -18,7 +18,7 @@ docker exec -it my_devops_toolkit /bin/bash ## Use case 1: Run terraform sample code provided in the container ```bash -docker run --rm --network host -it tungbq/devops-toolkit:latest +docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest # You now in the container terminal # Navigate to Terraform sample pushd samples/terraform/basic @@ -34,7 +34,7 @@ popd ## Use case 2: Clone external code inside container ```bash -docker run --rm --network host -it tungbq/devops-toolkit:latest +docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest # You now in the container terminal # Now run your cloned script From 68eb6bea6fb6941c18445e173bf006d61774afa7 Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 23:19:55 +0700 Subject: [PATCH 8/9] New feature document.part5 --- docs/usage/ansible_usage.md | 4 ++++ docs/usage/awscli_usage.md | 4 ++++ docs/usage/azurecli_usage.md | 4 ++++ docs/usage/helm_usage.md | 4 ++++ docs/usage/kubectl_usage.md | 4 ++++ docs/usage/python_usage.md | 4 ++++ docs/usage/terraform_usage.md | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/docs/usage/ansible_usage.md b/docs/usage/ansible_usage.md index a13052a..0458681 100644 --- a/docs/usage/ansible_usage.md +++ b/docs/usage/ansible_usage.md @@ -15,6 +15,10 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` +## Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + ## Use case 1: Run Ansible sample code provided in the container ```bash diff --git a/docs/usage/awscli_usage.md b/docs/usage/awscli_usage.md index d1db7d1..2918ac1 100644 --- a/docs/usage/awscli_usage.md +++ b/docs/usage/awscli_usage.md @@ -19,6 +19,10 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` +## Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + ## Use case 1: Configure credentials and list S3 bucket with awscli ```bash diff --git a/docs/usage/azurecli_usage.md b/docs/usage/azurecli_usage.md index de3b560..1a2b561 100644 --- a/docs/usage/azurecli_usage.md +++ b/docs/usage/azurecli_usage.md @@ -18,6 +18,10 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` +## Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + ## Use case 1: Az login and run command ```bash diff --git a/docs/usage/helm_usage.md b/docs/usage/helm_usage.md index aec7397..1c16403 100644 --- a/docs/usage/helm_usage.md +++ b/docs/usage/helm_usage.md @@ -19,6 +19,10 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` +## Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + ## Use case 1: Deploy an application with Helm ```bash diff --git a/docs/usage/kubectl_usage.md b/docs/usage/kubectl_usage.md index ed222ed..a0cd5a9 100644 --- a/docs/usage/kubectl_usage.md +++ b/docs/usage/kubectl_usage.md @@ -15,6 +15,10 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` +## Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + ## Use case 1: Use kube config from the host Mount the `.kube/config` file from the host to container diff --git a/docs/usage/python_usage.md b/docs/usage/python_usage.md index 8d80551..d266b70 100644 --- a/docs/usage/python_usage.md +++ b/docs/usage/python_usage.md @@ -16,6 +16,10 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` +## Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + ## Use case 1: Run python sample code provided in the container ```bash diff --git a/docs/usage/terraform_usage.md b/docs/usage/terraform_usage.md index d8141da..7d2869f 100644 --- a/docs/usage/terraform_usage.md +++ b/docs/usage/terraform_usage.md @@ -15,6 +15,10 @@ To use the existing container instead of creating one, use `docker exec` command docker exec -it my_devops_toolkit /bin/bash ``` +## Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + ## Use case 1: Run terraform sample code provided in the container ```bash From 91482260ee4f4a8b4e2a1db9e3b8139246bc737f Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sat, 6 Jul 2024 23:28:19 +0700 Subject: [PATCH 9/9] Cleanup dockerfile --- Dockerfile | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6e0be36..b8bc66b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -92,19 +92,6 @@ RUN mkdir -p /etc/apt/keyrings && \ RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* -# # Create the configuration directories inside the container -# RUN mkdir -p /root/.aws /root/.azure /root/.kube /root/.terraform.d/plugins /root/.config/helm /root/.ansible -# RUN mkdir -p /config/.aws /config/.azure /config/.kube /config/.terraform.d/plugins /config/.config/helm /config/.ansible - -# # Set up symlinks (this assumes that the configuration folder is mounted to /config) -# RUN ln -s /config/.aws /root/.aws && \ -# ln -s /config/.azure /root/.azure && \ -# ln -s /config/.kube /root/.kube && \ -# ln -s /config/.terraform.d/plugins /root/.terraform.d/plugins && \ -# ln -s /config/.helm /root/.config/helm && \ -# ln -s /config/.ansible /root/.ansible && \ -# ln -s /config/.gitconfig /root/.gitconfig - # Set the working directory WORKDIR /root