Skip to content

Automatic rebuild & continuous debug support for Go with docker containers

License

Notifications You must be signed in to change notification settings

anishkargaonkar/gocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gocker

Gocker is a starter project using docker and golang with automatic rebuild & debug in development mode.

Originally forked from gocker

Getting started

Prerequisites

In order to run this project you need to have Docker > 1.17.05 installed for building the production image.

Installing

To use this to start your golang project, simply do:

$> git clone https://github.com/anishkargaonkar/gocker

Then feel free to add other docker services in the docker-compose.yml files to suit the needs of your app.

Development

$> docker-compose up

It is possible to disable automatic rebuild in development. In order to do this simply change the value of WATCH to anything different than true in the .env file. In this case you will have to relaunch $> docker-compose up each time you want to rebuild.

In case of development of server (like an http server) replace in modd.conf "prep: go run ./*.go" by :

prep: go build -o $BIN_NAME ./*.go 
daemon: ./$BIN_NAME

To create binary set the BUILD to true in the env file. The binary name can be customized by setting the BIN_NAME variable.

For dependencies management dep is used. If you prefer you can disable it by setting the value od GO_DEP to false in the .env* file.

In the Dockerfile, there is the creation of a user to create file on the disk as non root user. By default the user is gocker with a UID of 1000. You can change these values in .env file.

To know the uid of your current user use the following command:$> id

Debugging

It is possible to use delve to debug the project. In order to use it:

  • set the DEBUG variable to true
  • install delve on the host
  • connect delve on the host to the delve headless server running in the container
    $> dlv connect localhost:2345
    the port can be customized in modd-debug.conf. If you modify the port don't forget to update the docker-compose.yml.

Visual Studio Code Configuration has also been provided which will attach vscode debugger to the dlv server running in docker exposed on http://localhost:2345.

Production

$> docker build -t gocker-prod:latest -f ./Dockerfile.prod .
$> docker run gocker-prod:latest

With the hello world example, the size of the production docker image is 5.52MB.

File structure

The folder go is a volume which represents the go folder of the docker image. It allows to use code autocompletion in your favorite IDE.

The folder go/src/app corresponds to the folder containing the source code of your app. It the folder which will be automatically rerun. At the root of this folder there is a file start.sh. It is the script run when the docker image start, it allows to download and install dependencies and then to run the project.

Built With

  • Docker - The linux container
  • Docker compose - Util used to manage docker images
  • Golang - Language for which this project is used

About

Automatic rebuild & continuous debug support for Go with docker containers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published