Skip to content
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
6 changes: 6 additions & 0 deletions .github/workflows/docker-image-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'Dockerfile'
- 'scripts/*'
- '.github/workflows/*'
- 'samples/'

jobs:
build:
Expand All @@ -26,3 +27,8 @@ jobs:
cd scripts
chmod +x check_version_in_toolkit.sh
./check_version_in_toolkit.sh "devops-toolkit-review:$GITHUB_SHA" "../toolkit_info.json"

- name: Running Sample Tool Code
run: |
echo "Run sample tool code inside toolkit"
docker run --rm devops-toolkit-review:$GITHUB_SHA samples/run_sample.sh
5 changes: 5 additions & 0 deletions .github/workflows/docker-image-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
chmod +x check_version_in_toolkit.sh
./check_version_in_toolkit.sh "devops-toolkit-merge:$GITHUB_SHA" "../toolkit_info.json"

- name: Running Sample Tool Code
run: |
echo "Run sample tool code inside toolkit"
docker run --rm devops-toolkit-merge:$GITHUB_SHA samples/run_sample.sh

- name: Push Docker Image
run: |
SHA7=${GITHUB_SHA::7}
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,17 @@ RUN mkdir -p /etc/apt/keyrings && \
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Reset environment variables
ENV DEBIAN_FRONTEND teletype
ENV TZ=""

# Set the working directory
WORKDIR /root

# Adding tooling samples
COPY samples/ /root/samples/
RUN chmod +x /root/samples/run_sample.sh

# Reset environment variables
ENV DEBIAN_FRONTEND teletype
ENV TZ=""

# Define the default command to run when the container starts
CMD ["/bin/bash"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Before you begin, make sure you have [Docker](https://docs.docker.com/engine/ins

## Build your own image

_NOTE:_ If you'd refer using the official prebuilt docker image from DockerHub, you can skip this section!
**NOTE:** If you'd refer using the official prebuilt docker image from DockerHub, you can skip this section!
Jump to [Use Docker Hub image](https://github.com/tungbq/devops-toolkit?tab=readme-ov-file#use-the-official-image-from-docker-hub) for instead.

**1. Clone the Repository:**
Expand Down Expand Up @@ -98,6 +98,14 @@ docker run --rm devops-toolkit:latest python3 --version
docker run --rm devops-toolkit:latest ansible --version
```

## Running Sample Tool Code Inside the Toolkit

Check out the full samples and instruction at [samples](./samples/)

```bash
docker run --rm devops-toolkit:latest samples/run_sample.sh
```

## The DevOps Toolkit Core

Built on `ubuntu:22.04` base image
Expand Down
57 changes: 57 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Sample code for tools inside toolkit

## First step

Start and dive into the container

```bash
docker run -it --rm devops-toolkit:latest
```

Congrats! You now in the container and able to run the tooling sample inside toolkit, the console will look like:

```bash
root@05cf97a07b19:~#
```

## Python

```bash
python3 samples/python/rectangle_area_calculator.py
````

## Ansible

```bash
ansible-playbook samples/ansible/check_os.yml
```

## Terraform

```bash
# Navigate to Terraform sample
pushd samples/terraform/basic
# Init the terraform
terraform init
# Apply change, select 'yes' to confirm
terraform apply
# Once done, destroy the infra, select 'yes' to confirm
terraform destroy
popd
```

## Kubectl

- TODO

## Helm

- TODO

## AwsCLI

- TODO

## AzureCLI

- TODO
10 changes: 10 additions & 0 deletions samples/ansible/check_os.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Check OS Version on Localhost
hosts: localhost
tasks:
- name: Gather facts
ansible.builtin.setup:

- name: Print OS version
ansible.builtin.debug:
msg: "The OS version is {{ ansible_distribution }} {{ ansible_distribution_version }}"
30 changes: 30 additions & 0 deletions samples/python/rectangle_area_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def calculate_rectangle_area(length, width):
"""
Calculate the area of a rectangle.

Args:
- length (float): Length of the rectangle.
- width (float): Width of the rectangle.

Returns:
- float: The calculated area of the rectangle.
"""
print("Length:", length)
print("Width:", width)

area = length * width
return area

def main():
# Define length and width of the rectangle
length = 5.0
width = 3.0

# Calculate the area of the rectangle
area = calculate_rectangle_area(length, width)

# Display the result
print("The area of the rectangle is:", area)

if __name__ == "__main__":
main()
47 changes: 47 additions & 0 deletions samples/run_sample.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# Define color variables
GREEN='\033[0;32m' # Green color
NC='\033[0m' # No color (reset)

# Function to log messages with INFO prefix in green color
console_log() {
message=$1
echo -e "${GREEN}[INFO] $message ${NC}"
}

###########
# Python
###########
console_log "Running Python sample: rectangle_area_calculator.py"
python3 samples/python/rectangle_area_calculator.py

###########
# Ansible
###########
console_log "Running Ansible sample: check_os.yml"
ansible-playbook samples/ansible/check_os.yml

###########
# Terraform
###########
console_log "Running Terraform sample: basic"
pushd samples/terraform/basic || exit
terraform init
terraform apply -auto-approve
terraform destroy -auto-approve
popd || exit

###########
# Kubectl
###########
console_log "Running Kubectl sample: check version"
kubectl version

###########
# Helm
###########
console_log "Running Helm sample: add and search"
helm repo add bitnami https://charts.bitnami.com/bitnami
helm search repo bitnami | grep jenkins

5 changes: 5 additions & 0 deletions samples/terraform/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "null_resource" "local_command" {
provisioner "local-exec" {
command = "echo Hello, Terraform!"
}
}