aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Resnick <max@ofmax.li>2025-03-03 21:42:57 -0800
committerMax Resnick <max@ofmax.li>2025-03-03 21:42:57 -0800
commite31be2ef1be5745e4af74def945e694ea1bd4fe9 (patch)
tree421bc259d7d81027f6d4cedbf98d5c217341fcd7
parentb62450b18522f33c27cd67ff0191a42908e88bb1 (diff)
downloadunbound-adblock-config-e31be2ef1be5745e4af74def945e694ea1bd4fe9.tar.gz
feat: add Dockerfile and justfile
Diffstat (limited to '')
-rw-r--r--Dockerfile15
-rw-r--r--justfile81
2 files changed, 96 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..e94a18d
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,15 @@
+FROM public.ecr.aws/s0f9o2k5/just:v0.0.1 AS just
+FROM golangci/golangci-lint:latest AS golint
+FROM golang:bookworm AS build
+ARG version
+COPY --from=just /just /usr/local/bin/just
+COPY --from=golint /usr/bin/golangci-lint /usr/bin/golangci-lint
+COPY . /build
+WORKDIR /build
+RUN just build $version
+
+
+FROM scratch
+COPY --from=build /build/_build/bin/unbound-ads /unbound-ads
+WORKDIR /
+CMD ["unbound-ads"]
diff --git a/justfile b/justfile
new file mode 100644
index 0000000..82c10f6
--- /dev/null
+++ b/justfile
@@ -0,0 +1,81 @@
+TEMPDIR := `mktemp -d`
+BUILDDIR := "_build"
+
+ALL_VERSIONS := BUILDDIR / "ALL_VERSIONS"
+NEW_VERSION := BUILDDIR / "NEW_VERSION"
+CURRENT_VERSION := BUILDDIR / "CURRENT_VERSION"
+
+COMMIT := `git rev-parse --short HEAD`
+TAGS := `git tag -l`
+
+default:
+ @just --choose
+
+docker-build: new-ver
+ new_ver=$(cat {{ NEW_VERSION }}); \
+ docker build --build-arg="version=$new_ver" -t unbound-ads:$new_ver .
+
+builddir:
+ mkdir -p {{ BUILDDIR }}/etc
+ mkdir -p {{ BUILDDIR }}/bin
+
+clean:
+ rm -r {{ BUILDDIR }}
+
+new-ver part="latest": builddir
+ #!/usr/bin/env bash
+ set -euxo pipefail
+ echo "{{ TAGS }}" > {{ ALL_VERSIONS }}
+ cat {{ ALL_VERSIONS }} | bumpver --last-version patch - > {{ CURRENT_VERSION }}
+ if [[ {{part}} == "latest" ]];
+ then
+ bumpver patch --prerelease --prerelease-fmt 'latest.$KeyArg commit.$BumpInt' -k commit={{COMMIT}} {{ CURRENT_VERSION }} > {{ NEW_VERSION }}
+ git tag $(cat {{ NEW_VERSION }})
+ else
+ bumpver {{part}} <(git tag -l) > {{ NEW_VERSION }}
+ fi
+
+git-push tag:
+ git push origin master
+ git push origin {{ tag }}
+
+git-tag-release:
+ #!/usr/bin/env bash
+ set -euxo pipefail
+ new_ver=$(cat {{ NEW_VERSION }})
+ current_ver=$(cat {{ CURRENT_VERSION}})
+ # temp light weight tag for building release notes
+ git tag $new_ver
+ echo "v${new_ver} release" > {{ TEMPDIR }}/chglog
+ git-chglog $current_ver..$new_ver >> {{ TEMPDIR }}/chglog
+ echo "## Coverage" >> {{ TEMPDIR }}/chglog
+ echo "" >> {{ TEMPDIR }}/chglog
+ go tool cover -func={{ TEMPDIR }}/testcover.out >> {{ TEMPDIR }}/chglog
+ # end temp tag
+ git tag -d $new_ver
+ git tag --annotate --sign --cleanup=whitespace --file {{ TEMPDIR }}/chglog ${new_ver}
+
+
+release part: test builddir (new-ver part) docker-build git-tag-release push
+
+
+build version: test builddir
+ CGO_ENABLED=0 go build -a -ldflags "-s -X 'main.Version={{version}}'" -o {{ BUILDDIR }}/bin/unbound-ads main.go
+
+push:
+ just docker-push; \
+ just git-push
+ @echo "pushed to all endpoints"
+
+docker-push registry="public.ecr.aws/s0f9o2k5":
+ new_ver=$(cat {{ NEW_VERSION }}); \
+ docker tag unbound-ads:$new_ver {{registry}}/unbound-ads:$new_ver; \
+ docker push {{registry}}/unbound-ads:$new_ver
+
+run repo=(TEMPDIR):
+ go run main.go
+
+test:
+ golangci-lint run
+ go test -v -coverprofile={{ TEMPDIR }}/testcover.out ./...
+ go tool cover -func={{ TEMPDIR }}/testcover.out