Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable toolkit container configuration reusable #186

Merged
merged 9 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,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"]
79 changes: 51 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🔓

Expand All @@ -36,29 +37,39 @@ 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.

## Quick start 🔥

```bash
# Use latest tag
docker run --network host -it --rm tungbq/devops-toolkit:latest
- Use latest tag

# Use specific tag
docker run --network host -it --rm tungbq/devops-toolkit:0.1.0
```
```bash
mkdir ~/.devops-toolkit-config
docker run --network host -it --rm -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest
```

## Demo 📺
- Use specific tag

Check out the full sample and instruction at [**samples**](./samples/)
```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
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/)

## Getting started 📖

### Pull the official image from Docker Hub
Expand All @@ -82,32 +93,44 @@ 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
```
```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

# ... more command as your needed
```
root@docker-desktop:~# aws configure
root@docker-desktop:~# az login --use-device-code

# ... 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.

- Prepare configuration folder on the Host (Skip this step if you do not intend to reuse configurations.)

## User guide 📖
```bash
mkdir ~/.devops-toolkit-config
```

Explore the comprehensive guide below to gain insight into the detailed utilization of every tool within the toolkit
_NOTE:_ We are using `~/.devops-toolkit-config` to store toolkit configurations, but you can choose any folder name on the host.

- [**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 🧰

Expand Down
12 changes: 8 additions & 4 deletions docs/usage/ansible_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ 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
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
Expand All @@ -27,7 +31,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
Expand All @@ -45,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 -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
```

Expand All @@ -55,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 -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
```

Expand Down
16 changes: 5 additions & 11 deletions docs/usage/awscli_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ 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
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 #
###############################################
Expand All @@ -42,16 +46,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)
23 changes: 8 additions & 15 deletions docs/usage/azurecli_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,26 @@ 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
docker run --rm -it tungbq/devops-toolkit:latest
## To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code <SHOWN_IN_SCREEN> to authenticate
az login
# List all resource groups
az group list
```

## Use case 2: Using Azure config from the host
docker run --rm -it -v ~/.devops-toolkit-config:/config tungbq/devops-toolkit:latest

Mount the `.azure` folder from host when running toolkit container
# 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 <SHOWN_IN_SCREEN> to authenticate

```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
[
{
Expand Down
8 changes: 5 additions & 3 deletions docs/usage/helm_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ To use the existing container instead of creating one, use `docker exec` command
docker exec -it my_devops_toolkit /bin/bash
```

## Use case 1: Deploy an application with Helm
## Common Run Modes

For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md).

Mount the `.kube/config` file from the host to container (or other kubeconfig files you had)
## Use case 1: Deploy an application with Helm

```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 #
###############################################
Expand Down
9 changes: 6 additions & 3 deletions docs/usage/kubectl_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ 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
## 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

```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 #
###############################################
Expand All @@ -38,7 +42,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
Expand Down
10 changes: 7 additions & 3 deletions docs/usage/python_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ 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
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
```

## 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
Expand All @@ -48,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 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
```

Expand Down
52 changes: 52 additions & 0 deletions docs/usage/run_mode.md
Original file line number Diff line number Diff line change
@@ -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 <RUN_OPTS> tungbq/devops-toolkit:<TAG>`, 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 <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`).

## 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
```
Loading