Skip to content

Commit e4dd9a9

Browse files
authored
Merge pull request #1 from HomeDevopsLab/initial-version
Adding dockerfile
2 parents e036cae + 53ba480 commit e4dd9a9

3 files changed

Lines changed: 295 additions & 0 deletions

File tree

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: docker.io
15+
IMAGE_NAME: iac-tools
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to Docker Hub
32+
if: startsWith(github.ref, 'refs/tags/')
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ secrets.DOCKERHUB_USERNAME }}
37+
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
39+
- name: Extract metadata
40+
if: startsWith(github.ref, 'refs/tags/')
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=pr
48+
type=semver,pattern={{version}}
49+
type=semver,pattern={{major}}.{{minor}}
50+
type=semver,pattern={{major}}
51+
type=raw,value=latest,enable={{is_default_branch}}
52+
type=sha,prefix={{branch}}-
53+
54+
- name: Build and push Docker image
55+
if: startsWith(github.ref, 'refs/tags/')
56+
uses: docker/build-push-action@v5
57+
with:
58+
context: .
59+
platforms: linux/amd64,linux/arm64
60+
push: ${{ github.event_name != 'pull_request' }}
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
cache-from: type=gha
64+
cache-to: type=gha,mode=max
65+
66+
test:
67+
runs-on: ubuntu-latest
68+
needs: build
69+
if: github.event_name == 'pull_request'
70+
71+
steps:
72+
- name: Checkout repository
73+
uses: actions/checkout@v4
74+
75+
- name: Set up Docker Buildx
76+
uses: docker/setup-buildx-action@v3
77+
78+
- name: Build test image
79+
uses: docker/build-push-action@v5
80+
with:
81+
context: .
82+
load: true
83+
tags: test-image
84+
cache-from: type=gha
85+
86+
- name: Test Terraform
87+
run: |
88+
echo "Testing Terraform installation..."
89+
docker run --rm test-image terraform --version
90+
91+
- name: Test Terragrunt
92+
run: |
93+
echo "Testing Terragrunt installation..."
94+
docker run --rm test-image terragrunt --version
95+
96+
- name: Test Ansible
97+
run: |
98+
echo "Testing Ansible installation..."
99+
docker run --rm test-image ansible --version
100+
101+
- name: Test Git
102+
run: |
103+
echo "Testing Git installation..."
104+
docker run --rm test-image git --version
105+
106+
security-scan:
107+
runs-on: ubuntu-latest
108+
needs: build
109+
if: github.event_name == 'pull_request'
110+
permissions:
111+
contents: read
112+
security-events: write
113+
114+
steps:
115+
- name: Checkout repository
116+
uses: actions/checkout@v4
117+
118+
- name: Set up Docker Buildx
119+
uses: docker/setup-buildx-action@v3
120+
121+
- name: Build image for scanning
122+
uses: docker/build-push-action@v5
123+
with:
124+
context: .
125+
load: true
126+
tags: scan-image
127+
cache-from: type=gha
128+
129+
- name: Run Trivy vulnerability scanner
130+
uses: aquasecurity/trivy-action@master
131+
with:
132+
image-ref: "scan-image"
133+
format: "sarif"
134+
output: "trivy-results.sarif"
135+
136+
- name: Upload Trivy scan results to GitHub Security tab
137+
uses: github/codeql-action/upload-sarif@v3
138+
if: always()
139+
with:
140+
sarif_file: "trivy-results.sarif"

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM ubuntu:24.04
2+
LABEL maintainer="Krzysztof Królikowski <kkrolikowski@gmail.com>"
3+
LABEL description="Docker image for a basic Ubuntu setup with IAC tools"
4+
LABEL version="1.0"
5+
6+
ENV DEBIAN_FRONTEND="noninteractive"
7+
ENV TERRAGRUNT_VERSION="v0.77.22"
8+
ENV TF_VERSION="1.11.4"
9+
ENV ARCH="amd64"
10+
ENV OS="linux"
11+
ENV BINARY_NAME="terragrunt_${OS}_${ARCH}"
12+
ENV PATH="$PATH:/root/.local/bin"
13+
14+
RUN apt-get update && \
15+
apt-get install -y \
16+
git \
17+
curl \
18+
unzip \
19+
pipx && \
20+
rm -rf /var/lib/apt/lists/*
21+
RUN curl -L "https://github.com/gruntwork-io/terragrunt/releases/download/${TERRAGRUNT_VERSION}/${BINARY_NAME}" -o "${BINARY_NAME}" && \
22+
chmod +x "${BINARY_NAME}" && \
23+
mv "${BINARY_NAME}" /usr/local/bin/terragrunt
24+
RUN curl -L "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_${OS}_${ARCH}.zip" -o terraform.zip && \
25+
unzip terraform.zip && \
26+
mv terraform /usr/local/bin/ && \
27+
rm terraform.zip && \
28+
chmod +x /usr/local/bin/terraform
29+
RUN pipx install --include-deps ansible

README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# IAC Tools Docker Image
2+
3+
A Docker image containing essential Infrastructure as Code (IAC) tools for automating infrastructure management and deployment.
4+
5+
## Overview
6+
7+
This Docker image is based on Ubuntu 24.04 and includes popular IAC tools commonly used in DevOps workflows:
8+
9+
- **Terraform** - Infrastructure provisioning tool
10+
- **Terragrunt** - Terraform wrapper for managing multiple environments
11+
- **Ansible** - Configuration management and automation tool
12+
13+
## Included Tools
14+
15+
| Tool | Version | Description |
16+
| ---------- | -------- | ------------------------------------------------------------------------------------------------ |
17+
| Terraform | 1.11.4 | Infrastructure as Code tool for building, changing, and versioning infrastructure |
18+
| Terragrunt | v0.77.22 | Thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules |
19+
| Ansible | Latest | Automation platform for configuration management, application deployment, and task automation |
20+
21+
## Additional Packages
22+
23+
- Git - Version control system
24+
- Curl - Command line tool for transferring data
25+
- Unzip - Archive extraction utility
26+
- Pipx - Tool for installing and running Python applications in isolated environments
27+
28+
## Usage
29+
30+
### Pull the image
31+
32+
```bash
33+
# From Docker Hub (after CI/CD setup)
34+
docker pull <your-dockerhub-username>/iac-tools:latest
35+
36+
# Or build locally
37+
docker build -t iac-tools:latest .
38+
```
39+
40+
### Run the container
41+
42+
```bash
43+
# Interactive shell
44+
docker run -it --rm iac-tools:latest /bin/bash
45+
46+
# Mount your workspace
47+
docker run -it --rm -v $(pwd):/workspace -w /workspace iac-tools:latest /bin/bash
48+
49+
# Run specific commands
50+
docker run --rm -v $(pwd):/workspace -w /workspace iac-tools:latest terraform --version
51+
docker run --rm -v $(pwd):/workspace -w /workspace iac-tools:latest terragrunt --version
52+
docker run --rm -v $(pwd):/workspace -w /workspace iac-tools:latest ansible --version
53+
```
54+
55+
### Docker Compose
56+
57+
You can also use this image with Docker Compose:
58+
59+
```yaml
60+
version: "3.8"
61+
services:
62+
iac-tools:
63+
image: iac-tools:latest
64+
volumes:
65+
- .:/workspace
66+
working_dir: /workspace
67+
stdin_open: true
68+
tty: true
69+
```
70+
71+
## Building the Image
72+
73+
### Local Build
74+
To build the image locally:
75+
76+
```bash
77+
docker build -t iac-tools:latest .
78+
```
79+
80+
### Automated CI/CD
81+
This repository includes a GitHub Actions workflow that automatically:
82+
- Builds multi-platform Docker images (amd64/arm64) on every push
83+
- Tests all included tools (Terraform, Terragrunt, Ansible, Git)
84+
- Performs security vulnerability scanning
85+
- Publishes to Docker Hub on main branch and tags
86+
87+
See [GITHUB_ACTIONS_SETUP.md](GITHUB_ACTIONS_SETUP.md) for detailed setup instructions.
88+
89+
## Environment Variables
90+
91+
- `DEBIAN_FRONTEND=noninteractive` - Prevents interactive prompts during package installation
92+
- `TERRAGRUNT_VERSION=v0.77.22` - Specifies the Terragrunt version to install
93+
- `TF_VERSION=1.11.4` - Specifies the Terraform version to install
94+
- `ARCH=amd64` - Target architecture
95+
- `OS=linux` - Target operating system
96+
- `PATH` - Includes `/root/.local/bin` for pipx-installed tools
97+
98+
## Use Cases
99+
100+
This image is ideal for:
101+
102+
- CI/CD pipelines requiring infrastructure automation
103+
- Development environments for IAC workflows
104+
- Consistent tooling across different environments
105+
- Containerized infrastructure deployments
106+
- Learning and experimenting with IAC tools
107+
108+
## Security
109+
110+
- The image runs as root user (default for this use case)
111+
- Base image is Ubuntu 24.04 with latest security updates
112+
- Only essential packages are installed to minimize attack surface
113+
114+
## Maintenance
115+
116+
- **Maintainer**: Krzysztof Królikowski <kkrolikowski@gmail.com>
117+
- **Version**: 1.0
118+
- **Base Image**: Ubuntu 24.04
119+
120+
## License
121+
122+
See the [LICENSE](LICENSE) file for license information.
123+
124+
## Contributing
125+
126+
Feel free to submit issues and enhancement requests!

0 commit comments

Comments
 (0)