mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 13:23:09 +01:00
Refactor CI and dev workflow with buildx bake (#247)
* Upload artifacts * Add image-local target * Single job for artifacts and image * Add armv5 artifact Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -2,15 +2,7 @@
|
||||
/*.iml
|
||||
|
||||
.dev
|
||||
/.git
|
||||
/.github
|
||||
/.res
|
||||
/bin
|
||||
/dist
|
||||
/docs
|
||||
/.editorconfig
|
||||
/.gitignore
|
||||
/.goreleaser.yml
|
||||
/CHANGELOG.md
|
||||
/LICENSE
|
||||
/README.md
|
||||
/site
|
||||
/coverage.txt
|
||||
|
||||
14
.github/CONTRIBUTING.md
vendored
14
.github/CONTRIBUTING.md
vendored
@@ -2,18 +2,20 @@
|
||||
|
||||
Hi there! I'm thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
|
||||
|
||||
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](../LICENSE).
|
||||
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license)
|
||||
to the public under the [project's open source license](../LICENSE).
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
1. [Fork](https://github.com/crazy-max/diun/fork) and clone the repository
|
||||
2. Configure and install the dependencies: `go mod download`
|
||||
3. Create a new branch: `git checkout -b my-branch-name`
|
||||
4. Make your change
|
||||
5. Test your code: `go test -covermode=atomic ./...`
|
||||
6. Build with [GoReleaser](https://goreleaser.com/): `goreleaser release --skip-publish --skip-validate --rm-dist`
|
||||
7. Push to your fork and [submit a pull request](https://github.com/crazy-max/diun/compare)
|
||||
8. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
||||
4. Make your changes
|
||||
5. Validate: `docker buildx bake validate`
|
||||
6. Test your code: `docker buildx bake test`
|
||||
7. Build the project: `docker buildx bake artifact-all image-all`
|
||||
8. Push to your fork and [submit a pull request](https://github.com/crazy-max/diun/compare)
|
||||
9. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
||||
|
||||
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
|
||||
|
||||
|
||||
140
.github/workflows/build.yml
vendored
140
.github/workflows/build.yml
vendored
@@ -20,62 +20,45 @@ on:
|
||||
- 'docs/**'
|
||||
- 'mkdocs.yml'
|
||||
|
||||
jobs:
|
||||
go:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Prepare
|
||||
id: prep
|
||||
run: |
|
||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||
echo ::set-output name=tag_name::${GITHUB_REF#refs/tags/}
|
||||
fi
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15
|
||||
-
|
||||
name: Cache Go modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
-
|
||||
name: GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
args: release --skip-publish --rm-dist
|
||||
-
|
||||
name: GitHub Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
draft: true
|
||||
files: |
|
||||
dist/checksums.txt
|
||||
dist/*.tar.gz
|
||||
dist/*.zip
|
||||
name: ${{ steps.prep.outputs.tag_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
env:
|
||||
DOCKERHUB_SLUG: crazymax/diun
|
||||
GHCR_SLUG: ghcr.io/crazy-max/diun
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
version: latest
|
||||
buildkitd-flags: --debug
|
||||
-
|
||||
name: Test
|
||||
uses: crazy-max/ghaction-docker-buildx-bake@v1
|
||||
with:
|
||||
targets: test
|
||||
-
|
||||
name: Upload coverage
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
file: ./coverage.txt
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ test ]
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Docker meta
|
||||
id: docker_meta
|
||||
@@ -84,9 +67,13 @@ jobs:
|
||||
images: |
|
||||
${{ env.DOCKERHUB_SLUG }}
|
||||
${{ env.GHCR_SLUG }}
|
||||
tag-semver: |
|
||||
{{version}}
|
||||
tag-edge: true
|
||||
tag-match: ^v(\d{1,3}.\d{1,3}.\d{1,3})$
|
||||
tag-match-group: 1
|
||||
label-custom: |
|
||||
org.opencontainers.image.title=Diun
|
||||
org.opencontainers.image.description=Docker image update notifier
|
||||
org.opencontainers.image.vendor=CrazyMax
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
@@ -94,7 +81,8 @@ jobs:
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
buildkitd-flags: "--debug"
|
||||
version: latest
|
||||
buildkitd-flags: --debug
|
||||
-
|
||||
name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
@@ -111,21 +99,41 @@ jobs:
|
||||
username: ${{ secrets.GHCR_USERNAME }}
|
||||
password: ${{ secrets.GHCR_TOKEN }}
|
||||
-
|
||||
name: Build
|
||||
uses: docker/build-push-action@v2
|
||||
name: Build artifacts
|
||||
uses: crazy-max/ghaction-docker-buildx-bake@v1
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le
|
||||
targets: artifact-all
|
||||
-
|
||||
name: Move artifacts
|
||||
run: |
|
||||
mv ./dist/**/* ./dist/
|
||||
-
|
||||
name: Upload artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: diun
|
||||
path: ./dist/*
|
||||
if-no-files-found: error
|
||||
-
|
||||
name: Build image
|
||||
uses: crazy-max/ghaction-docker-buildx-bake@v1
|
||||
with:
|
||||
files: |
|
||||
./docker-bake.hcl
|
||||
${{ steps.docker_meta.outputs.bake-file }}
|
||||
targets: image-all
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||
build-args: |
|
||||
VERSION=${{ steps.docker_meta.outputs.version }}
|
||||
labels: |
|
||||
${{ steps.docker_meta.outputs.labels }}
|
||||
org.opencontainers.image.title=Diun
|
||||
org.opencontainers.image.description=Docker image update notifier
|
||||
org.opencontainers.image.vendor=CrazyMax
|
||||
-
|
||||
name: GitHub Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
draft: true
|
||||
files: |
|
||||
dist/*.tar.gz
|
||||
dist/*.zip
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: Check manifest
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
28
.github/workflows/docs.yml
vendored
28
.github/workflows/docs.yml
vendored
@@ -30,27 +30,15 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Prepare
|
||||
id: prep
|
||||
run: |
|
||||
VERSION=edge
|
||||
RELEASE=false
|
||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||
VERSION=${GITHUB_REF#refs/tags/v}
|
||||
fi
|
||||
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
RELEASE=true
|
||||
fi
|
||||
echo ::set-output name=release::${RELEASE}
|
||||
-
|
||||
name: Build mkdocs Docker image
|
||||
run: |
|
||||
docker build -t mkdocs -f ./docs/Dockerfile ./
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
version: latest
|
||||
-
|
||||
name: Build docs
|
||||
run: |
|
||||
docker run --rm -v "$(pwd):/docs" mkdocs build --strict
|
||||
sudo chown -R $(id -u):$(id -g) ./site
|
||||
uses: crazy-max/ghaction-docker-buildx-bake@v1
|
||||
with:
|
||||
targets: docs
|
||||
-
|
||||
name: Check GitHub Pages status
|
||||
uses: crazy-max/ghaction-github-status@v2
|
||||
@@ -58,7 +46,7 @@ jobs:
|
||||
pages_threshold: major_outage
|
||||
-
|
||||
name: Deploy
|
||||
if: github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || steps.prep.outputs.release == 'true')
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: crazy-max/ghaction-github-pages@v2
|
||||
with:
|
||||
target_branch: gh-pages
|
||||
|
||||
44
.github/workflows/gosum.yml
vendored
44
.github/workflows/gosum.yml
vendored
@@ -1,44 +0,0 @@
|
||||
name: gosum
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
paths:
|
||||
- '.github/workflows/gosum.yml'
|
||||
- 'go.mod'
|
||||
- 'go.sum'
|
||||
|
||||
jobs:
|
||||
fix:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15
|
||||
-
|
||||
name: Tidy
|
||||
run: |
|
||||
rm -f go.sum
|
||||
go mod tidy
|
||||
-
|
||||
name: Set up Git
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
git config user.name GitHub
|
||||
git config user.email noreply@github.com
|
||||
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
|
||||
-
|
||||
name: Commit and push changes
|
||||
run: |
|
||||
git add .
|
||||
if output=$(git status --porcelain) && [ ! -z "$output" ]; then
|
||||
git commit --author "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" --message "Fix go modules"
|
||||
git push
|
||||
fi
|
||||
57
.github/workflows/test.yml
vendored
57
.github/workflows/test.yml
vendored
@@ -1,57 +0,0 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags:
|
||||
- 'v*'
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- '.github/workflows/docs.yml'
|
||||
- 'docs/**'
|
||||
- 'mkdocs.yml'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- '.github/workflows/docs.yml'
|
||||
- 'docs/**'
|
||||
- 'mkdocs.yml'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.15
|
||||
-
|
||||
name: Cache Go modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
-
|
||||
name: Go mod
|
||||
run: |
|
||||
go mod download
|
||||
-
|
||||
name: Test
|
||||
run: |
|
||||
go test -coverprofile=coverage.txt -covermode=atomic -race ./...
|
||||
-
|
||||
name: Upload coverage
|
||||
uses: codecov/codecov-action@v1
|
||||
if: success()
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
file: ./coverage.txt
|
||||
30
.github/workflows/validate.yml
vendored
Normal file
30
.github/workflows/validate.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
name: validate
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
tags:
|
||||
- 'v*'
|
||||
- 'dockerfile/*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
version: latest
|
||||
-
|
||||
name: Validate
|
||||
uses: crazy-max/ghaction-docker-buildx-bake@v1
|
||||
with:
|
||||
targets: validate
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@
|
||||
.dev
|
||||
/bin
|
||||
/dist
|
||||
/site
|
||||
/coverage.txt
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
- GOPROXY=https://goproxy.io,direct
|
||||
|
||||
before:
|
||||
hooks:
|
||||
- go mod download
|
||||
|
||||
builds:
|
||||
-
|
||||
main: ./cmd/main.go
|
||||
ldflags:
|
||||
- -s -w -X main.version={{.Version}}
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- darwin
|
||||
- linux
|
||||
- windows
|
||||
goarch:
|
||||
- 386
|
||||
- amd64
|
||||
- arm
|
||||
- arm64
|
||||
- ppc64le
|
||||
- s390x
|
||||
goarm:
|
||||
- 6
|
||||
- 7
|
||||
|
||||
archives:
|
||||
-
|
||||
replacements:
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
files:
|
||||
- LICENSE
|
||||
- README.md
|
||||
- CHANGELOG.md
|
||||
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
36
Dockerfile
36
Dockerfile
@@ -1,27 +1,35 @@
|
||||
# syntax=docker/dockerfile:1.2
|
||||
ARG GO_VERSION=1.15
|
||||
ARG VERSION=dev
|
||||
ARG GORELEASER_VERSION=0.149.0
|
||||
|
||||
FROM --platform=${BUILDPLATFORM:-linux/amd64} tonistiigi/xx:golang AS xgo
|
||||
|
||||
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:${GO_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache curl gcc git musl-dev
|
||||
COPY --from=xgo / /
|
||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
|
||||
ARG GORELEASER_VERSION
|
||||
RUN apk add --no-cache ca-certificates curl gcc file git musl-dev tar
|
||||
RUN wget -qO- https://github.com/goreleaser/goreleaser/releases/download/v${GORELEASER_VERSION}/goreleaser_Linux_x86_64.tar.gz | tar -zxvf - goreleaser \
|
||||
&& mv goreleaser /usr/local/bin/goreleaser
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS gomod
|
||||
COPY . .
|
||||
RUN go mod download
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
go mod tidy && go mod download
|
||||
|
||||
FROM gomod AS build
|
||||
ARG TARGETPLATFORM
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG VERSION
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GOPROXY https://goproxy.io,direct
|
||||
RUN go build -ldflags "-w -s -X 'main.version=${VERSION}'" -v -o /opt/diun cmd/main.go
|
||||
ARG TARGETVARIANT
|
||||
ARG GIT_REF
|
||||
RUN --mount=type=bind,target=/src,rw \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=target=/go/pkg/mod,type=cache \
|
||||
./hack/goreleaser.sh
|
||||
|
||||
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:latest
|
||||
FROM scratch AS artifacts
|
||||
COPY --from=build /out/*.tar.gz /
|
||||
COPY --from=build /out/*.zip /
|
||||
|
||||
FROM --platform=$TARGETPLATFORM alpine
|
||||
LABEL maintainer="CrazyMax"
|
||||
|
||||
RUN apk --update --no-cache add \
|
||||
@@ -29,7 +37,7 @@ RUN apk --update --no-cache add \
|
||||
libressl \
|
||||
&& rm -rf /tmp/* /var/cache/apk/*
|
||||
|
||||
COPY --from=build /opt/diun /usr/local/bin/diun
|
||||
COPY --from=build /usr/local/bin/diun /usr/local/bin/diun
|
||||
RUN diun --version
|
||||
|
||||
ENV DIUN_DB_PATH="/data/diun.db"
|
||||
|
||||
@@ -47,7 +47,7 @@ func main() {
|
||||
kong.Description(fmt.Sprintf("%s. More info: %s", meta.Desc, meta.URL)),
|
||||
kong.UsageOnError(),
|
||||
kong.Vars{
|
||||
"version": fmt.Sprintf("%s", version),
|
||||
"version": version,
|
||||
},
|
||||
kong.ConfigureHelp(kong.HelpOptions{
|
||||
Compact: true,
|
||||
|
||||
88
docker-bake.hcl
Normal file
88
docker-bake.hcl
Normal file
@@ -0,0 +1,88 @@
|
||||
// Go version
|
||||
variable "GO_VERSION" {
|
||||
default = "1.15"
|
||||
}
|
||||
|
||||
// GitHub reference as defined in GitHub Actions (eg. refs/head/master))
|
||||
variable "GITHUB_REF" {
|
||||
default = ""
|
||||
}
|
||||
|
||||
target "go-version" {
|
||||
args = {
|
||||
GO_VERSION = GO_VERSION
|
||||
}
|
||||
}
|
||||
|
||||
// Special target: https://github.com/crazy-max/ghaction-docker-meta#bake-definition
|
||||
target "ghaction-docker-meta" {
|
||||
tags = ["crazymax/diun:local"]
|
||||
}
|
||||
|
||||
group "default" {
|
||||
targets = ["image-local"]
|
||||
}
|
||||
|
||||
group "validate" {
|
||||
targets = ["lint", "vendor-validate"]
|
||||
}
|
||||
|
||||
target "lint" {
|
||||
inherits = ["go-version"]
|
||||
dockerfile = "./hack/lint.Dockerfile"
|
||||
target = "lint"
|
||||
}
|
||||
|
||||
target "vendor-validate" {
|
||||
inherits = ["go-version"]
|
||||
dockerfile = "./hack/vendor.Dockerfile"
|
||||
target = "validate"
|
||||
}
|
||||
|
||||
target "vendor-update" {
|
||||
inherits = ["go-version"]
|
||||
dockerfile = "./hack/vendor.Dockerfile"
|
||||
target = "update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "test" {
|
||||
inherits = ["go-version"]
|
||||
dockerfile = "./hack/test.Dockerfile"
|
||||
target = "test-coverage"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "docs" {
|
||||
dockerfile = "./hack/docs.Dockerfile"
|
||||
target = "release"
|
||||
output = ["./site"]
|
||||
}
|
||||
|
||||
target "artifact" {
|
||||
args = {
|
||||
GIT_REF = GITHUB_REF
|
||||
}
|
||||
inherits = ["go-version"]
|
||||
target = "artifacts"
|
||||
output = ["./dist"]
|
||||
}
|
||||
|
||||
target "artifact-all" {
|
||||
inherits = ["artifact"]
|
||||
platforms = ["linux/amd64", "linux/arm/v5", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/386", "linux/ppc64le", "linux/s390x", "windows/amd64", "windows/386", "darwin/amd64"]
|
||||
}
|
||||
|
||||
target "image" {
|
||||
inherits = ["go-version", "ghaction-docker-meta"]
|
||||
}
|
||||
|
||||
target "image-local" {
|
||||
inherits = ["image"]
|
||||
output = ["type=docker"]
|
||||
}
|
||||
|
||||
target "image-all" {
|
||||
inherits = ["image"]
|
||||
platforms = ["linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64", "linux/386", "linux/ppc64le"]
|
||||
}
|
||||
@@ -8,6 +8,7 @@ Choose the archive matching the destination platform:
|
||||
|
||||
* [diun_{{ git.tag | trim('v') }}_darwin_x86_64.tar.gz]({{ config.repo_url }}/releases/download/v{{ git.tag | trim('v') }}/diun_{{ git.tag | trim('v') }}_darwin_x86_64.tar.gz)
|
||||
* [diun_{{ git.tag | trim('v') }}_linux_arm64.tar.gz]({{ config.repo_url }}/releases/download/v{{ git.tag | trim('v') }}/diun_{{ git.tag | trim('v') }}_linux_arm64.tar.gz)
|
||||
* [diun_{{ git.tag | trim('v') }}_linux_armv5.tar.gz]({{ config.repo_url }}/releases/download/v{{ git.tag | trim('v') }}/diun_{{ git.tag | trim('v') }}_linux_armv5.tar.gz)
|
||||
* [diun_{{ git.tag | trim('v') }}_linux_armv6.tar.gz]({{ config.repo_url }}/releases/download/v{{ git.tag | trim('v') }}/diun_{{ git.tag | trim('v') }}_linux_armv6.tar.gz)
|
||||
* [diun_{{ git.tag | trim('v') }}_linux_armv7.tar.gz]({{ config.repo_url }}/releases/download/v{{ git.tag | trim('v') }}/diun_{{ git.tag | trim('v') }}_linux_armv7.tar.gz)
|
||||
* [diun_{{ git.tag | trim('v') }}_linux_i386.tar.gz]({{ config.repo_url }}/releases/download/v{{ git.tag | trim('v') }}/diun_{{ git.tag | trim('v') }}_linux_i386.tar.gz)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FROM squidfunk/mkdocs-material:6.1.7
|
||||
# syntax=docker/dockerfile:1.2
|
||||
|
||||
RUN \
|
||||
apk add --no-cache \
|
||||
FROM squidfunk/mkdocs-material:6.1.7 AS base
|
||||
RUN apk add --no-cache \
|
||||
git \
|
||||
git-fast-import \
|
||||
openssh \
|
||||
@@ -14,3 +14,10 @@ RUN \
|
||||
'mkdocs-macros-plugin' \
|
||||
&& apk del .build gcc musl-dev \
|
||||
&& rm -rf /tmp/*
|
||||
|
||||
FROM base AS generate
|
||||
RUN --mount=type=bind,target=. \
|
||||
mkdocs build --strict --site-dir /tmp/site
|
||||
|
||||
FROM scratch AS release
|
||||
COPY --from=generate /tmp/site/ /
|
||||
164
hack/goreleaser.sh
Executable file
164
hack/goreleaser.sh
Executable file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
: ${TARGETPLATFORM=}
|
||||
: ${TARGETOS=}
|
||||
: ${TARGETARCH=}
|
||||
: ${TARGETVARIANT=}
|
||||
: ${CGO_ENABLED=}
|
||||
: ${GOARCH=}
|
||||
: ${GOOS=}
|
||||
: ${GOARM=}
|
||||
: ${GOBIN=}
|
||||
: ${GIT_REF=}
|
||||
|
||||
set -eu
|
||||
|
||||
if [ ! -z "$TARGETPLATFORM" ]; then
|
||||
os="$(echo $TARGETPLATFORM | cut -d"/" -f1)"
|
||||
arch="$(echo $TARGETPLATFORM | cut -d"/" -f2)"
|
||||
if [ ! -z "$os" ] && [ ! -z "$arch" ]; then
|
||||
export GOOS="$os"
|
||||
export GOARCH="$arch"
|
||||
if [ "$arch" = "arm" ]; then
|
||||
case "$(echo $TARGETPLATFORM | cut -d"/" -f3)" in
|
||||
"v5")
|
||||
export GOARM="5"
|
||||
;;
|
||||
"v6")
|
||||
export GOARM="6"
|
||||
;;
|
||||
*)
|
||||
export GOARM="7"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -z "$TARGETOS" ]; then
|
||||
export GOOS="$TARGETOS"
|
||||
fi
|
||||
|
||||
if [ ! -z "$TARGETARCH" ]; then
|
||||
export GOARCH="$TARGETARCH"
|
||||
fi
|
||||
|
||||
if [ "$TARGETARCH" = "arm" ]; then
|
||||
if [ ! -z "$TARGETVARIANT" ]; then
|
||||
case "$TARGETVARIANT" in
|
||||
"v5")
|
||||
export GOARM="5"
|
||||
;;
|
||||
"v6")
|
||||
export GOARM="6"
|
||||
;;
|
||||
*)
|
||||
export GOARM="7"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
export GOARM="7"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$CGO_ENABLED" = "1" ]; then
|
||||
case "$GOARCH" in
|
||||
"amd64")
|
||||
export CC="x86_64-linux-gnu-gcc"
|
||||
;;
|
||||
"ppc64le")
|
||||
export CC="powerpc64le-linux-gnu-gcc"
|
||||
;;
|
||||
"s390x")
|
||||
export CC="s390x-linux-gnu-gcc"
|
||||
;;
|
||||
"arm64")
|
||||
export CC="aarch64-linux-gnu-gcc"
|
||||
;;
|
||||
"arm")
|
||||
case "$GOARM" in
|
||||
"5")
|
||||
export CC="arm-linux-gnueabi-gcc"
|
||||
;;
|
||||
*)
|
||||
export CC="arm-linux-gnueabihf-gcc"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ "$GOOS" = "wasi" ]; then
|
||||
export GOOS="js"
|
||||
fi
|
||||
|
||||
if [ -z "$GOBIN" ] && [ -n "$GOPATH" ] && [ -n "$GOARCH" ] && [ -n "$GOOS" ]; then
|
||||
export PATH=${GOPATH}/bin/${GOOS}_${GOARCH}:${PATH}
|
||||
fi
|
||||
|
||||
cat > ./.goreleaser.yml <<EOL
|
||||
dist: /out
|
||||
|
||||
builds:
|
||||
-
|
||||
main: ./cmd/main.go
|
||||
ldflags:
|
||||
- -s -w -X "main.version={{ .Version }}"
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- ${GOOS}
|
||||
goarch:
|
||||
- ${GOARCH}
|
||||
goarm:
|
||||
- ${GOARM}
|
||||
hooks:
|
||||
post:
|
||||
- cp "{{ .Path }}" /usr/local/bin/diun
|
||||
|
||||
archives:
|
||||
-
|
||||
replacements:
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
files:
|
||||
- CHANGELOG.md
|
||||
- LICENSE
|
||||
- README.md
|
||||
|
||||
release:
|
||||
disable: true
|
||||
EOL
|
||||
|
||||
gitTag=""
|
||||
case "$GIT_REF" in
|
||||
refs/tags/v*)
|
||||
gitTag="${GIT_REF#refs/tags/v}"
|
||||
export GORELEASER_CURRENT_TAG=$gitTag
|
||||
;;
|
||||
*)
|
||||
if gitTag=$(git tag --points-at HEAD --sort -version:creatordate | head -n 1); then
|
||||
if [ -z "$gitTag" ]; then
|
||||
gitTag=$(git describe --tags --abbrev=0)
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
echo "git tag found: ${gitTag}"
|
||||
|
||||
gitDirty="true"
|
||||
if git describe --exact-match --tags --match "$gitTag" >/dev/null 2>&1; then
|
||||
gitDirty="false"
|
||||
fi
|
||||
echo "git dirty: ${gitDirty}"
|
||||
|
||||
flags=""
|
||||
if [ "$gitDirty" = "true" ]; then
|
||||
flags="--snapshot"
|
||||
fi
|
||||
|
||||
set -x
|
||||
/usr/local/bin/goreleaser release $flags
|
||||
15
hack/lint.Dockerfile
Normal file
15
hack/lint.Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
# syntax=docker/dockerfile:1.2
|
||||
ARG GO_VERSION=1.15
|
||||
|
||||
FROM golang:${GO_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
WORKDIR /src
|
||||
|
||||
FROM golangci/golangci-lint:v1.27-alpine AS golangci-lint
|
||||
|
||||
FROM base AS lint
|
||||
RUN --mount=type=bind,target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/root/.cache/golangci-lint \
|
||||
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
|
||||
golangci-lint run --timeout 10m0s ./...
|
||||
20
hack/test.Dockerfile
Normal file
20
hack/test.Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
# syntax=docker/dockerfile:1.2
|
||||
ARG GO_VERSION=1.15
|
||||
|
||||
FROM golang:${GO_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS gomod
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
go mod tidy && go mod download
|
||||
|
||||
FROM gomod AS test
|
||||
RUN --mount=type=bind,target=. \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic -race ./...
|
||||
|
||||
FROM scratch AS test-coverage
|
||||
COPY --from=test /tmp/coverage.txt /coverage.txt
|
||||
24
hack/vendor.Dockerfile
Normal file
24
hack/vendor.Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
||||
# syntax=docker/dockerfile:1.2
|
||||
ARG GO_VERSION=1.15
|
||||
|
||||
FROM golang:${GO_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS vendored
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
go mod tidy && go mod download && \
|
||||
mkdir /out && cp go.mod go.sum /out
|
||||
|
||||
FROM scratch AS update
|
||||
COPY --from=vendored /out /
|
||||
|
||||
FROM vendored AS validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
git add -A && cp -rf /out/* .; \
|
||||
if [ -n "$(git status --porcelain -- go.mod go.sum)" ]; then \
|
||||
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake update-vendor"'; \
|
||||
git status --porcelain -- go.mod go.sum; \
|
||||
exit 1; \
|
||||
fi
|
||||
@@ -101,7 +101,7 @@ func (di *Diun) Start() error {
|
||||
// Start scheduler
|
||||
di.cron.Start()
|
||||
log.Info().Msgf("Next run in %s (%s)",
|
||||
durafmt.ParseShort(di.cron.Entry(di.jobID).Next.Sub(time.Now())).String(),
|
||||
durafmt.ParseShort(time.Until(di.cron.Entry(di.jobID).Next)).String(),
|
||||
di.cron.Entry(di.jobID).Next)
|
||||
|
||||
select {}
|
||||
@@ -116,7 +116,7 @@ func (di *Diun) Run() {
|
||||
defer atomic.StoreUint32(&di.locker, 0)
|
||||
if di.jobID > 0 {
|
||||
defer log.Info().Msgf("Next run in %s (%s)",
|
||||
durafmt.ParseShort(di.cron.Entry(di.jobID).Next.Sub(time.Now())).String(),
|
||||
durafmt.ParseShort(time.Until(di.cron.Entry(di.jobID).Next)).String(),
|
||||
di.cron.Entry(di.jobID).Next)
|
||||
}
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ func TestValidation(t *testing.T) {
|
||||
dec, err := env.Encode("DIUN_", cfg)
|
||||
require.NoError(t, err)
|
||||
for _, value := range dec {
|
||||
fmt.Println(fmt.Sprintf(`%s=%s`, value.Name, value.Default))
|
||||
fmt.Printf(`%s=%s\n`, value.Name, value.Default)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,7 +55,11 @@ func (c *Client) migration2() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
defer func() {
|
||||
if err := tx.Rollback(); err != nil {
|
||||
log.Error().Err(err).Msg("Cannot rollback")
|
||||
}
|
||||
}()
|
||||
|
||||
bucket := tx.Bucket([]byte(bucketManifest))
|
||||
curs := bucket.Cursor()
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
@@ -42,7 +43,11 @@ func (c *Client) Send(entry model.NotifEntry) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize Matrix client")
|
||||
}
|
||||
defer m.Logout()
|
||||
defer func() {
|
||||
if _, err := m.Logout(); err != nil {
|
||||
log.Error().Err(err).Msg("Cannot logout")
|
||||
}
|
||||
}()
|
||||
|
||||
user, err := utl.GetSecret(c.cfg.User, c.cfg.UserFile)
|
||||
if err != nil {
|
||||
|
||||
@@ -59,7 +59,6 @@ plugins:
|
||||
- exclude:
|
||||
glob:
|
||||
- "_overrides/*"
|
||||
- "Dockerfile"
|
||||
- git-revision-date-localized:
|
||||
type: iso_datetime
|
||||
- macros
|
||||
|
||||
Reference in New Issue
Block a user