Skip to content

Commit df5ae08

Browse files
committed
Dockerhub build and deploy support
1 parent 6a799bc commit df5ae08

File tree

7 files changed

+108
-6
lines changed

7 files changed

+108
-6
lines changed

.dockerignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
webhookdb-cli
18+
webhookdb
19+
webhookdb.wasm
20+
21+
dist/
22+
.env
23+
temp/
24+
25+
.idea/
26+
*.yaml
27+
.gitignore
28+
.github
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
7+
jobs:
8+
push_to_registry:
9+
name: Push Docker image to Docker Hub
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out the repo
13+
uses: actions/checkout@v4
14+
15+
- name: Log in to Docker Hub
16+
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
17+
with:
18+
username: ${{ secrets.DOCKERHUB_USERNAME }}
19+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
20+
21+
- name: Extract metadata (tags, labels) for Docker
22+
id: meta
23+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
24+
with:
25+
images: webhookdb/webhookdb-cli
26+
27+
- name: Build and push Docker image
28+
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
29+
with:
30+
context: .
31+
file: ./Dockerfile
32+
push: true
33+
tags: ${{ steps.meta.outputs.tags }}
34+
labels: ${{ steps.meta.outputs.labels }}
35+
build-args: |
36+
GIT_REF=${{ github.ref }}
37+
GIT_SHA=${{ github.sha }}
38+
RELEASED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ"

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.17
2+
3+
WORKDIR /app
4+
5+
COPY go.mod go.sum ./
6+
7+
RUN go mod download
8+
9+
COPY . ./
10+
11+
ARG RELEASED_AT="-"
12+
ARG GIT_SHA="-"
13+
ARG GIT_REF="-"
14+
15+
RUN go build -ldflags "-X github.com/webhookdb/webhookdb-cli/config.BuildTime=${RELEASED_AT} -X github.com/webhookdb/webhookdb-cli/config.BuildSha=${GIT_SHA} -X github.com/webhookdb/webhookdb-cli/config.Version=${GIT_REF}" -o webhookdb
16+
17+
ENTRYPOINT ["./webhookdb"]

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BIN := ./webhookdb
22
ARGS := WEBHOOKDB_API_HOST=http://localhost:18001
3-
BUILDFLAGS = "-X github.com/webhookdb/webhookdb-cli/config.BuildTime=`date -u +"%Y-%m-%dT%H:%M:%SZ"` -X github.com/webhookdb/webhookdb-cli/config.BuildSha=`git rev-list -1 HEAD`"
3+
BUILDFLAGS = "-X github.com/webhookdb/webhookdb-cli/config.BuildTime=`date -u +"%Y-%m-%dT%H:%M:%SZ"` -X github.com/webhookdb/webhookdb-cli/config.BuildSha=`git rev-list -1 HEAD` -X github.com/webhookdb/webhookdb-cli/config.Version=`git rev-parse --abbrev-ref HEAD`"
44
WEBSITE = ../webhookdb-api/webhookdb-website
55

66
ifdef GOROOT
@@ -62,6 +62,19 @@ wasm-server:
6262

6363
build-all: build-arm64 build build-wasm
6464

65+
docker-build:
66+
docker build -f Dockerfile -t webhookdb-cli \
67+
--build-arg GIT_SHA=`git rev-list --abbrev-commit -1 HEAD` \
68+
--build-arg GIT_REF=`git rev-parse --abbrev-ref HEAD` \
69+
--build-arg RELEASED_AT=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
70+
.
71+
72+
docker-run-version:
73+
@docker run -it webhookdb-cli version --time
74+
75+
docker-run-%:
76+
@docker run -it webhookdb-cli $(*)
77+
6578
docs: build
6679
@DOCBUILD=true $(BIN) docs build
6780
docs-write: build ## Write a new copy of MANUAL.md.

appcontext/appcontext.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@ var userAgent string
106106

107107
func init() {
108108
userAgent = fmt.Sprintf("WebhookDB/v1 webhookdb-cli/%s (%s; %s) Built/%s https://webhookdb.com",
109-
config.BuildSha[:8], runtime.GOOS, runtime.GOARCH, config.BuildTime)
109+
config.BuildShaShort, runtime.GOOS, runtime.GOARCH, config.BuildTime)
110110
}

cmd/cmd_version.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
var versionCmd = &cli.Command{
1010
Name: "version",
1111
Usage: "Print version and exit.",
12+
Flags: []cli.Flag{&cli.BoolFlag{Name: "time"}},
1213
Action: func(c *cli.Context) error {
13-
shaPart := config.BuildSha
14-
if len(shaPart) >= 8 {
15-
shaPart = fmt.Sprintf(" (%s)", config.BuildSha[0:8])
16-
}
14+
shaPart := fmt.Sprintf(" (%s)", config.BuildShaShort)
1715
fmt.Fprintf(c.App.Writer, "%s%s\n", config.Version, shaPart)
16+
if c.Bool("time") {
17+
fmt.Fprintf(c.App.Writer, "%s\n", config.BuildTime)
18+
}
1819
return nil
1920
},
2021
}

config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const UnknownVersion = "?.?.?"
1111

1212
var BuildTime = "1970-01-01T00:00:00Z"
1313
var BuildSha = "0000000000000000000000000000000000000000"
14+
var BuildShaShort = ""
1415
var Version = UnknownVersion
1516
var Repo = "webhookdb/webhookdb-cli"
1617

@@ -84,6 +85,10 @@ func lookupEnv(k, d string) string {
8485
const SentryDsnProd = "https://[email protected]/6224206"
8586

8687
func init() {
88+
BuildShaShort = BuildSha
89+
if len(BuildShaShort) > 8 {
90+
BuildShaShort = BuildShaShort[0:8]
91+
}
8792
MustSetEnv("WEBHOOKDB_API_HOST", "https://api.production.webhookdb.com")
8893
MustSetEnv("WEBHOOKDB_LOG_LEVEL", "error")
8994
}

0 commit comments

Comments
 (0)