Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git*
bin
.vscode
LICENSE
README.md
records-example.json
build.sh
45 changes: 45 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode/
vendor/
bin/
21 changes: 17 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
export GOBIN="$(pwd)/bin"
export CGO_ENABLED=0

go build -tags netgo -a
go install
go build -o $GOBIN -tags netgo -a
#go install
4 changes: 2 additions & 2 deletions dns/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down