Skip to content

Instantly share code, notes, and snippets.

@xslim
Last active November 9, 2020 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xslim/9affed81fcd755bc3ff540971b219fbb to your computer and use it in GitHub Desktop.
Save xslim/9affed81fcd755bc3ff540971b219fbb to your computer and use it in GitHub Desktop.
go cobra Dockerfile

Building

docker build -t go-cobra .

Run

  name=${PWD##*/}
  pkg="github.com/xslim/${name}"
  workdir="/go/src/${pkg}"

  docker run -it --rm -v "$PWD":${workdir} -w ${workdir} go-cobra build -v
#!/bin/sh
name=${PWD##*/}
# pkg="github.com/xslim/${name}"
# workdir="/go/src/${pkg}"
# image="golang"
# image="go-cobra"
# docker run -it --rm -v "$PWD":${workdir} -w ${workdir} ${image} $@
env="-e GOOS=darwin -e GOARCH=amd64"
cache="-v go_cache:/root/.cache/go-build"
docker run -it --rm ${cache} -v "$PWD":/app -w /app ${env} golang:alpine go build -v
FROM golang:alpine
LABEL maintainer Taras Kalapun <t.kalapun@gmail.com>
RUN apk add --no-cache git
RUN go get -u github.com/spf13/cobra
RUN go get -u github.com/spf13/viper
RUN go get -u github.com/mitchellh/go-homedir
ENV GOOS=darwin
ENV GOARCH=amd64
ENTRYPOINT ["go"]
CMD ["--help"]
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment