class DockerJockey::GoHelper

Attributes

options[RW]

Public Instance Methods

build() click to toggle source
# File lib/langs/go_helper.rb, line 71
def build()
  script = script_base() + "
  go build -o app
  cp app $wd
  chmod a+rwx $wd/app
  " + script_cleanup()
  DockerJockey.docker_exec_script("iron/go:dev", script, options)
end
run(args=[], options) click to toggle source
# File lib/langs/go_helper.rb, line 7
    def run(args=[], options)
      @options = options
      if args.length < 1
        raise "devo go: invalid args: #{args.inspect}"
      end
      case args[0]
      when 'get', 'vendor'
script = script_base() + '
pwd
cat api.go
go get
cp -r $p/vendor $wd
chmod -R a+rw $wd/vendor
' + script_cleanup()
        # ["-w","/go/src/x/y/z","-e","GOPATH=/go/src/x/y/z/vendor:/go"]
        DockerJockey.docker_exec_script("iron/go:dev", script, options)
      when 'build'
        # todo: use extra params provided by user, eg: #{args.join(' '). But need to parse -o to find output file name to copy
        build()
      when 'fmt'
        DockerJockey.docker_exec("iron/go:dev", "go fmt", options)
      when 'static'
        static()
      when 'run'
        build()
        DockerJockey.docker_exec("iron/go", "./app", options)
      when 'image'
        DockerJockey::ImageHelper.build1('iron/go', './app', args[1..args.length])
      when 'version'
        DockerJockey.docker_exec("iron/go:dev", "go version", options)
      else
        raise "Invalid Go command: #{args[0]}"
      end
    end
script_base() click to toggle source
# File lib/langs/go_helper.rb, line 41
    def script_base
      script_base = '
set -e
#echo $PWD
wd=$PWD
defSrcPath="x/y/z"
if [ -z "$SRCPATH" ]; then
  SRCPATH=$defSrcPath
fi
#echo "srcpath $SRCPATH ---"
p=/go/src/$SRCPATH
mkdir -p $p
ls -al
if [ "$(ls -A $wd)" ]
then
  # only if files exist, errors otherwise
  cp -r * $p
fi
cd $p
export GOPATH=$p/vendor:/go
'
      script_base
    end
script_cleanup() click to toggle source
# File lib/langs/go_helper.rb, line 64
    def script_cleanup
      script_cleanup = '
rm -rf /go
'
      script_cleanup
    end
static() click to toggle source
# File lib/langs/go_helper.rb, line 80
def static()
  script = script_base() + "
  CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags=\"-s\" -o static
  cp static $wd
  chmod a+rwx $wd/static
  " + script_cleanup()
  DockerJockey.docker_exec_script("iron/go:dev", script, options)
end