Giter Site home page Giter Site logo

gocker's Introduction

Gocker

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

PROJECT NOT MAINTAINED

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/ilourt/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. Be carefful, it is now in alpha mode but must become the future official tool to manage dependencies. 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 ilourt 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.

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.

With atom you could use the package atomenv to specify the $GOPATH on a project basis

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

Author

Irwin Lourtet https://github.com/ilourt ([email protected])

Thanks to people on reddit who helps me improve it.

gocker's People

Contributors

ilourt avatar tyler-smith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocker's Issues

Unable to start Debugger inside docker

  • Delve github package path needs to be updated in the script /go/src/app/start.sh from
    github.com/derekparker/delve/cmd/dlv -> github.com/go-delve/delve/cmd/dlv

  • Give delve permission to debug in the docker-compose.yml by setting security_opt option.

/go/src/app/start.sh

#!/bin/sh

if [ "$GO_DEP" = true ]; then
  go get -u github.com/golang/dep/cmd/dep
  dep init
  dep ensure -update
else
  go install -v .
fi

if [ "$DEBUG" = true ] ; then
  go get github.com/go-delve/delve/cmd/dlv
  go get github.com/cortesi/modd/cmd/modd
  modd -f ./modd-debug.conf
fi

if [ "$WATCH" = true ] ; then
  go get github.com/cortesi/modd/cmd/modd
  modd
fi

if [ "$BUILD" = true ] ; then
  go build -o $BIN_NAME .
  if [ "$EXEC" = true ] ; then
    ./$BIN_NAME
  fi
fi

docker-compose.yml

version: '3'
services:
  golang:
    build:
      context: .
      args:
        USER: gocker
        UID: 1000
    image: gocker
    security_opt:
      - seccomp:unconfined
    volumes:
      - ./go:/go
    command: sh ./start.sh
    env_file:
      - .env
    ports:
      - 2345:2345 # Ports using for debuging with dlv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.