Skip to content

Commit

Permalink
Improve the devops toolkit configuration path name (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
tungbq authored Aug 17, 2024
1 parent 99319c0 commit d37889e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 34 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@ _NOTE_: In the following section, we use the latest tag in the documentation, bu
- Use latest tag

```bash
mkdir -p ~/.devops-toolkit-config
docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
mkdir -p ~/.dtc
docker run --network host -it --rm -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
```

- Use specific tag

```bash
docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:0.1.0
docker run --network host -it --rm -v ~/.dtc:/dtc tungbq/devops-toolkit:0.1.0
```

- _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).
- You can replace `~/.dtc` with any desired folder path on your VM.
- Remove the `-v ~/.dtc:/dtc` option if you do not wish to store configurations on the host (not recommended for configuration reuse).

## 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 ~/.dtc:/dtc tungbq/devops-toolkit:latest samples/run_sample.sh
```

Check out the full sample and instruction at [**samples**](./samples/)
Expand Down Expand Up @@ -93,7 +93,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 -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --network host -it --rm -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
```

- Now we are in the docker container terminal, let's explore it
Expand Down Expand Up @@ -123,10 +123,10 @@ Explore the comprehensive guide below to gain insight into the detailed utilizat
- Prepare configuration folder on the Host (Skip this step if you do not intend to reuse configurations.)

```bash
mkdir ~/.devops-toolkit-config
mkdir ~/.dtc
```

_NOTE:_ We are using `~/.devops-toolkit-config` to store toolkit configurations, but you can choose any folder name on the host.
_NOTE:_ We are using `~/.dtc` 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)
Expand Down
8 changes: 4 additions & 4 deletions docs/usage/ansible_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**]
## Use case 1: Run Ansible sample code provided in the container

```bash
docker run --rm --network host -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest
docker run --rm --network host -v ~/.dtc:/dtc -it tungbq/devops-toolkit:latest

# You now in the container terminal
ansible-playbook samples/ansible/check_os.yml
Expand All @@ -31,7 +31,7 @@ ansible-playbook samples/ansible/check_os.yml
## Use case 2: Clone external code inside container

```bash
docker run --rm --network host -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest
docker run --rm --network host -v ~/.dtc:/dtc -it tungbq/devops-toolkit:latest
# You now in the container terminal

# Now run your cloned script
Expand All @@ -49,7 +49,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 -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest
docker run --rm -v "$(pwd)":/root/ansible_workspace --network host -v ~/.dtc:/dtc -it tungbq/devops-toolkit:latest
# Run the ansible code as usual
```

Expand All @@ -59,7 +59,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 -v ~/.devops-toolkit-config:/config -it tungbq/devops-toolkit:latest
docker run --rm -v ~/.ssh:/root/.ssh -v "$(pwd)":/root/ansible_workspace --network host -v ~/.dtc:/dtc -it tungbq/devops-toolkit:latest
# Run the ansible code as usual
```

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/awscli_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**]
## Use case 1: Configure credentials and list S3 bucket with awscli

```bash
docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
###############################################
# Now we are in the docker container terminal #
###############################################
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/azurecli_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**]
## Use case 1: Az login and run command

```bash
docker run --rm -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest

# Login with AZ CLI
az login --use-device-code
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/helm_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**]
## Use case 1: Deploy an application with Helm

```bash
docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
###############################################
# Now we are in the docker container terminal #
###############################################
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/kubectl_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**]
Mount the `.kube/config` file from the host to container

```bash
docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
###############################################
# Now we are in the docker container terminal #
###############################################
Expand Down
6 changes: 3 additions & 3 deletions docs/usage/python_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**]
## Use case 1: Run python sample code provided in the container

```bash
docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
# You now in the container terminal
python3 samples/python/rectangle_area_calculator.py
```

## Use case 2: Clone external code inside container

```bash
docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
# You now in the container terminal
# Clone code
mkdir python_workspace
Expand All @@ -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/python_workspace --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm -v "$(pwd)":/root/python_workspace --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
# Run the python code as usual
```

Expand Down
6 changes: 3 additions & 3 deletions docs/usage/run_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Command: `docker run <RUN_OPTS> tungbq/devops-toolkit:<TAG>`, 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 <CONTAINER_NAME>`: Assign a name to the container (e.g: `--name demo001`).
- `-v <ABS_PATH_ON_THE_HOST>:/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 <ABS_PATH_ON_THE_HOST>:/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 ~/.dtc:/dtc`, `-v /tmp/devops-toolkit-config-01:/config`).

## Example

Expand Down Expand Up @@ -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 ~/.dtc # or other location you want to store the configuration
docker run --network host -it --rm -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
```
6 changes: 3 additions & 3 deletions docs/usage/terraform_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**]
## Use case 1: Run terraform sample code provided in the container

```bash
docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
# You now in the container terminal
# Navigate to Terraform sample
pushd samples/terraform/basic
Expand All @@ -38,7 +38,7 @@ popd
## Use case 2: Clone external code inside container

```bash
docker run --rm --network host -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest
# You now in the container terminal

# Now run your cloned script
Expand All @@ -56,7 +56,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 -v ~/.devops-toolkit-config:/config --network host -it tungbq/devops-toolkit:latest
docker run --rm -v "$(pwd)":/root/terraform_workspace -v ~/.dtc:/dtc --network host -it tungbq/devops-toolkit:latest
# Run the terraform code as usual
```

Expand Down
17 changes: 9 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

CONFIG_DIR=/config
# NOTE: 'dtc' stands for devops toolkit configuration
CONFIG_DIR=/dtc

# Function to create symlink if source exists
create_symlink() {
Expand All @@ -12,18 +13,18 @@ create_symlink() {
fi
}

# Check if the /config directory exists and is not empty
# Check if the /dtc 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
## config mount point
mkdir -p /config/.aws \
/config/.azure \
/config/.kube \
/config/.terraform.d \
/config/.config/helm \
/config/.ansible
mkdir -p /dtc/.aws \
/dtc/.azure \
/dtc/.kube \
/dtc/.terraform.d \
/dtc/.config/helm \
/dtc/.ansible

## root container path
mkdir -p /root/.config/
Expand Down

0 comments on commit d37889e

Please sign in to comment.