Skip to content

Commit 7e85d6b

Browse files
authored
docker: Publish to Docker Hub (#422)
* docker: Publish to Docker Hub * Don't keep the username a secret * rename all the workflows
1 parent 1d2916b commit 7e85d6b

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed

.github/workflows/ci-kotlin.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: sqlc kotlin test suite
1+
name: gradle
22
on: [push, pull_request]
33
jobs:
44

55
build:
6-
name: Build And Test
6+
name: test
77
runs-on: ubuntu-latest
88

99
services:

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: sqlc test suite
1+
name: go
22
on: [push, pull_request]
33
jobs:
44

55
build:
6-
name: Build
6+
name: test
77
runs-on: ubuntu-latest
88

99
services:

.github/workflows/docker.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: docker
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
10+
docker:
11+
name: push kjconroy/sqlc:devel
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@master
15+
- uses: docker/build-push-action@v1
16+
with:
17+
username: kjconroy
18+
password: ${{ secrets.DOCKER_PASSWORD }}
19+
build_args: github_ref=${{ github.ref }},github_sha=${{ github.sha }}
20+
repository: kjconroy/sqlc
21+
add_git_labels: true
22+
tags: devel

.github/workflows/equinox.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish to Equinox
1+
name: equinox
22

33
on:
44
push:
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111

1212
macos:
13-
name: Build on macOS
13+
name: release --platforms darwin
1414
runs-on: macos-latest
1515
steps:
1616
- uses: actions/checkout@master
@@ -26,7 +26,7 @@ jobs:
2626
run: go run scripts/release.go -draft darwin_amd64
2727

2828
linux:
29-
name: Build on Linux
29+
name: release --platforms linux
3030
runs-on: ubuntu-latest
3131
needs: [macos]
3232
steps:

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# STEP 1: Build sqlc
2+
FROM golang:1.13 AS builder
3+
4+
COPY . /workspace
5+
WORKDIR /workspace
6+
7+
ARG github_ref
8+
ARG github_sha
9+
ENV GITHUB_REF=$github_ref
10+
ENV GITHUB_SHA=$github_sha
11+
RUN go run scripts/release.go -docker
12+
13+
# STEP 2: Build a tiny image
14+
FROM scratch
15+
16+
COPY --from=builder /workspace/sqlc /workspace/sqlc
17+
ENTRYPOINT ["/workspace/sqlc"]

scripts/release.go

+27-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ import (
1111

1212
func main() {
1313
draft := flag.Bool("draft", false, "create a draft release")
14+
docker := flag.Bool("docker", false, "create a docker release")
1415
flag.Parse()
1516

16-
arch := flag.Arg(0)
17-
if arch == "" {
18-
log.Fatalf("missing platform_arch argument")
19-
}
20-
2117
sha := os.Getenv("GITHUB_SHA")
2218
ref := os.Getenv("GITHUB_REF")
2319
cmd := exec.Command("git", "show", "--no-patch", "--no-notes", "--pretty=%ci", sha)
2420
out, err := cmd.CombinedOutput()
2521
if err != nil {
22+
log.Println(strings.TrimSpace(string(out)))
2623
log.Fatal(err)
2724
}
2825

@@ -32,6 +29,30 @@ func main() {
3229
date = strings.Replace(date, ":", "", -1)
3330
version := fmt.Sprintf("v0.0.0-%s-%s", date, sha[:12])
3431

32+
if *docker {
33+
x := "-extldflags \"-static\" -X github.com/kyleconroy/sqlc/internal/cmd.version=" + version
34+
args := []string{
35+
"build",
36+
"-a",
37+
"-ldflags", x,
38+
"-o", "/workspace/sqlc",
39+
"./cmd/sqlc",
40+
}
41+
cmd = exec.Command("go", args...)
42+
cmd.Env = os.Environ()
43+
out, err = cmd.CombinedOutput()
44+
if err != nil {
45+
log.Println(strings.TrimSpace(string(out)))
46+
log.Fatal(err)
47+
}
48+
return
49+
}
50+
51+
arch := flag.Arg(0)
52+
if arch == "" {
53+
log.Fatalf("missing platform_arch argument")
54+
}
55+
3556
xname := "./equinox"
3657
if _, err := os.Stat("./equinox"); os.IsNotExist(err) {
3758
xname = "equinox"
@@ -65,8 +86,8 @@ func main() {
6586
cmd = exec.Command(xname, args...)
6687
cmd.Env = os.Environ()
6788
out, err = cmd.CombinedOutput()
68-
log.Println(strings.TrimSpace(string(out)))
6989
if err != nil {
90+
log.Println(strings.TrimSpace(string(out)))
7091
log.Fatal(err)
7192
}
7293
}

0 commit comments

Comments
 (0)