Giter Club home page Giter Club logo

go's Introduction

MOVED: I've created a new follow on project for Go and other languages here: https://github.com/treeder/dj

This is a Docker image to help you develop in Go (golang). The great thing is you don't need to have anything installed except Docker, you don't even need Go installed. See this post about developing with Docker.

This image can perform the following functions:

  • vendor - vendors your dependencies into a /vendor directory.
  • build - builds your program using the vendored dependencies, with no import rewriting.
  • remote - this one will produce a binary from a GitHub repo. Equivalent to cloning, vendoring and building.
  • image - this will build and create a Docker image out of your program.
  • cross - cross compile your program into a variety of platforms. Based on this.
  • static - statically compile your program. This is great for making the tiniest Docker image possible.

Usage

Vendor dependencies:

docker run --rm -it -v "$PWD":/app -w /app treeder/go vendor

You may need to add more options if you have subdirectory imports:

docker run --rm -it -v "$PWD":/app -w /app -e "SRCPATH=github.com/username/reponame" treeder/go vendor

The SRCPATH should match your local import statements. Only required if you have subdirectories in the current repository that you are using in imports.

Build:

docker run --rm -v "$PWD":/app -w /app treeder/go build

Run:

This is just a normal Docker run. I'm using iron/base here because it's a tiny image that has everything you need to run your Go binary on.

docker run --rm -v "$PWD":/app -w /app -p 8080:8080 iron/base ./app

Format:

docker run --rm -v "$PWD":/app -w /app treeder/go fmt

Advanced Commands

Build a remote git repo:

This produces a binary given a remote git repo containing a Go program.

docker run --rm -v "$PWD":/app -w /app treeder/go remote https://github.com/treeder/hello-app.go.git

You'll end up with a binary called app which you can run with the same command as above.

Build a Docker image out of your program:

This will build a Docker image with your program inside it.

The argument after image is IMAGE_NAME:tag. Also, note the extra mount here, that's required to talk to the Docker host.

docker run --rm -v "$PWD":/app -w /app -v /var/run/docker.sock:/var/run/docker.sock treeder/go image username/myapp:latest

Boom, creates a small Docker image for you. Run docker images to check it out, should be about ~12MB total.

Test your new image:

docker run --rm -v "$PWD":/app -w /app -p 8080:8080 username/myapp

Cross compile:

This uses a different image, treeder/go-cross, to do a cross compile.

docker run --rm -v "$PWD":/app -w /app treeder/go-cross cross

Build static binary:

This is great for making the tiniest Docker image possible

docker run --rm -v "$PWD":/app -w /app treeder/go static

Check Go version:

docker run --rm treeder/go version

Wrapper Script

We've provided a wrapper.sh script to make running each command more convenient.

To use it, download it and put it in your $PATH. Then, create an alias for it by pasting the following into your shell config file (e.g. .bashrc, .zshrc, etc...):

alias dgo='wrapper.sh'

Now you're ready to run the wrapper. It supports the following commands:

  • dgo build
  • dgo cross
  • dgo static
  • dgo vendor
  • dgo image
  • dgo run
  • dgo run-static

TODO:

...

Building this image

docker build -t treeder/go:latest .

Tag it with Go version too (can check with docker run --rm treeder/go version):

docker tag treeder/go:latest treeder/go:1.4.2

Push:

docker push treeder/go

go's People

Contributors

arschles avatar josegonzalez avatar piperchester avatar treeder 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

go's Issues

Private Repo Source Build

Would it be easy to add private repo authentication to the build process? For example, adding a "dgo get" command that creates a docker data only container to pull down from custom sources

Can't build

Hi I'm getting this errors when I do a build:

Building...
# x/y/z
./main.go:5: illegal NUL byte
./main.go:6: illegal character 0x0
./main.go:6: illegal NUL byte
./main.go:6: illegal character 0x0
./main.go:6: illegal NUL byte
./main.go:6: illegal character 0x0
./main.go:6: illegal NUL byte
./main.go:6: illegal character 0x0
./main.go:6: illegal NUL byte
./main.go:6: illegal character 0x0
./main.go:6: too many errors

This is the main.go:

package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

Some problems with go.sh ...

  1. If a user sets an own working directory with some spaces in its pathname, the script will fail in various places due to missing quotes around variables. Isn't it the first rule of shell scripting to never leave a variable unquoted? ;)
  2. "Building Docker image '$2'..." will not print the image name (wrong quotes)

vendor creates files owned by root

This is an awesome tool! Thanks for building it.

I noticed that when I run docker run --rm -v $PWD:/myApp -w /myApp treeder/go vendor it creates a directory for vendor'd assets that is owned by root and have 777 permissions - similarly, built applications are owned by root and are 777. Shouldn't those be owned by whichever user is using the docker tool? i.e. I'm running as a normal user who's been added to the docker group - so I would expect those resulting files to have the same permissions as the files I created to be used with the tool.

$ ls -l
total 6256
-rwxrwxrwx 1 root           root           6397008 Aug 30 06:57 myApp
-rw-rw-r-- 1 funnylookinhat funnylookinhat     337 Aug 30 06:55 myApp.go
drwxrwxrwx 4 root           root              4096 Aug 30 06:55 vendor

I would have expected this:

$ ls -l
total 6256
-rwxrwxr-x 1 funnylookinhat funnylookinhat     6397008 Aug 30 06:57 myApp
-rw-rw-r-- 1 funnylookinhat funnylookinhat     337 Aug 30 06:55 myApp.go
drwxrwxr-x 4 funnylookinhat funnylookinhat    4096 Aug 30 06:55 vendor

Might seem trivial - but in my experience, permissions should never be taken for granted. :)

Vendoring Issues

I get this error when trying to vendor my dependencies (from GitHub and local sources).

Vendoring dependencies...
# x/y/z
./main.go:31: illegal NUL byte
./main.go:32: illegal character 0x0
./main.go:32: illegal NUL byte
./main.go:32: illegal character 0x0
./main.go:32: illegal NUL byte
./main.go:32: illegal character 0x0
./main.go:32: illegal NUL byte
./main.go:32: illegal character 0x0
./main.go:32: illegal NUL byte
./main.go:32: illegal character 0x0
./main.go:32: too many errors

I even tried your code and I am getting some newline errors when I tried your app.go example.

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.