Skip to content

vadzappa/gomon-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gomon-docker

Docker image for golang development with hot-reload

This image allows to run golang inside container with possibility to:

  1. Debug (using Delve)
  2. Autorefresh/autorestart using inotify

Quirks

  1. Due to some specifics which were needed, GOFLAGS is set to '-mod=vendor'. This could be overwritten using docker-compose file
  2. WORKDIR is set to /app so watcher expects source code to be located under workdir. (Just map your code to /app using docker-compose)
  3. Signalling - when running in debug mode, -9 (kill) is send to debugger and application. When running in GO_NO_DEBUG=true mode, TERM signal is sent to application
  4. Files watching - right now only files with extension go are monitored. Next versions would probably include some ENV for this
  5. Delve api version 2 is used

Env

The following env variables are available:

  • PACKAGE_DIR - package where the main file located if not in root. Example: ./cmd/run. Defaults to .
  • GO_NO_DEBUG - set it to anything except empty value to disable debugging, leaving only hot-reload on code changes
  • GOMON_DIED_CHECK_INTERVAL - (in seconds, default: 2s) monitor will check if APP is alive with set interval
  • GOMON_IGNORE - extended regex to exclude files being watched
  • GO_DEBUG_STARTUP_RETRIES - max amount of 10-sec sleep iterations to give debugger time to properly set up, while running without GO_NO_DEBUG. Defaults to 6

Ports

Port 40000 is exposed for delve debugging

Sample usage

With debug disabled

version: '2.1'
services:
  go-dev:
    image: gomon-docker:1.13
    environment:
      GO_NO_DEBUG: "true"
    volumes:
      - .:/app:delegated
    ports:
      - 9080 # your application exposed port
    network_mode: bridge
    restart: always

With debug enabled

version: '2.1'
services:
  go-dev:
    image: gomon-docker:1.13
    volumes:
      - .:/app:delegated
    ports:
      - 40000:40000 # this is Delve debugging port
      - 9080 # your application exposed port
    network_mode: bridge
    restart: always

About

Docker image for golang development with hot-reload

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •