A lightweight Go development environment
[TOC]
This repository allows to create a Docker services and/or microservices built with Go.
The Docker image is based on golang:alpine in order to keep images as much lightweight as possible.
- Unified environment to build CLI or web applications with Go.
- Allows to create production-grade Docker images based on Alpine and/or Scratch.
To use this repository it is required:
- Docker - An open source containerization platform.
- Git - The free and open source distributed version control system.
Type | Component | Description |
---|---|---|
Infrastructure | Docker | Containerization platform |
Service | Go | Build simple, secure, scalable systems with Go |
Miscelaneous | Bash | Allows to create an interactive shell within main service |
Miscelaneous | Make | Allows to execute commands defined on a Makefile |
Just clone the repository into your preferred path:
$ mkdir -p ~/path/to/my-new-project && cd ~/path/to/my-new-project
$ git clone [email protected]:fonil/dockerized-go-dev-env.git .
Your application will be placed in ./src folder.
Folder | Description |
---|---|
./src | The src directory contains the source code of your application. |
./targets | The targets directory contains the Makefile partials organized by task. |
If you take a look to docker-compose.yml#L14 this folder is mounted as a volume into the application container. With this setup you are able to modify the source code of your application, within your preferred IDE, on your host and automatically have those changes in the container π
A Makefile is provided with some predefined commands:
~/path/to/my-new-project$ make
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β .: AVAILABLE COMMANDS :. β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Β· version Application: displays the Go Version
Β· init Application: initialized the Go module
Β· tidy Application: add module requirements and sum
Β· dependencies Application: list application dependencies
Β· test Application: executes the test suite
Β· format Application: fix source code format
Β· run Application: executes the main script
Β· compile Application: build the application binary file
Β· execute Application: executes the binary script
Β· execute-production Application: executes the binary script from production image
Β· build-scratch Docker: builds the service for production environment
Β· build-alpine Docker: builds the service for production environment
Β· build Docker: builds the service
Β· down Docker: stops the service
Β· up Docker: starts the service
Β· logs Docker: exposes the service logs
Β· restart Docker: restarts the service
Β· bash Docker: stablish a bash session into main container
~/path/to/my-new-project$ make build
It is important to use make build
command instead of docker-compose build
to create the Docker base image. The reason why is because the Makefile command passes to Dockerfile
your host account details, required to create an internal user into the application container with the same name, group and ids.
This way avoids file permission conflicts on internally created files that needs to be shared with the host.
~/path/to/my-new-project$ make up
~/path/to/my-new-project$ make init
~/path/to/my-new-project$ make run
This command executes the application by running
go run main.go
~/path/to/my-new-project$ make compile
~/path/to/my-new-project$ make execute
This command executes the application by running
docker-compose exec --workdir=/go/bin app ...
~/path/to/my-new-project$ make down
~/path/to/my-new-project$ make format
~/path/to/my-new-project$ make test
~/path/to/my-new-project$ make build-alpine
This command builds a production-grade Docker image containing the application binary file(s).
~/path/to/my-new-project$ make build-scratch
This command builds a production-grade Docker image containing the application binary file(s).
~/path/to/my-new-project$ make execute-production
This command executes the service from the recently created production-grade Docker image.
Please review our security policy on how to report security vulnerabilities:
PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY
Only the latest major version receives security fixes.
If you discover a security vulnerability within this project, please open an issue here. All security vulnerabilities will be promptly addressed.
The MIT License (MIT). Please see LICENSE file for more information.