Skip to content

fonil/dockerized-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dockerized Go Development Environment

A lightweight Go development environment

[TOC]

Summary

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.

Highlights

  • Unified environment to build CLI or web applications with Go.
  • Allows to create production-grade Docker images based on Alpine and/or Scratch.

Requirements

To use this repository it is required:

  • Docker - An open source containerization platform.
  • Git - The free and open source distributed version control system.

Built with

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

Getting Started

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 .

Conventions

Application

Your application will be placed in ./src folder.

Directory structure

The Root Directory
Folder Description
./src The src directory contains the source code of your application.
./targets The targets directory contains the Makefile partials organized by task.
The ./src Directory

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 πŸ˜ƒ

Available commands

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

Development

Build the service
~/path/to/my-new-project$ make build
About make build command

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.

Start the service
~/path/to/my-new-project$ make up
Initialize the Go module
~/path/to/my-new-project$ make init
Run the business application logic
~/path/to/my-new-project$ make run

This command executes the application by running go run main.go

Compile the application
~/path/to/my-new-project$ make compile
Execute the application binary file
~/path/to/my-new-project$ make execute

This command executes the application by running docker-compose exec --workdir=/go/bin app ...

Stop the service
~/path/to/my-new-project$ make down

Quality Assurance

Dealing with Code Quality
~/path/to/my-new-project$ make format
Dealing with Tests
~/path/to/my-new-project$ make test

Production

Creating an Alpine-based Docker Image
~/path/to/my-new-project$ make build-alpine
About make build-alpine command

This command builds a production-grade Docker image containing the application binary file(s).

Creating a Scratch-based Docker Image
~/path/to/my-new-project$ make build-scratch
About make build-scratch command

This command builds a production-grade Docker image containing the application binary file(s).

Execute the service
~/path/to/my-new-project$ make execute-production
About make execute-production command

This command executes the service from the recently created production-grade Docker image.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities:

PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY

Supported Versions

Only the latest major version receives security fixes.

Reporting a Vulnerability

If you discover a security vulnerability within this project, please open an issue here. All security vulnerabilities will be promptly addressed.

License

The MIT License (MIT). Please see LICENSE file for more information.

About

A lightweight GoLang development environment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published