• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

treeder/go: Go tool that uses Docker and only Docker.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

treeder/go

开源软件地址:

https://github.com/treeder/go

开源编程语言:

Shell 92.6%

开源软件介绍:

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



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap