GO-Docker-AI is a tool written in Go designed to analyze and lint Dockerfiles, providing suggestions and corrections to improve the quality and efficiency of Docker images.
- Static analysis of Dockerfiles.
- Suggestions for optimization and fixing common mistakes.
- NOT YET: Multi-platform support, FOR NOW WE ONLY SUPPORT "linux amd64"
- No external dependencies: standalone binary.
- Integration with OpenAI for advanced suggestions.
- Creation of base Dockerfile based on best practices.
- Go 1.20 or later.
- Operating System:
- Linux
- NOT YET: Windows
- NOT YET: macOS
- Docker (optional for testing).
- OpenAI API Key (required for functionality).
Before running the tool, export your OpenAI API key as an environment variable:
export OPENAI_API_KEY=your_openai_key
Make sure to replace your_openai_key
with your actual OpenAI API key.
git clone https://github.com/la-plas-growth/go-docker-ai.git
cd go-docker-ai
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -a -o go-docker-ai-linux-amd64 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -a -o go-docker-ai-linux-arm64 .
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -a -o go-Docker-ai-windows-amd64 .
You can also use the build.sh
script to generate binaries for all supported platforms:
sh build.sh
- Download the precompiled binary from the releases section.
- Add the binary to your
$PATH
or execute it directly.
Run the following command to analyze a Dockerfile:
./go-docker-ai-linux-amd64 dockerfile lint -f /path/to/Dockerfile
Example output:
{
issues": [
{
"issue": "Using a large base image without necessity.",
"severity": "high",
"advice": "Consider using a leaner base image, such as `alpine` without glibc dependencies, to minimize the size and security risks."
},
{
"issue": "Base image version is mutable and not pinned.",
"severity": "medium",
"advice": "It's advisable to pin the base image version using a specific digest instead of just `alpine-3.9_glibc-2.29` to avoid potential issues with future updates."
},
{
"issue": "No explicit update before package installation.",
"severity": "medium",
"advice": "Run `apk update` before installing packages to ensure you're getting the latest available versions of packages."
}
]
}
Run the followinf command to create a base Dockerfile:
./go-docker-ai-linux-amd64 dockerfile create -t golang
Output: the file will be created in the folder where the command is been executed
Command | Description |
---|---|
dockerfile create -t <lang> -p <path> |
Create a base dockerfile in any language |
dockerifle lint -f <file> |
Lint the specified Dockerfile. |
version |
Show the tool version. |
help |
Display available commands. |
If you want to contribute or customize the project, make sure you have Go installed. Use the following commands to start the project in development mode:
-
Install dependencies:
go mod tidy
-
Run tests:
go test ./...
-
Start the tool:
go run main.go <command> <arg>
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a branch for your feature/bugfix:
git checkout -b my-feature
- Commit your changes:
git commit -m "Description of the change"
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
For questions or issues, open an issue or contact:
- Author: la-plas-growth
- Author: Allan-Nava