This Dockerfile is designed to build and deploy the mailculator processor
application using three distinct stages:
- Builder Stage
- Development Stage
- Production Stage
Each stage serves a specific purpose, and you can use them based on your needs.
Purpose: This stage is responsible for building the Go application, running tests, and preparing it for further stages (Development or Production).
Description:
- The base image used is
golang:1.23
. - The
mailculator processor
project is copied into the container and the necessary dependencies are downloaded usinggo mod tidy
andgo mod download
. - The tests are run with
go test ./...
to ensure everything is correct. - The application is built with
go build
and the resulting binary is copied to/usr/local/bin/mailculator-processor
in a file calleddaemon
. - Finally, the binary is made executable with
chmod +x
.
To build the image:
docker build --no-cache -t mailculatorp-builder --target mailculatorp-builder .
To introspect the builder image:
docker run -ti --rm mailculatorp-builder bash
Purpose: This stage is used for local development.
Description:
The base image used is golang:1.23. The binary generated in the builder stage is copied into this container. To build the image:
docker build --no-cache -t mailculatorp-dev --target mailculatorp-dev .
If you want to generate some dummy data:
sudo chown -R "$(whoami):$(id -gn)" ./data && ./data/maildir/dummy-gen.sh
To run the development container:
docker run --rm -p9090:9090 -v$(pwd)/data:/var/lib/mailculator-processor mailculatorp-dev
To access Prometheus
live stats click here.
Purpose: This stage is optimized for production deployment. It creates a minimal container to run the mailculator processor binary in a secure and efficient environment.
Description:
The base image used is gcr.io/distroless/base-debian12, which is a minimal image without unnecessary tools or packages. The binary from the builder stage is copied into the container. The container is configured to run the mailculator processor binary. To build the image:
docker build --no-cache -t mailculatorp-prod --target mailculatorp-prod .
To run the production container:
docker run --rm mailculatorp-prod