diff --git a/.gitignore b/.gitignore index dbced62..9008131 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.test *.out .runconf -var/ \ No newline at end of file +var/ +dist/ \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..ea6fe5d --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,53 @@ +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm + - arm64 + ignore: + - goos: freebsd + goarch: arm + - goos: freebsd + goarch: arm64 + dir: app + ldflags: "-s -w -X main.revision={{.Tag}}-{{.ShortCommit}}-{{.CommitDate}}" + +archives: + - name_template: "{{.ProjectName}}_{{.Tag}}_{{.Os}}_{{.Arch}}" + replacements: + 386: i386 + amd64: x86_64 + darwin: macos + format_overrides: + - goos: windows + format: zip + files: + - LICENSE + - README.md + +nfpms: + - + package_name: reproxy + file_name_template: "{{.ProjectName}}_{{.Tag}}_{{.Os}}_{{.Arch}}" + vendor: Umputun + homepage: https://reproxy.io + maintainer: Umputun + description: reverse proxy + license: MIT + formats: + - deb + - rpm + bindir: /usr/bin + epoch: 1 + release: 1 + files: + "reproxy.service": "/etc/systemd/system/reproxy.service" + "reproxy-example.yml": "/etc/reproxy-example.yml" + scripts: + postinstall: "scripts/postinstall.sh" + preremove: "scripts/preremove.sh" \ No newline at end of file diff --git a/Dockerfile.artifacts b/Dockerfile.artifacts new file mode 100644 index 0000000..33b45b0 --- /dev/null +++ b/Dockerfile.artifacts @@ -0,0 +1,19 @@ +FROM goreleaser/goreleaser as build + +WORKDIR /build +ADD . /build + +RUN goreleaser --snapshot --skip-publish --rm-dist + +FROM alpine +COPY --from=build /build/dist/ /dist/ +RUN \ + mkdir -p /artifacts && \ + cp /dist/*.gz /artifacts/ && \ + cp /dist/*.zip /artifacts/ && \ + cp /dist/*.txt /artifacts/ && \ + cp /dist/*.rpm /artifacts/ && \ + cp /dist/*.deb /artifacts/ && \ + ls -la /artifacts/* + +CMD ["sleep", "100"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9f2b369 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +docker: + docker build -t umputun/reproxy . + +dist: + - @mkdir -p dist + docker build -f Dockerfile.artifacts -t reproxy.bin . + - @docker rm -f reproxy.bin 2>/dev/null || exit 0 + docker run -d --name=reproxy.bin reproxy.bin + docker cp reproxy.bin:/artifacts dist/ + docker rm -f reproxy.bin + +race_test: + cd app && go test -race -mod=vendor -timeout=60s -count 1 ./... + +.PHONY: dist docker race_test diff --git a/reproxy-example.yml b/reproxy-example.yml new file mode 100644 index 0000000..6d4bb1d --- /dev/null +++ b/reproxy-example.yml @@ -0,0 +1,5 @@ +default: + - {route: "^/api/svc1/(.*)", dest: "http://127.0.0.1:8080/blah1/$1"} + - {route: "/api/svc3/xyz", dest: "http://127.0.0.3:8080/blah3/xyz", "ping": "http://127.0.0.3:8080/ping"} +srv.example.com: + - {route: "^/api/svc2/(.*)", dest: "http://127.0.0.2:8080/blah2/$1/abc"} diff --git a/reproxy.service b/reproxy.service new file mode 100644 index 0000000..ab2d11c --- /dev/null +++ b/reproxy.service @@ -0,0 +1,14 @@ +[Unit] +Description=Reverse proxy service +After=network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +Restart=always +RestartSec=1 +User=root +ExecStart=/usr/bin/reproxy -f /etc/reproxy.yml -u + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh new file mode 100644 index 0000000..ac989ae --- /dev/null +++ b/scripts/postinstall.sh @@ -0,0 +1,3 @@ +#!/bin/sh +systemctl start reproxy +systemctl enable reproxy diff --git a/scripts/preremove.sh b/scripts/preremove.sh new file mode 100644 index 0000000..7bc883a --- /dev/null +++ b/scripts/preremove.sh @@ -0,0 +1,3 @@ +#!/bin/sh +systemctl stop reproxy +systemctl disable reproxy