Skip to content

docker: Publish to Docker Hub #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci-kotlin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: sqlc kotlin test suite
name: gradle
on: [push, pull_request]
jobs:

build:
name: Build And Test
name: test
runs-on: ubuntu-latest

services:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: sqlc test suite
name: go
on: [push, pull_request]
jobs:

build:
name: Build
name: test
runs-on: ubuntu-latest

services:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: docker

on:
push:
branches:
- master

jobs:

docker:
name: push kjconroy/sqlc:devel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: docker/build-push-action@v1
with:
username: kjconroy
password: ${{ secrets.DOCKER_PASSWORD }}
build_args: github_ref=${{ github.ref }},github_sha=${{ github.sha }}
repository: kjconroy/sqlc
add_git_labels: true
tags: devel
6 changes: 3 additions & 3 deletions .github/workflows/equinox.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish to Equinox
name: equinox

on:
push:
Expand All @@ -10,7 +10,7 @@ on:
jobs:

macos:
name: Build on macOS
name: release --platforms darwin
runs-on: macos-latest
steps:
- uses: actions/checkout@master
Expand All @@ -26,7 +26,7 @@ jobs:
run: go run scripts/release.go -draft darwin_amd64

linux:
name: Build on Linux
name: release --platforms linux
runs-on: ubuntu-latest
needs: [macos]
steps:
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# STEP 1: Build sqlc
FROM golang:1.13 AS builder

COPY . /workspace
WORKDIR /workspace

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

# STEP 2: Build a tiny image
FROM scratch

COPY --from=builder /workspace/sqlc /workspace/sqlc
ENTRYPOINT ["/workspace/sqlc"]
33 changes: 27 additions & 6 deletions scripts/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ import (

func main() {
draft := flag.Bool("draft", false, "create a draft release")
docker := flag.Bool("docker", false, "create a docker release")
flag.Parse()

arch := flag.Arg(0)
if arch == "" {
log.Fatalf("missing platform_arch argument")
}

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)
}

Expand All @@ -32,6 +29,30 @@ func main() {
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
args := []string{
"build",
"-a",
"-ldflags", x,
"-o", "/workspace/sqlc",
"./cmd/sqlc",
}
cmd = exec.Command("go", args...)
cmd.Env = os.Environ()
out, err = cmd.CombinedOutput()
if err != nil {
log.Println(strings.TrimSpace(string(out)))
log.Fatal(err)
}
return
}

arch := flag.Arg(0)
if arch == "" {
log.Fatalf("missing platform_arch argument")
}

xname := "./equinox"
if _, err := os.Stat("./equinox"); os.IsNotExist(err) {
xname = "equinox"
Expand Down Expand Up @@ -65,8 +86,8 @@ func main() {
cmd = exec.Command(xname, args...)
cmd.Env = os.Environ()
out, err = cmd.CombinedOutput()
log.Println(strings.TrimSpace(string(out)))
if err != nil {
log.Println(strings.TrimSpace(string(out)))
log.Fatal(err)
}
}