This documentation provides a step-by-step guide for configuring and using Docker within the development environment of the Slim Toolkit (github.com/slimtoolkit/slim
). This guide is aimed at expert developers familiar with Docker and Go.
Dockerfile Overview
The Dockerfile is a key component of the Slim development process. It is responsible for setting up the environment in which the Go application is built and tested. Below is a breakdown of the Dockerfile used in the Slim toolkit.
WORKDIR /go/src
# Set property for golangci-lint version
ARG GOLANGCILINT_VERSION=v1.24.0
# Install golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCILINT_VERSION}
# Install ltag tool
RUN go get -v -u github.com/kunalkushwaha/ltag && rm -rf /go/src/github.com/kunalkushwaha
# Copy project files
COPY . .
Breakdown of the Dockerfile Steps
Setting the Working Directory
TheWORKDIR /go/src
command sets the working directory. All subsequent commands will be executed in this directory.Building Arguments
TheARG GOLANGCILINT_VERSION
line defines a build argument to specify the version ofgolangci-lint
that will be installed.Installing golangci-lint
TheRUN
directive usescurl
to fetch the installation script forgolangci-lint
and executes it. This linter is helpful for maintaining code quality within the project.Installing ltag Tool
AnotherRUN
directive installs theltag
tool, which may be used for managing version tags in Go applications. The unnecessary files are removed afterward to keep the image clean.Copying Project Files
TheCOPY . .
command copies all files from the current directory into the working directory of the Docker image. This is essential for building the project.
Makefile Functions
The Makefile provides several targets to simplify the development workflow. Here are key commands relevant to Docker:
build_in_docker
This target allows you to build the Go application within a Docker container. You can define it in your Makefile as follows:build_in_docker: docker build -t slim-toolkit .
build_dev
This target can be utilized for building the application for development purposes. Add this target to your Makefile:build_dev: go build -o slim-toolkit github.com/slimtoolkit/slim
test
For running tests, including those with the “e2e” build constraint defined, you might structure your Makefile like so:test: go test -tags=e2e ./...
Example Usage
To effectively leverage Docker within your development process with the Slim Toolkit, follow these steps:
Build the Docker Image
Use thebuild_in_docker
target from your Makefile.make build_in_docker
Run Tests in Docker
Depending on how your tests are structured and if you are utilizing the defined “e2e” constraint, execute:make test
Cleanup
Maintain a clean environment by using theclean
target, which you can define as:clean: rm -rf slim-toolkit
Conclusion
Docker configuration in the Slim Toolkit development environment streamlines the setup and testing of the application. By employing the Dockerfile and Makefile effectively, expert developers can maintain an efficient development process.
References
- Source: Dockerfile and Makefile of Slim Toolkit (
github.com/slimtoolkit/slim
).