diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4b0798 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/cadmium +/source diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..046bccf --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,23 @@ +image: golang:1.10 + +build: + stage: build + variables: + CADDY_TAG: $CI_COMMIT_TAG + script: + - scripts/download "$(dirname $CI_PROJECT_URL)/caddy/-/archive/${CADDY_TAG}/caddy-${CADDY_TAG}.tar.gz" + - mkdir -p "$GOPATH/src/github.com/mholt" + - ln -s "$(pwd)/source" "$GOPATH/src/github.com/mholt/caddy" + - scripts/build ${CADDY_TAG} + artifacts: + paths: + - cadmium + - source + only: + - tags + - api + - pipelines + - triggers + - web + + diff --git a/patches/collection.go b/patches/collection.go new file mode 100644 index 0000000..60c46e1 --- /dev/null +++ b/patches/collection.go @@ -0,0 +1,56 @@ +// package telemetry implements a stub of the Caddy telemetry client package API +// found at https://github.com/mholt/caddy/tree/master/telemetry +// +// It doesn't do anything. Replacing the telemetry code with a stub is the best +// way to ensure compatibility with plugins is maintained. The +// `-disabled-metrics` runtime flag doesn't work. The compile-time +// `enableTelemetry` flag is OK, but this is better. + +package telemetry + +import ( + "github.com/google/uuid" +) + +func Init(instanceID uuid.UUID, disabledMetricsKeys []string) { + +} + +func StartEmitting() { + +} + +func StopEmitting() { + +} + +func Reset() { +} + +func Set(key string, val interface{}) { + +} + +func SetNested(key, subkey string, val interface{}) { + +} + +func Append(key string, value interface{}) { + +} + +func AppendUnique(key string, value interface{}) { + +} + +func Add(key string, amount int) { + +} + +func Increment(key string) { + +} + +func FastHash(input []byte) string { + return "" +} diff --git a/patches/run.go.diff b/patches/run.go.diff new file mode 100644 index 0000000..71dfd8b --- /dev/null +++ b/patches/run.go.diff @@ -0,0 +1,27 @@ +--- a/caddy/caddymain/run.go 2018-07-12 01:02:24.244606006 +0100 ++++ b/caddy/caddymain/run.go 2018-07-12 01:02:48.584895759 +0100 +@@ -117,7 +117,7 @@ + os.Exit(0) + } + if version { +- fmt.Printf("%s %s (unofficial)\n", appName, appVersion) ++ fmt.Printf("%s %s\n", appName, appVersion) + if devBuild && gitShortStat != "" { + fmt.Printf("%s\n%s\n", gitShortStat, gitFilesModified) + } +@@ -490,7 +490,7 @@ + return envMap, nil + } + +-const appName = "Caddy" ++const appName = "Cadmium" + + // Flags that control program flow or startup + var ( +@@ -519,4 +519,4 @@ + gitFilesModified string // git diff-index --name-only HEAD + ) + +-const enableTelemetry = true ++const enableTelemetry = false +lupine@gitlab-t470p:~/Desktop/caddy diff --git a/scripts/build b/scripts/build new file mode 100755 index 0000000..efa840f --- /dev/null +++ b/scripts/build @@ -0,0 +1,15 @@ +#!/bin/sh + +if [ "x$1" = "x" ]; then + echo "Usage: $0 " + exit 1 +fi + +echo "Building Cadmium $1..." + +cm="github.com/mholt/caddy/caddy/caddymain" +go build \ + -o cadmium \ + -ldflags "-X \"$cm.gitTag=$1\" -X \"$cm.gitNearestTag=$1\"" \ + github.com/mholt/caddy/caddy + diff --git a/scripts/download b/scripts/download new file mode 100755 index 0000000..9cc7a71 --- /dev/null +++ b/scripts/download @@ -0,0 +1,24 @@ +#!/bin/sh + +if [ "x$1" = "x" ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ -e "source" ]; then + echo "source/ directory already exists, remove it first" + exit 1 +fi + +curl -L "$1" | tar -xzf - +mv caddy* source + +# Disable telemetry in run.go and rename to Cadmium +patch -d source -p1 <"$(pwd)/patches/run.go.diff" + +# Replace telemetry with a stub +rm -r source/telemetry +mkdir source/telemetry +cp patches/collection.go source/telemetry/collection.go + +