Skip to content

Commit

Permalink
add build time to version
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Aug 9, 2021
1 parent 5c2e0b9 commit 484cf26
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: echo "::set-output name=date::$(date --utc +%Y-%m-%dT%H:%M:%SZ)"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
Expand All @@ -29,7 +32,9 @@ jobs:
push: true
tags: quay.io/bakito/adguardhome-sync:latest,quay.io/bakito/adguardhome-sync:${{ github.event.release.tag_name }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: VERSION=${{ github.event.release.tag_name }}
build-args: |
VERSION=${{ github.event.release.tag_name }}
BUILD=${{ steps.date.outputs.date }}
- name: Build and push main
id: docker_build_main
Expand All @@ -39,6 +44,8 @@ jobs:
push: true
tags: quay.io/bakito/adguardhome-sync:main
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: VERSION=main
build-args: |
VERSION=main
BUILD=${{ steps.date.outputs.date }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w -X github.com/bakito/adguardhome-sync/version.Version={{.Version}}
- -s -w -X github.com/bakito/adguardhome-sync/version.Version={{.Version}} -X github.com/bakito/adguardhome-sync/version.Build={{.Date}}
goos:
- linux
- windows
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ WORKDIR /go/src/app
RUN apt-get update && apt-get install -y upx

ARG VERSION=main
ARG BUILD="N/A"

ENV GOPROXY=https://goproxy.io \
GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux

ADD . /go/src/app/

RUN go build -a -installsuffix cgo -ldflags="-w -s -X github.com/bakito/adguardhome-sync/version.Version=${VERSION}" -o adguardhome-sync . \
RUN go build -a -installsuffix cgo -ldflags="-w -s -X github.com/bakito/adguardhome-sync/version.Version=${VERSION} -X github.com/bakito/adguardhome-sync/version.Build=${BUILD}" -o adguardhome-sync . \
&& upx -q adguardhome-sync

# application image
Expand Down
3 changes: 1 addition & 2 deletions pkg/sync/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/version"
)

func (w *worker) handleSync(rw http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -62,7 +61,7 @@ func use(h http.HandlerFunc, middleware ...func(http.HandlerFunc) http.HandlerFu
}

func (w *worker) listenAndServe() {
l.With("version", version.Version, "port", w.cfg.API.Port).Info("Starting API server")
l.With("port", w.cfg.API.Port).Info("Starting API server")

ctx, cancel := context.WithCancel(context.Background())
mux := http.NewServeMux()
Expand Down
5 changes: 3 additions & 2 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Sync(cfg *types.Config) error {
return fmt.Errorf("no replicas configured")
}

l.With("version", version.Version, "build", version.Build).Info("AdGuardHome sync")
cfg.Origin.AutoSetup = false

w := &worker{
Expand All @@ -37,7 +38,7 @@ func Sync(cfg *types.Config) error {
}
if cfg.Cron != "" {
w.cron = cron.New()
cl := l.With("version", version.Version, "cron", cfg.Cron)
cl := l.With("cron", cfg.Cron)
_, err := w.cron.AddFunc(cfg.Cron, func() {
w.sync()
})
Expand All @@ -53,7 +54,7 @@ func Sync(cfg *types.Config) error {
}
}
if cfg.RunOnStart {
l.With("version", version.Version).Info("Run on startup")
l.Info("Running sync on startup")
w.sync()
}
if cfg.API.Port != 0 {
Expand Down
2 changes: 2 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ package version
var (
// Version the module version
Version = "devel"
// Build the build time
Build = "N/A"
)

0 comments on commit 484cf26

Please sign in to comment.