Skip to content

Instantly share code, notes, and snippets.

@nwillems
Last active June 5, 2018 08:10
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 nwillems/500d819155422e68c7aa115e9521eb26 to your computer and use it in GitHub Desktop.
Save nwillems/500d819155422e68c7aa115e9521eb26 to your computer and use it in GitHub Desktop.
cali-example
#!/bin/bash
docker run -e CGO_ENABLED=0 --rm -v "$PWD":/go/src/cali-example -w /go/src/cali-example golang:1.10.2 go build
docker build -t cali-example .
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock cali-example fortune
FROM scratch
COPY cali-example /tool
ENTRYPOINT ["/tool"]
nwillems@work $ # First run is with the new version
nwillems@work $ docker run -e CGO_ENABLED=0 --rm -v "$PWD":/go/src/cali-example -w /go/src/cali-example golang:1.10.2 go build && docker build -t cali-example . && docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock cali-example fortune
Sending build context to Docker daemon 21.79MB
Step 1/3 : FROM scratch
--->
Step 2/3 : COPY cali-example /tool
---> efa9c55b36ae
Step 3/3 : ENTRYPOINT ["/tool"]
---> Running in a7092ad3cea4
Removing intermediate container a7092ad3cea4
---> 708969ba5c2f
Successfully built 708969ba5c2f
Successfully tagged cali-example:latest
You have a tendency to feel you are superior to most computers.
nwillems@work $ ls
Dockerfile Gopkg.lock Gopkg.toml cali-example cali.go vendor
nwillems@work $ vim Gopkg.toml # Change version
nwillems@work $ dep ensure
nwillems@work $ docker run -e CGO_ENABLED=0 --rm -v "$PWD":/go/src/cali-example -w /go/src/cali-example golang:1.10.2 go build && docker build -t cali-example . && docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock cali-example fortune
Sending build context to Docker daemon 21.79MB
Step 1/3 : FROM scratch
--->
Step 2/3 : COPY cali-example /tool
---> c966765c11b7
Step 3/3 : ENTRYPOINT ["/tool"]
---> Running in b3d03b914ea0
Removing intermediate container b3d03b914ea0
---> 43a56fb5e289
Successfully built 43a56fb5e289
Successfully tagged cali-example:latest
FATA[0000] Error setting container defaults: Error expanding bind path: user: Current not implemented on linux/amd64
[[constraint]]
name = "github.com/skybet/cali"
version = "0.3.0"
# Change the above line, to provoke the error
[prune]
go-tests = true
unused-packages = true
package main
import "github.com/skybet/cali"
func main() {
cli := cali.NewCli("cali-example")
cli.SetShort("Example CLI tool")
cmdFortune(cli)
cli.Start()
}
func cmdFortune(cli *cali.Cli) {
fortune := cli.NewCommand("fortune")
fortune.SetShort("Get a fortune to bring you further in life")
fortuneTask := fortune.Task("tsnwi/fortune:release")
fortuneTask.SetInitFunc(func(t *cali.Task, args []string) {
t.AddEnv("PROFILE", cli.FlagValues().GetString("profile"))
})
}
@nwillems
Copy link
Author

nwillems commented Jun 5, 2018

to "fix" this, if you wan't to stick with cali v0.2.0, you need to change your build environment and base-image to alpine. Eg.

docker run -e CGO_ENABLED=0 --rm -v "$PWD":/go/src/cali-example -w /go/src/cali-example golang:1.10.2-alpine go build && docker build -t cali-example . && docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock cali-example fortune

And change https://gist.github.com/nwillems/500d819155422e68c7aa115e9521eb26#file-dockerfile-L1 to FROM alpine

@nwillems
Copy link
Author

nwillems commented Jun 5, 2018

There is also some fiddling with CGO_ENABLED, that I honestly don't exactly understand :-( Resources or pointers would be greatly appreciated :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment