diff --git a/.dockerignore b/.dockerignore index e4adc91..356433f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,4 +5,5 @@ /bin /misc/docker/Dockerfile /.env -/.env.dist \ No newline at end of file +/.env.dist +/tools \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2a576f4..ddcc7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /vendor /bin /node_modules -/.env \ No newline at end of file +/.env +/tools \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..158c006 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v14.16.0 diff --git a/Makefile b/Makefile index 9c222f3..8d1422f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,14 @@ -DOCKER_DATE_TAG := $(shell date +%Y%m%d%H%M) +DOCKER_DATE_TAG := $(shell date --utc +%Y.%-m.%-d%-H%-M) + +YQ_VERSION ?= v4.30.4 +YQ_BINARY ?= yq_linux_amd64 + +tools: tools/yq/bin/yq + +tools/yq/bin/yq: + mkdir -p tools/yq/bin + wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY} -O tools/yq/bin/yq &&\ + chmod +x tools/yq/bin/yq build: CGO_ENABLED=0 go build -v -o bin/fake-smtp ./cmd/fake-smtp @@ -31,7 +41,7 @@ docker-release: test: go test -v -race ./... -release: dist +release: dist tools @./misc/script/release.sh dist: diff --git a/misc/docker/Dockerfile b/misc/docker/Dockerfile index f342298..c39f9b3 100644 --- a/misc/docker/Dockerfile +++ b/misc/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17 AS build +FROM golang:1.19 AS build ARG HTTP_PROXY= ARG HTTPS_PROXY= @@ -14,13 +14,8 @@ COPY . /src WORKDIR /src -RUN cp -f misc/docker/config-patch.yml misc/release/config-patch.yml - -RUN go get github.com/krishicks/yaml-patch/cmd/yaml-patch - -RUN npm install \ - && make vendor \ - && echo "---" > ./misc/release/config-patch.yml \ +RUN cp -f misc/docker/config-patch.txt misc/release/config-patch.txt \ + && npm install \ && make ARCH_TARGETS=amd64 release FROM busybox @@ -31,4 +26,6 @@ WORKDIR /app RUN mkdir -p /app +EXPOSE 8080 2525 + CMD ["bin/fake-smtp", "--config", "config.yml"] \ No newline at end of file diff --git a/misc/docker/config-patch.txt b/misc/docker/config-patch.txt new file mode 100644 index 0000000..62f7583 --- /dev/null +++ b/misc/docker/config-patch.txt @@ -0,0 +1 @@ +.smtp.debug = false diff --git a/misc/docker/config-patch.yml b/misc/docker/config-patch.yml deleted file mode 100644 index cf67519..0000000 --- a/misc/docker/config-patch.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- op: replace - path: /smtp/debug - value: false \ No newline at end of file diff --git a/misc/release/config-patch.txt b/misc/release/config-patch.txt new file mode 100644 index 0000000..80b27ae --- /dev/null +++ b/misc/release/config-patch.txt @@ -0,0 +1,3 @@ +.data.path = "/var/lib/fake-smtp/data.db" +.smtp.address = "127.0.0.1:2525" +.smtp.debug = false diff --git a/misc/release/config-patch.yml b/misc/release/config-patch.yml deleted file mode 100644 index cf62cd6..0000000 --- a/misc/release/config-patch.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- op: replace - path: /data/path - value: /var/lib/fake-smtp/data.db -- op: replace - path: /smtp/address - value: 127.0.0.1:2525 -- op: replace - path: /smtp/debug - value: false \ No newline at end of file diff --git a/misc/script/release.sh b/misc/script/release.sh index 9e9f20b..477a570 100755 --- a/misc/script/release.sh +++ b/misc/script/release.sh @@ -73,13 +73,17 @@ function dump_default_conf { local command=$1 local os=$2 local arch=$3 - local tmp_conf=$(mktemp) local patched_conf=$(mktemp) - go run "$PROJECT_DIR/cmd/$command" -dump-config > "$tmp_conf" - cat "$tmp_conf" | yaml-patch -o misc/release/config-patch.yml > "$patched_conf" + go run "$PROJECT_DIR/cmd/$command" -dump-config > "$patched_conf" + + while IFS= read -r yq_cmd; do + echo "patching configuration with '$yq_cmd'..." + tools/yq/bin/yq -i "$yq_cmd" "$patched_conf" + done < misc/release/config-patch.txt + copy "$command" $os $arch "$patched_conf" "config.yml" - rm -f "$tmp_conf" "$patched_conf" + rm -f "$patched_conf" } function compress {