From 9148f79c08cd82bd473a242a8f382085498f0fc2 Mon Sep 17 00:00:00 2001 From: NotExisting <61290107+N0tExisting@users.noreply.github.com> Date: Tue, 12 Oct 2021 13:41:18 +0200 Subject: [PATCH 1/2] Multiple Fixes: - Fix Spelling in `util.go` - Impove Docker Build - Ignore more dirs - Add Build cmd for windows --- .dockerignore | 7 +++++++ .gitignore | 2 ++ Dockerfile | 21 +++++++++++++++++---- build.cmd | 7 +++++++ build.sh | 4 ++-- dns/util.go | 4 ++-- 6 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 build.cmd diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8309f3d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git* +bin +.vscode +LICENSE +README.md +records-example.json +build.sh diff --git a/.gitignore b/.gitignore index 1d74e21..684f19b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .vscode/ +vendor/ +bin/ diff --git a/Dockerfile b/Dockerfile index 5da8f3c..597eb1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,24 @@ -FROM debian:stable-slim +FROM golang:1.14 as builder + +WORKDIR /tmp/proj/ +ENV GOBIN="$(pwd)/bin" +ENV CGO_ENABLED=0 + +COPY . ./ + +RUN go build -o ./bin/go-nameserver -tags netgo -a +#RUN go install + +FROM debian:stable-slim as runtime RUN apt-get update \ && apt-get install -y --no-install-recommends net-tools iputils-ping \ - && apt-get clean && rm -rf /var/lib/apt/lists/* + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* -ADD bin/go-nameserver /go-nameserver +COPY --from=builder /tmp/proj/bin/go-nameserver /go-nameserver -EXPOSE 53 +EXPOSE 53/udp +EXPOSE 53/tcp ENTRYPOINT ["/go-nameserver"] \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..da2f442 --- /dev/null +++ b/build.cmd @@ -0,0 +1,7 @@ +@echo off + +set GOBIN=%~dp0bin\ +set CGO_ENABLED=0 + +go build -o %~dp0bin\go-nameserver.exe -tags netgo -a +::go install diff --git a/build.sh b/build.sh index 4227f1d..4023172 100755 --- a/build.sh +++ b/build.sh @@ -3,5 +3,5 @@ export GOBIN="$(pwd)/bin" export CGO_ENABLED=0 -go build -tags netgo -a -go install \ No newline at end of file +go build -o $GOBIN -tags netgo -a +#go install diff --git a/dns/util.go b/dns/util.go index 9fe95ff..bd0607f 100644 --- a/dns/util.go +++ b/dns/util.go @@ -11,13 +11,13 @@ import ( // UtilPingHost .. func UtilPingHost(host string, maxSeconds int) bool { - cmd := fmt.Sprintf("ping %s -c 1 -w %d > /dev/null && echo reacheable || echo 0", host, maxSeconds) + cmd := fmt.Sprintf("ping %s -c 1 -w %d > /dev/null && echo reachable || echo 0", host, maxSeconds) output, err := exec.Command("/bin/sh", "-c", cmd).Output() if err != nil { log.Print(err) return false } - isReachable := strings.HasPrefix(string(output), "reacheable") + isReachable := strings.HasPrefix(string(output), "reachable") log.Printf("Ping %s: %t", host, isReachable) return isReachable } From 52dd924474b2fed88ed0fcdce44abf1b093af731 Mon Sep 17 00:00:00 2001 From: NotExisting <61290107+N0tExisting@users.noreply.github.com> Date: Tue, 12 Oct 2021 13:52:45 +0200 Subject: [PATCH 2/2] Add CI --- .github/workflows/CI.yml | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..fa76bf1 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,45 @@ +name: CI + +on: + push: + branches: ["*"] + pull_request: + branches: ["*"] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Build + run: ./build.sh + + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + - name: Test + run: go test -v ./... + + docker: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Build the Docker image + run: docker build . --file Dockerfile --tag go-nameserver:$(date +%s)