mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-29 02:31:17 +00:00
Compare commits
4 commits
ae7439d3ae
...
77d1cfbc81
Author | SHA1 | Date | |
---|---|---|---|
77d1cfbc81 | |||
1d106b1c40 | |||
fa418b839d | |||
ee92c2d19b |
12 changed files with 258 additions and 76 deletions
62
.github/workflows/build.yaml
vendored
62
.github/workflows/build.yaml
vendored
|
@ -1,54 +1,37 @@
|
||||||
name: Build
|
name: Build
|
||||||
on:
|
on:
|
||||||
schedule:
|
|
||||||
- cron: "0 10 * * *"
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "main"
|
- "main"
|
||||||
tags:
|
|
||||||
- "v*.*.*"
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
|
||||||
- "main"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
attestations: write
|
||||||
|
id-token: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Install devbox
|
- name: Install devbox
|
||||||
uses: jetify-com/devbox-install-action@v0.11.0
|
uses: jetify-com/devbox-install-action@v0.11.0
|
||||||
with:
|
with:
|
||||||
enable-cache: true
|
enable-cache: true
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
|
||||||
if: github.event_name != 'pull_request'
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.repository_owner }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: |
|
|
||||||
ghcr.io/mentos1386/zdravko
|
|
||||||
tags: |
|
|
||||||
type=schedule
|
|
||||||
type=ref,event=branch
|
|
||||||
type=ref,event=pr
|
|
||||||
type=semver,pattern={{version}}
|
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
|
||||||
type=semver,pattern={{major}}
|
|
||||||
type=sha
|
|
||||||
|
|
||||||
- name: Setup Golang cache
|
- name: Setup Golang cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
|
@ -59,18 +42,13 @@ jobs:
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go-
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
- name: Build binaries
|
- name: Build artifacts
|
||||||
run: devbox run -- just build-bin
|
run: devbox run -- just unstable
|
||||||
|
|
||||||
- name: Build and push
|
- uses: actions/upload-artifact@v4
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
with:
|
||||||
file: build/Dockerfile
|
name: Unstable Build
|
||||||
context: .
|
path: dist
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -79,7 +57,7 @@ jobs:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
- name: Install devbox
|
- name: Install devbox
|
||||||
uses: jetify-com/devbox-install-action@v0.11.0
|
uses: jetify-com/devbox-install-action@v0.11.0
|
||||||
with:
|
with:
|
||||||
|
|
46
.github/workflows/release.yaml
vendored
Normal file
46
.github/workflows/release.yaml
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
attestations: write
|
||||||
|
id-token: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Install devbox
|
||||||
|
uses: jetify-com/devbox-install-action@v0.11.0
|
||||||
|
with:
|
||||||
|
enable-cache: true
|
||||||
|
- name: Setup Golang cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cache/go-build
|
||||||
|
~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: devbox run -- just release
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
bin/
|
bin/
|
||||||
|
dist/
|
||||||
|
|
||||||
# Node
|
# Node
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
|
@ -48,10 +48,10 @@ just generate-jwt-key
|
||||||
# Start development environment
|
# Start development environment
|
||||||
just run
|
just run
|
||||||
|
|
||||||
# Or build binaries
|
# Or build binaries, packages, docker images...
|
||||||
just build-bin
|
just build
|
||||||
# Or docker image (for current platform)
|
# Or build only one binary.
|
||||||
just build-docker
|
just build-only-binary
|
||||||
```
|
```
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
FROM gcr.io/distroless/static-debian12:latest as production
|
FROM gcr.io/distroless/static-debian12:latest as production
|
||||||
ARG TARGETARCH
|
|
||||||
ARG TARGETOS
|
|
||||||
|
|
||||||
COPY ./bin/zdravko-${TARGETOS}-${TARGETARCH} /bin/zdravko
|
|
||||||
|
|
||||||
|
COPY zdravko /bin/zdravko
|
||||||
COPY LICENSE /LICENSE
|
COPY LICENSE /LICENSE
|
||||||
COPY README.md /README.md
|
COPY README.md /README.md
|
||||||
|
|
||||||
|
@ -22,8 +19,5 @@ ENV TEMPORAL_DATABASE_PATH=/data/temporal.db
|
||||||
ENV KEYVALUE_DATABASE_PATH=/data/keyvalue.db
|
ENV KEYVALUE_DATABASE_PATH=/data/keyvalue.db
|
||||||
VOLUME /data
|
VOLUME /data
|
||||||
|
|
||||||
ENV DATABASE_PATH=/data/zdravko.db
|
|
||||||
ENV TEMPORAL_DATABASE_PATH=/data/temporal.db
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/zdravko"]
|
ENTRYPOINT ["/bin/zdravko"]
|
||||||
CMD ["--server", "--temporal", "--worker"]
|
CMD ["--server", "--temporal", "--worker"]
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
# Build the application
|
# Only build binary for current platform.
|
||||||
build: build-bin build-docker
|
build-only-bin:
|
||||||
|
goreleaser build --snapshot --clean --single-target --config ./build/release.yaml
|
||||||
|
|
||||||
# Build multiarch binaries
|
# Build binaries, packages, docker images for all platforms.
|
||||||
build-bin:
|
build:
|
||||||
#!/bin/bash
|
goreleaser release --snapshot --clean --config ./build/release.yaml
|
||||||
for os in {{OS}}
|
|
||||||
do
|
# Unstable release process.
|
||||||
for arch in {{ARCH}}
|
unstable:
|
||||||
do
|
#!/bin/env bash
|
||||||
echo "Building zdravko for $os $arch..."
|
set -exuo pipefail
|
||||||
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o bin/zdravko-$os-$arch cmd/zdravko/main.go
|
goreleaser release --clean --snapshot --config ./build/release.yaml
|
||||||
done
|
|
||||||
|
IMAGES=$(docker image ls --format "{{'{{ .Repository }}:{{ .Tag }}'}}" | grep -e "{{ DOCKER_IMAGE }}.*")
|
||||||
|
|
||||||
|
for image in ${IMAGES}; do
|
||||||
|
docker push ${image}
|
||||||
done
|
done
|
||||||
|
|
||||||
# Build docker image
|
docker manifest create {{ DOCKER_IMAGE }} ${IMAGES}
|
||||||
build-docker: build-bin
|
docker manifest push {{ DOCKER_IMAGE }}
|
||||||
#!/bin/bash
|
|
||||||
docker buildx build \
|
# Stable release process.
|
||||||
-f build/Dockerfile \
|
release:
|
||||||
-t {{DOCKER_IMAGE}} \
|
goreleaser release --clean --config ./build/release.yaml
|
||||||
.
|
|
||||||
|
|
100
build/release.yaml
Normal file
100
build/release.yaml
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
report_sizes: true
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
use: github
|
||||||
|
|
||||||
|
snapshot:
|
||||||
|
name_template: "{{ .Version }}-UNSTABLE-{{ .ShortCommit }}"
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- main: ./cmd/zdravko
|
||||||
|
mod_timestamp: "{{ .CommitTimestamp }}"
|
||||||
|
flags:
|
||||||
|
- -trimpath
|
||||||
|
goos:
|
||||||
|
- "darwin"
|
||||||
|
- "freebsd"
|
||||||
|
- "linux"
|
||||||
|
- "windows"
|
||||||
|
goarch:
|
||||||
|
- "amd64"
|
||||||
|
- "arm64"
|
||||||
|
|
||||||
|
nfpms:
|
||||||
|
- vendor: Tine Jozelj
|
||||||
|
homepage: https://zdravko.mnts.dev
|
||||||
|
maintainer: Tine Jozelj <me@mnts.dev>
|
||||||
|
license: AGPL-3.0
|
||||||
|
description: |
|
||||||
|
Zdravko is a selfhosted healthcheck service designed to work for small scale,
|
||||||
|
or multi region deployments. It can monitor virtually anything.
|
||||||
|
formats:
|
||||||
|
- apk
|
||||||
|
- deb
|
||||||
|
- rpm
|
||||||
|
- termux.deb
|
||||||
|
- archlinux
|
||||||
|
provides:
|
||||||
|
- zdravko
|
||||||
|
|
||||||
|
universal_binaries:
|
||||||
|
- replace: true
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- format: tar.gz
|
||||||
|
wrap_in_directory: true
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
format: zip
|
||||||
|
|
||||||
|
dockers:
|
||||||
|
- image_templates:
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:sha-{{ .ShortCommit }}-amd64"
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-amd64"
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:latest-amd64"
|
||||||
|
use: buildx
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
dockerfile: build/Dockerfile
|
||||||
|
extra_files:
|
||||||
|
- "README.md"
|
||||||
|
- "LICENSE"
|
||||||
|
build_flag_templates:
|
||||||
|
- "--pull"
|
||||||
|
- "--label=org.opencontainers.image.created={{.Date}}"
|
||||||
|
- "--label=org.opencontainers.image.title={{.ProjectName}}"
|
||||||
|
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
|
||||||
|
- "--label=org.opencontainers.image.version={{.Version}}"
|
||||||
|
- "--platform=linux/amd64"
|
||||||
|
- image_templates:
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:sha-{{ .ShortCommit }}-arm64"
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-arm64"
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:latest-arm64"
|
||||||
|
use: buildx
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
dockerfile: build/Dockerfile
|
||||||
|
extra_files:
|
||||||
|
- "README.md"
|
||||||
|
- "LICENSE"
|
||||||
|
build_flag_templates:
|
||||||
|
- "--pull"
|
||||||
|
- "--label=org.opencontainers.image.created={{.Date}}"
|
||||||
|
- "--label=org.opencontainers.image.title={{.ProjectName}}"
|
||||||
|
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
|
||||||
|
- "--label=org.opencontainers.image.version={{.Version}}"
|
||||||
|
- "--platform=linux/arm64"
|
||||||
|
|
||||||
|
docker_manifests:
|
||||||
|
- name_template: "{{ .Env.DOCKER_REGISTRY }}:sha-{{ .ShortCommit }}"
|
||||||
|
image_templates:
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-amd64"
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-arm64"
|
||||||
|
- name_template: "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}"
|
||||||
|
image_templates:
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-amd64"
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-arm64"
|
||||||
|
- name_template: "{{ .Env.DOCKER_REGISTRY }}:latest"
|
||||||
|
image_templates:
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-amd64"
|
||||||
|
- "{{ .Env.DOCKER_REGISTRY }}:{{ .Version }}-arm64"
|
|
@ -14,6 +14,12 @@ import (
|
||||||
"github.com/mentos1386/zdravko/pkg/worker"
|
"github.com/mentos1386/zdravko/pkg/worker"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
commit = "none"
|
||||||
|
date = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
type StartableAndStoppable interface {
|
type StartableAndStoppable interface {
|
||||||
Name() string
|
Name() string
|
||||||
Start() error
|
Start() error
|
||||||
|
@ -42,7 +48,8 @@ func main() {
|
||||||
flag.BoolVar(&startTemporal, "temporal", false, "Start the temporal")
|
flag.BoolVar(&startTemporal, "temporal", false, "Start the temporal")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
slog.Info("Starting zdravko...", "server", startServer, "worker", startWorker, "temporal", startTemporal)
|
slog.Info("Starting zdravko", "version", version, "commit", commit, "date", date)
|
||||||
|
slog.Info("Components...", "server", startServer, "worker", startWorker, "temporal", startTemporal)
|
||||||
|
|
||||||
if !startServer && !startWorker && !startTemporal {
|
if !startServer && !startWorker && !startTemporal {
|
||||||
slog.Error("At least one of the following must be set: --server, --worker, --temporal")
|
slog.Error("At least one of the following must be set: --server, --worker, --temporal")
|
||||||
|
|
|
@ -12,5 +12,5 @@ deploy-fly-set-jwt-key-secrets:
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Deploy locally with docker compose
|
# Deploy locally with docker compose
|
||||||
deploy-docker: build-docker
|
deploy-docker: build
|
||||||
docker compose --file dpeloy/docker-compose.yaml up
|
docker compose --file dpeloy/docker-compose.yaml up
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"sqlite-web@latest",
|
"sqlite-web@latest",
|
||||||
"go@1.22",
|
"go@1.22",
|
||||||
"tailwindcss@latest",
|
"tailwindcss@latest",
|
||||||
"temporal-cli@latest"
|
"temporal-cli@latest",
|
||||||
|
"goreleaser@latest"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
48
devbox.lock
48
devbox.lock
|
@ -69,6 +69,54 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"goreleaser@latest": {
|
||||||
|
"last_modified": "2024-05-29T10:04:41Z",
|
||||||
|
"resolved": "github:NixOS/nixpkgs/ac82a513e55582291805d6f09d35b6d8b60637a1#goreleaser",
|
||||||
|
"source": "devbox-search",
|
||||||
|
"version": "1.26.2",
|
||||||
|
"systems": {
|
||||||
|
"aarch64-darwin": {
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "out",
|
||||||
|
"path": "/nix/store/3igms7180pkaki16zvfid4q7jp2g22b0-goreleaser-1.26.2",
|
||||||
|
"default": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"store_path": "/nix/store/3igms7180pkaki16zvfid4q7jp2g22b0-goreleaser-1.26.2"
|
||||||
|
},
|
||||||
|
"aarch64-linux": {
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "out",
|
||||||
|
"path": "/nix/store/k5cnmyfha51wygjalza3kf6kjwwds0lh-goreleaser-1.26.2",
|
||||||
|
"default": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"store_path": "/nix/store/k5cnmyfha51wygjalza3kf6kjwwds0lh-goreleaser-1.26.2"
|
||||||
|
},
|
||||||
|
"x86_64-darwin": {
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "out",
|
||||||
|
"path": "/nix/store/9xx7jd8hi5ff305kysnq7wylf92w69vh-goreleaser-1.26.2",
|
||||||
|
"default": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"store_path": "/nix/store/9xx7jd8hi5ff305kysnq7wylf92w69vh-goreleaser-1.26.2"
|
||||||
|
},
|
||||||
|
"x86_64-linux": {
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "out",
|
||||||
|
"path": "/nix/store/lwgrhyjg21q6zd1akid2v1nxxnpsscz1-goreleaser-1.26.2",
|
||||||
|
"default": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"store_path": "/nix/store/lwgrhyjg21q6zd1akid2v1nxxnpsscz1-goreleaser-1.26.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"just@latest": {
|
"just@latest": {
|
||||||
"last_modified": "2024-01-27T14:55:31Z",
|
"last_modified": "2024-01-27T14:55:31Z",
|
||||||
"resolved": "github:NixOS/nixpkgs/160b762eda6d139ac10ae081f8f78d640dd523eb#just",
|
"resolved": "github:NixOS/nixpkgs/160b762eda6d139ac10ae081f8f78d640dd523eb#just",
|
||||||
|
|
5
justfile
5
justfile
|
@ -8,6 +8,9 @@ export JWT_PRIVATE_KEY := `cat jwt.private.pem || echo ""`
|
||||||
export JWT_PUBLIC_KEY := `cat jwt.public.pem || echo ""`
|
export JWT_PUBLIC_KEY := `cat jwt.public.pem || echo ""`
|
||||||
|
|
||||||
GIT_SHA := `git rev-parse --short HEAD`
|
GIT_SHA := `git rev-parse --short HEAD`
|
||||||
|
|
||||||
|
export DOCKER_REGISTRY := "ghcr.io/mentos1386/zdravko"
|
||||||
|
|
||||||
DOCKER_IMAGE := "ghcr.io/mentos1386/zdravko:sha-"+GIT_SHA
|
DOCKER_IMAGE := "ghcr.io/mentos1386/zdravko:sha-"+GIT_SHA
|
||||||
|
|
||||||
STATIC_DIR := "./web/static"
|
STATIC_DIR := "./web/static"
|
||||||
|
@ -52,7 +55,7 @@ generate-jwt-key:
|
||||||
openssl rsa -pubout -in jwt.private.pem -out jwt.public.pem
|
openssl rsa -pubout -in jwt.private.pem -out jwt.public.pem
|
||||||
|
|
||||||
# Run Docker application.
|
# Run Docker application.
|
||||||
run-docker: build-docker
|
run-docker: build
|
||||||
docker run -p 8080:8080 \
|
docker run -p 8080:8080 \
|
||||||
-it --rm \
|
-it --rm \
|
||||||
-e SESSION_SECRET \
|
-e SESSION_SECRET \
|
||||||
|
|
Loading…
Reference in a new issue