Skip to content

Commit

Permalink
Dockerfile: Add version build argument (sqlc-dev#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy authored May 12, 2020
1 parent 0a44cd1 commit d51baf2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ WORKDIR /workspace

ARG github_ref
ARG github_sha
ARG version
ENV GITHUB_REF=$github_ref
ENV GITHUB_SHA=$github_sha
ENV VERSION=$version
RUN go run scripts/release.go -docker

# STEP 2: Build a tiny image
Expand Down
34 changes: 19 additions & 15 deletions scripts/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ func main() {
docker := flag.Bool("docker", false, "create a docker release")
flag.Parse()

version := os.Getenv("VERSION")
sha := os.Getenv("GITHUB_SHA")
ref := os.Getenv("GITHUB_REF")
cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
out, err := cmd.CombinedOutput()
if err != nil {
log.Println(strings.TrimSpace(string(out)))
log.Fatal(err)
}

var date string
parts := strings.Split(string(out), " ")
date = strings.Replace(parts[0]+parts[1], "-", "", -1)
date = strings.Replace(date, ":", "", -1)
version := fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
if version == "" {
cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
out, err := cmd.CombinedOutput()
if err != nil {
log.Println(strings.TrimSpace(string(out)))
log.Fatal(err)
}

var date string
parts := strings.Split(string(out), " ")
date = strings.Replace(parts[0]+parts[1], "-", "", -1)
date = strings.Replace(date, ":", "", -1)
version = fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
}

if *docker {
x := "-extldflags \"-static\" -X github.com/kyleconroy/sqlc/internal/cmd.version=" + version
Expand All @@ -38,9 +42,9 @@ func main() {
"-o", "/workspace/sqlc",
"./cmd/sqlc",
}
cmd = exec.Command("go", args...)
cmd := exec.Command("go", args...)
cmd.Env = os.Environ()
out, err = cmd.CombinedOutput()
out, err := cmd.CombinedOutput()
if err != nil {
log.Println(strings.TrimSpace(string(out)))
log.Fatal(err)
Expand Down Expand Up @@ -83,9 +87,9 @@ func main() {
}...)

log.Printf("Releasing %s on channel %s", flag.Arg(0), channel)
cmd = exec.Command(xname, args...)
cmd := exec.Command(xname, args...)
cmd.Env = os.Environ()
out, err = cmd.CombinedOutput()
out, err := cmd.CombinedOutput()
if err != nil {
log.Println(strings.TrimSpace(string(out)))
log.Fatal(err)
Expand Down

0 comments on commit d51baf2

Please sign in to comment.