Skip to content

Commit

Permalink
Dockerhub build and deploy support
Browse files Browse the repository at this point in the history
  • Loading branch information
rgalanakis committed Jan 9, 2024
1 parent 6a799bc commit df5ae08
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 6 deletions.
28 changes: 28 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

webhookdb-cli
webhookdb
webhookdb.wasm

dist/
.env
temp/

.idea/
*.yaml
.gitignore
.github
38 changes: 38 additions & 0 deletions .github/workflows/deploy-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build

on:
release:
types: [ published ]

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: webhookdb/webhookdb-cli

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GIT_REF=${{ github.ref }}
GIT_SHA=${{ github.sha }}
RELEASED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ"
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.17

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

ARG RELEASED_AT="-"
ARG GIT_SHA="-"
ARG GIT_REF="-"

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

ENTRYPOINT ["./webhookdb"]
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BIN := ./webhookdb
ARGS := WEBHOOKDB_API_HOST=http://localhost:18001
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`"
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`"
WEBSITE = ../webhookdb-api/webhookdb-website

ifdef GOROOT
Expand Down Expand Up @@ -62,6 +62,19 @@ wasm-server:

build-all: build-arm64 build build-wasm

docker-build:
docker build -f Dockerfile -t webhookdb-cli \
--build-arg GIT_SHA=`git rev-list --abbrev-commit -1 HEAD` \
--build-arg GIT_REF=`git rev-parse --abbrev-ref HEAD` \
--build-arg RELEASED_AT=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
.

docker-run-version:
@docker run -it webhookdb-cli version --time

docker-run-%:
@docker run -it webhookdb-cli $(*)

docs: build
@DOCBUILD=true $(BIN) docs build
docs-write: build ## Write a new copy of MANUAL.md.
Expand Down
2 changes: 1 addition & 1 deletion appcontext/appcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ var userAgent string

func init() {
userAgent = fmt.Sprintf("WebhookDB/v1 webhookdb-cli/%s (%s; %s) Built/%s https://webhookdb.com",
config.BuildSha[:8], runtime.GOOS, runtime.GOARCH, config.BuildTime)
config.BuildShaShort, runtime.GOOS, runtime.GOARCH, config.BuildTime)
}
9 changes: 5 additions & 4 deletions cmd/cmd_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
var versionCmd = &cli.Command{
Name: "version",
Usage: "Print version and exit.",
Flags: []cli.Flag{&cli.BoolFlag{Name: "time"}},
Action: func(c *cli.Context) error {
shaPart := config.BuildSha
if len(shaPart) >= 8 {
shaPart = fmt.Sprintf(" (%s)", config.BuildSha[0:8])
}
shaPart := fmt.Sprintf(" (%s)", config.BuildShaShort)
fmt.Fprintf(c.App.Writer, "%s%s\n", config.Version, shaPart)
if c.Bool("time") {
fmt.Fprintf(c.App.Writer, "%s\n", config.BuildTime)
}
return nil
},
}
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const UnknownVersion = "?.?.?"

var BuildTime = "1970-01-01T00:00:00Z"
var BuildSha = "0000000000000000000000000000000000000000"
var BuildShaShort = ""
var Version = UnknownVersion
var Repo = "webhookdb/webhookdb-cli"

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

func init() {
BuildShaShort = BuildSha
if len(BuildShaShort) > 8 {
BuildShaShort = BuildShaShort[0:8]
}
MustSetEnv("WEBHOOKDB_API_HOST", "https://api.production.webhookdb.com")
MustSetEnv("WEBHOOKDB_LOG_LEVEL", "error")
}

0 comments on commit df5ae08

Please sign in to comment.