diff --git a/.cz.toml b/.cz.toml new file mode 100644 index 0000000..167e0a0 --- /dev/null +++ b/.cz.toml @@ -0,0 +1,6 @@ +[tool.commitizen] +name = "cz_conventional_commits" +tag_format = "v$version" +version_scheme = "semver" +version = "1.16.4" +update_changelog_on_bump = true diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..9fd442e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:mantic + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + ca-certificates=20230311ubuntu1 \ + apt-utils=2.7.3 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + git=1:2.40.1-1ubuntu1 \ + golang=2:1.21~2 \ + zsh=5.9-5ubuntu1 \ + tree=2.1.1-1 \ + neovim=0.7.2-7 \ + wget=1.21.3-1ubuntu1 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN export GOBIN=/usr/local/bin \ + && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 \ + && go install golang.org/x/tools/gopls@v0.14.2 \ + && go install github.com/goreleaser/goreleaser@v1.23.0 \ + && go install github.com/go-delve/delve/cmd/dlv@v1.22.0 + +RUN wget -q -O /usr/local/bin/hadolint \ + https://github.com/hadolint/hadolint/releases/download/v2.8.0/hadolint-Linux-x86_64 \ + && chmod +x /usr/local/bin/hadolint + +ENV DEBIAN_FRONTEND=dialog + +SHELL ["/bin/zsh", "-c"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..049a167 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,31 @@ +{ + "name": "Dnsdock dev container", + "build": { + "dockerfile": "Dockerfile" + }, + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "/bin/zsh", + "terminal.integrated.defaultProfile.linux": "zsh", + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "zsh", + "icon": "terminal-bash" + } + } + }, + "extensions": [ + "ms-azuretools.vscode-docker", + "premparihar.gotestexplorer", + "golang.go", + "github.vscode-github-actions", + "KnisterPeter.vscode-commitizen", + "eamodio.gitlens", + "mhutchie.git-graph", + "yzhang.markdown-all-in-one", + "esbenp.prettier-vscode" + ] + } + } +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7161066 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 120 + +[*.go] +insert_final_newline = ignore +indent_style = tabs + +[*.json] +insert_final_newline = ignore + +[*.md] +trim_trailing_whitespace = false + diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/pull_request_template.md similarity index 100% rename from PULL_REQUEST_TEMPLATE.md rename to .github/pull_request_template.md diff --git a/.github/workflows/commit_checks.yml b/.github/workflows/commit_checks.yml new file mode 100644 index 0000000..434118e --- /dev/null +++ b/.github/workflows/commit_checks.yml @@ -0,0 +1,64 @@ +name: Commit Checks + +on: + workflow_call: + inputs: + base_sha: + description: 'Base SHA to check from' + required: true + type: string + head_sha: + description: 'Head SHA to check until' + required: true + type: string + +jobs: + commit_messages_checks: + name: Commit messages checks + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.7.0 + with: + devbox-version: 0.8.5 + enable-cache: 'true' + + - name: Check commit messages + run: devbox run -- cz check --rev-range ${{ inputs.base_sha }}..${{ inputs.head_sha }} + + code_lint_checks: + name: Code lint checks + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.7.0 + with: + devbox-version: 0.8.5 + enable-cache: 'true' + + - name: Lint code + run: devbox run lint + + test_checks: + name: Test checks + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.7.0 + with: + devbox-version: 0.8.5 + enable-cache: 'true' + + - name: Run tests + run: devbox run test diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..4bc8d83 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,15 @@ +name: main branch workflow + +on: + push: + branches: + - master + +jobs: + commit_checks: + name: Commit checks + uses: ./.github/workflows/commit_checks.yml + with: + base_sha: ${{ github.event.before }} + head_sha: ${{ github.event.after }} + diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..f8f00db --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,15 @@ +name: PR workflow + +on: + pull_request: + branches: + - master + +jobs: + commit_checks: + name: Commit checks + uses: ./.github/workflows/commit_checks.yml + with: + base_sha: ${{ github.event.pull_request.base.sha }} + head_sha: ${{ github.event.pull_request.head.sha }} + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dd177a8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release workflow + +on: + push: + branches-ignore: + - '**' + tags: + - 'v*' + +permissions: + contents: write + +jobs: + create_release: + name: Create release + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Install devbox + uses: jetpack-io/devbox-install-action@v0.7.0 + with: + devbox-version: 0.8.5 + enable-cache: 'true' + + - name: Publish release + run: devbox run release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml.bak b/.github/workflows/release.yml.bak new file mode 100644 index 0000000..452939a --- /dev/null +++ b/.github/workflows/release.yml.bak @@ -0,0 +1,25 @@ +name: Release workflow + +on: + push: + tags: + - "v*.*.*" + +jobs: + release: + runs-on: ubuntu-latest + steps: + + - name: Create bump and changelog + uses: commitizen-tools/commitizen-action@master + with: + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + changelog_increment_filename: CHANGELOG.md + + - name: Create release + uses: softprops/action-gh-release@v1 + with: + body_path: "CHANGELOG.md" + tag_name: ${{ env.REVISION }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index bdb42e0..787b7e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -dnsdock \ No newline at end of file +dnsdock +.go +.devbox +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..8dd4598 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,60 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 1 + +before: + hooks: + - devbox run test + - devbox run lint + +builds: + - env: + - CGO_ENABLED=0 + main: ./cmd/dnsdock + goarch: + - amd64 + - arm + goos: + - linux + +archives: + - format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{ .Version }}_ + {{ .Os }}_ + {{ .Arch }}{{ if eq .Arch "arm" }}v{{ .Arm }}l{{ end }} + +release: + prerelease: auto + draft: true + github: + owner: aacebedo + name: dnsdock + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +dockers: + - id: amd64 image + goos: linux + + goarch: amd64 + + image_templates: + - aacebedo/dnsdock:latest + - aacebedo/dnsdock:{{ .Tag }} + + # hooks: + # pre: docker login -u $DOCKER_USER -p $DOCKER_PASS + # post: docker push aacebedo/dnsdock:latest && docker push aacebedo/dnsdock:{{ .Tag }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..000da26 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/commitizen-tools/commitizen + rev: v3.13.0 + hooks: + - id: commitizen diff --git a/.project b/.project deleted file mode 100644 index 1dd11b9..0000000 --- a/.project +++ /dev/null @@ -1,18 +0,0 @@ - - - dnsdock - - - - - - com.googlecode.goclipse.goBuilder - clean,full,incremental, - - - - - - com.googlecode.goclipse.core.goNature - - diff --git a/.tm_properties b/.tm_properties deleted file mode 100644 index 7164bd0..0000000 --- a/.tm_properties +++ /dev/null @@ -1,3 +0,0 @@ -[ *.go ] -softTabs = false -tabSize = 2 \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e764e5a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Run dnsdock", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "cmd/dnsdock/dnsdock.go" + } + ] +} diff --git a/Dockerfile b/Dockerfile index 498b825..8f3cf74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,44 +1,4 @@ -FROM alpine:3.6 AS builder +FROM scratch -ARG GOLANG_VERSION=1.8.4-r0 - -RUN apk update -RUN apk add go=${GOLANG_VERSION} go-tools=${GOLANG_VERSION} git musl-dev -RUN go version - -ENV GOPATH=/go -ENV PATH=${PATH}:/go/bin -ENV CGO_ENABLED=0 - -RUN go get -v github.com/tools/godep -# RUN go get -u github.com/golang/lint/golint -RUN go get github.com/ahmetb/govvv - -RUN mkdir -p /go/src/github.com/aacebedo/dnsdock - -WORKDIR /go/src/github.com/aacebedo/dnsdock - -RUN git clone https://github.com/aacebedo/dnsdock /go/src/github.com/aacebedo/dnsdock -# RUN git checkout {{$GIT_COMMIT}} - -RUN mkdir /tmp/output - -WORKDIR /go/src/github.com/aacebedo/dnsdock - -ENV GIT_SSL_NO_VERIFY=true - -RUN godep restore - -ENV GOARCH=amd64 - -WORKDIR /go/src/github.com/aacebedo/dnsdock/src - -RUN govvv build -o /tmp/output/dnsdock - -FROM alpine:3.18.2 - -ENV GOARCH=amd64 - -COPY --from=builder /tmp/output/dnsdock /bin/dnsdock - -ENTRYPOINT ["dnsdock"] \ No newline at end of file +COPY dnsdock / +ENTRYPOINT ["dnsdock"] diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json deleted file mode 100644 index fcab44a..0000000 --- a/Godeps/Godeps.json +++ /dev/null @@ -1,186 +0,0 @@ -{ - "ImportPath": "github.com/aacebedo/dnsdock", - "GoVersion": "go1.6", - "GodepVersion": "v74", - "Packages": [ - "./..." - ], - "Deps": [ - { - "ImportPath": "github.com/Microsoft/go-winio", - "Comment": "v0.3.5-2-gce2922f", - "Rev": "ce2922f643c8fd76b46cadc7f404a06282678b34" - }, - { - "ImportPath": "github.com/Sirupsen/logrus", - "Comment": "v0.10.0-19-gf3cfb45", - "Rev": "f3cfb454f4c209e6668c95216c4744b8fddb2356" - }, - { - "ImportPath": "github.com/alecthomas/template", - "Rev": "a0175ee3bccc567396460bf5acd36800cb10c49c" - }, - { - "ImportPath": "github.com/alecthomas/template/parse", - "Rev": "a0175ee3bccc567396460bf5acd36800cb10c49c" - }, - { - "ImportPath": "github.com/alecthomas/units", - "Rev": "2efee857e7cfd4f3d0138cc3cbb1b4966962b93a" - }, - { - "ImportPath": "github.com/docker/distribution/digest", - "Comment": "docs-v2.4.1-2016-06-28-6-g4e17ab5", - "Rev": "4e17ab5d319ac5b70b2769442947567a83386fbc" - }, - { - "ImportPath": "github.com/docker/distribution/reference", - "Comment": "docs-v2.4.1-2016-06-28-6-g4e17ab5", - "Rev": "4e17ab5d319ac5b70b2769442947567a83386fbc" - }, - { - "ImportPath": "github.com/docker/engine-api/client", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/client/transport", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/client/transport/cancellable", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/blkiodev", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/container", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/events", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/filters", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/network", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/reference", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/registry", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/strslice", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/swarm", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/time", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/engine-api/types/versions", - "Comment": "v0.3.1-196-gf50fbe5", - "Rev": "f50fbe5f9c4c8eeed591549d2c8187f4076f3717" - }, - { - "ImportPath": "github.com/docker/go-connections/nat", - "Comment": "v0.2.1", - "Rev": "990a1a1a70b0da4c4cb70e117971a4f0babfbf1a" - }, - { - "ImportPath": "github.com/docker/go-connections/sockets", - "Comment": "v0.2.1", - "Rev": "990a1a1a70b0da4c4cb70e117971a4f0babfbf1a" - }, - { - "ImportPath": "github.com/docker/go-connections/tlsconfig", - "Comment": "v0.2.1", - "Rev": "990a1a1a70b0da4c4cb70e117971a4f0babfbf1a" - }, - { - "ImportPath": "github.com/docker/go-units", - "Comment": "v0.3.0", - "Rev": "5d2041e26a699eaca682e2ea41c8f891e1060444" - }, - { - "ImportPath": "github.com/gorilla/context", - "Comment": "v1.1-4-gaed02d1", - "Rev": "aed02d124ae4a0e94fea4541c8effd05bf0c8296" - }, - { - "ImportPath": "github.com/gorilla/mux", - "Comment": "v1.1-13-g9fa818a", - "Rev": "9fa818a44c2bf1396a17f9d5a3c0f6dd39d2ff8e" - }, - { - "ImportPath": "github.com/miekg/dns", - "Rev": "5d001d020961ae1c184f9f8152fdc73810481677" - }, - { - "ImportPath": "github.com/op/go-logging", - "Comment": "v1-7-g970db52", - "Rev": "970db520ece77730c7e4724c61121037378659d9" - }, - { - "ImportPath": "github.com/opencontainers/runc/libcontainer/user", - "Comment": "v1.0.0-rc1-50-g7221e38", - "Rev": "7221e387826c9918fa9fd6e7975baf4d30c8fa54" - }, - { - "ImportPath": "github.com/vdemeester/docker-events", - "Rev": "be74d4929ec1ad118df54349fda4b0cba60f849b" - }, - { - "ImportPath": "golang.org/x/net/context", - "Rev": "b6d7b1396ec874c3b00f6c84cd4301a17c56c8ed" - }, - { - "ImportPath": "golang.org/x/net/proxy", - "Rev": "b6d7b1396ec874c3b00f6c84cd4301a17c56c8ed" - }, - { - "ImportPath": "golang.org/x/sys/unix", - "Rev": "62bee037599929a6e9146f29d10dd5208c43507d" - }, - { - "ImportPath": "golang.org/x/sys/windows", - "Rev": "62bee037599929a6e9146f29d10dd5208c43507d" - }, - { - "ImportPath": "gopkg.in/alecthomas/kingpin.v2", - "Comment": "v2.2.3", - "Rev": "e9044be3ab2a8e11d4e1f418d12f0790d57e8d70" - } - ] -} diff --git a/Godeps/Readme b/Godeps/Readme deleted file mode 100644 index 4cdaa53..0000000 --- a/Godeps/Readme +++ /dev/null @@ -1,5 +0,0 @@ -This directory tree is generated automatically by godep. - -Please do not edit. - -See https://github.com/tools/godep for more information. diff --git a/Makefile b/Makefile deleted file mode 100644 index bb70c22..0000000 --- a/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -build: - docker build -t dnsdock:latest . - -build-test: - docker build -t dnsdock:test . --progress=plain --no-cache diff --git a/Rockerfile b/Rockerfile deleted file mode 100644 index d434782..0000000 --- a/Rockerfile +++ /dev/null @@ -1,85 +0,0 @@ -# This file is part of DNSDock -# MIT -# -# Copyright (C) 2014 Tõnis Tiigi -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -{{$GOLANG_VERSION := "1.6.3"}} -{{$ARCH:= (or .ARCH "amd64")}} -{{$GIT_COMMIT:= (or .GIT_COMMIT "develop")}} -{{$DOCKERIMAGE_VERSION:= (or .DOCKERIMAGE_VERSION "dev")}} -{{$SRC_DIR:= (or .SRC_DIR ".")}} - -# build image -FROM alpine:3.4 -RUN apk update -RUN apk upgrade -RUN apk add go>{{$GOLANG_VERSION}} go-tools>{{$GOLANG_VERSION}} git musl-dev - -ENV GOPATH=/go -ENV PATH=${PATH}:/go/bin -ENV CGO_ENABLED=0 - -RUN go get -v github.com/tools/godep -RUN go get -u github.com/golang/lint/golint -RUN go get github.com/ahmetb/govvv - -RUN mkdir -p /go/src/github.com/aacebedo/dnsdock -WORKDIR /go/src/github.com/aacebedo/dnsdock -{{if .SRC_DIR}} - MOUNT {{$SRC_DIR}}:/go/src/github.com/aacebedo/dnsdock -{{else}} - RUN git clone https://github.com/aacebedo/dnsdock /go/src/github.com/aacebedo/dnsdock - RUN git checkout {{$GIT_COMMIT}} -{{end}} - -{{if .OUTPUT_DIR}} - MOUNT {{.OUTPUT_DIR}}:/tmp/output -{{else}} - RUN mkdir /tmp/output -{{end}} - -WORKDIR /go/src/github.com/aacebedo/dnsdock -RUN godep restore -ENV GOARCH={{$ARCH}} -WORKDIR /go/src/github.com/aacebedo/dnsdock/src -ATTACH sh -RUN govvv build -o /tmp/output/dnsdock -RUN golint -set_exit_status -{{if eq $ARCH "amd64"}} -RUN go vet -RUN go test ./... -{{end}} -TAG aacebedo/dnsdock-devenv:latest-{{$ARCH}} -EXPORT /tmp/output/dnsdock ./dnsdock - -# run image -{{if eq $ARCH "amd64"}} -FROM alpine -{{else}} -FROM easypi/alpine-arm -{{end}} -IMPORT ./dnsdock /bin/dnsdock -ENTRYPOINT ["dnsdock"] -TAG aacebedo/dnsdock:{{$DOCKERIMAGE_VERSION}}-{{$ARCH}} - -{{if ne $DOCKERIMAGE_VERSION "dev"}} -TAG aacebedo/dnsdock:latest-{{$ARCH}} -{{end}} diff --git a/src/main.go b/cmd/dnsdock/dnsdock.go similarity index 86% rename from src/main.go rename to cmd/dnsdock/dnsdock.go index 538d887..964c2c6 100644 --- a/src/main.go +++ b/cmd/dnsdock/dnsdock.go @@ -11,27 +11,25 @@ package main import ( "crypto/tls" "crypto/x509" - "github.com/aacebedo/dnsdock/src/core" - "github.com/aacebedo/dnsdock/src/servers" - "github.com/aacebedo/dnsdock/src/utils" + "github.com/aacebedo/dnsdock/internal/core" + "github.com/aacebedo/dnsdock/internal/servers" + "github.com/aacebedo/dnsdock/internal/utils" "github.com/op/go-logging" - "io/ioutil" "os" ) // GitSummary contains the version number -var GitSummary string +var GitSummary string var logger = logging.MustGetLogger("dnsdock.main") func main() { - var cmdLine = core.NewCommandLine(GitSummary) config, err := cmdLine.ParseParameters(os.Args[1:]) if err != nil { logger.Fatalf(err.Error()) } verbosity := 0 - if config.Quiet == false { - if config.Verbose == false { + if !config.Quiet { + if !config.Verbose { verbosity = 1 } else { verbosity = 2 @@ -54,7 +52,7 @@ func main() { MinVersion: tls.VersionTLS12, Certificates: []tls.Certificate{clientCert}, } - pemData, err := ioutil.ReadFile(config.TlsCaCert) + pemData, err := os.ReadFile(config.TlsCaCert) if err == nil { rootCert := x509.NewCertPool() rootCert.AppendCertsFromPEM(pemData) diff --git a/devbox.json b/devbox.json new file mode 100644 index 0000000..a50095a --- /dev/null +++ b/devbox.json @@ -0,0 +1,39 @@ +{ + "packages": [ + "go@1.21.5", + "gopls@0.14.2", + "commitizen@3.13.0", + "go-tools@2023.1.6", + "golangci-lint@1.55.2", + "delve@1.22.0", + "hadolint@2.12.0", + "pre-commit@3.6.0", + "goreleaser@1.23.0" + ], + "env": { + "NIX_HARDENING_ENABLE": "" + }, + "shell": { + "init_hook": [ + "export GOPATH=`pwd`/.go", + "export PATH=`pwd`/.go/bin:$PATH", + "export CGO_ENABLED=0" + ], + "scripts": { + "build": [ + "mkdir -p build && go build -o build/dnsdock${GOARCH:+.}${GOARCH} ./cmd/dnsdock" + ], + "test": [ + "go test ./..." + ], + "lint": [ + "go mod tidy", + "go vet ./... ", + "golangci-lint run ./..." + ], + "release": [ + "goreleaser --clean" + ] + } + } +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 0000000..f424c26 --- /dev/null +++ b/devbox.lock @@ -0,0 +1,185 @@ +{ + "lockfile_version": "1", + "packages": { + "commitizen@3.13.0": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#commitizen", + "source": "devbox-search", + "version": "3.13.0", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/2q29sp1whfi4z7fz2d5mi3633b8wgvk2-commitizen-3.13.0" + }, + "aarch64-linux": { + "store_path": "/nix/store/fx13w2bgfr4zbr8nfhvi6w2ldd62h3lh-commitizen-3.13.0" + }, + "x86_64-darwin": { + "store_path": "/nix/store/rks27zi77gsqm7sdg1cpkk1ls20dfkmr-commitizen-3.13.0" + }, + "x86_64-linux": { + "store_path": "/nix/store/isdx07sqxxh3zbbhx4h3d8d8j26d8mcn-commitizen-3.13.0" + } + } + }, + "delve@1.22.0": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#delve", + "source": "devbox-search", + "version": "1.22.0", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/09qvkgba1dkzqp68fcibkz1rnhmbsx3w-delve-1.22.0" + }, + "aarch64-linux": { + "store_path": "/nix/store/fa20vgdc700g7rqy6s49f8c7alkkhp8v-delve-1.22.0" + }, + "x86_64-darwin": { + "store_path": "/nix/store/wrnp7nl3rrx0w3czzhbs0pqbkpcn3s9j-delve-1.22.0" + }, + "x86_64-linux": { + "store_path": "/nix/store/8mip6mypyqpij9r8la8cp1rdn3kvx0s1-delve-1.22.0" + } + } + }, + "go-tools@2023.1.6": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#go-tools", + "source": "devbox-search", + "version": "2023.1.6", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/znwyinwhkfcbxs1krxrkifv8cfpsk2cv-go-tools-2023.1.6" + }, + "aarch64-linux": { + "store_path": "/nix/store/wcyzvjnki8mxjha2h1k9zfg9grd7pbn6-go-tools-2023.1.6" + }, + "x86_64-darwin": { + "store_path": "/nix/store/9nzqn3p88bc93d15h3361prs1yqk32gf-go-tools-2023.1.6" + }, + "x86_64-linux": { + "store_path": "/nix/store/k757m23123dbnjggb0lfmpjha4nl0mgy-go-tools-2023.1.6" + } + } + }, + "go@1.21.5": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#go", + "source": "devbox-search", + "version": "1.21.5", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/z6p2j8shdwi74kbm86jwdh03vxq91l0q-go-1.21.5" + }, + "aarch64-linux": { + "store_path": "/nix/store/1p00q366rk2j7w9lnflrl7xaks7wfq5d-go-1.21.5" + }, + "x86_64-darwin": { + "store_path": "/nix/store/brv7d6mlrclkzywf1vaf35wqhq4c0c82-go-1.21.5" + }, + "x86_64-linux": { + "store_path": "/nix/store/rccpgf2bnh58hhh4908p78i1rln9gzvp-go-1.21.5" + } + } + }, + "golangci-lint@1.55.2": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#golangci-lint", + "source": "devbox-search", + "version": "1.55.2", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/jn473vqnn5b22nfyi9i5q9baabins79d-golangci-lint-1.55.2" + }, + "aarch64-linux": { + "store_path": "/nix/store/0bviwvbqc81gnhhg937q1dx8vnv0c3ml-golangci-lint-1.55.2" + }, + "x86_64-darwin": { + "store_path": "/nix/store/b5w76bajwnajcdxw60363g5m8vxgd17a-golangci-lint-1.55.2" + }, + "x86_64-linux": { + "store_path": "/nix/store/4kq1iinaabjh96myl4q73d0yjw3p911l-golangci-lint-1.55.2" + } + } + }, + "gopls@0.14.2": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#gopls", + "source": "devbox-search", + "version": "0.14.2", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/7d4hvs3wq5sxg0z3mx78fjri80aa64pl-gopls-0.14.2" + }, + "aarch64-linux": { + "store_path": "/nix/store/xcmh0k2sjn72jzghi7hhqfcymzf7dch5-gopls-0.14.2" + }, + "x86_64-darwin": { + "store_path": "/nix/store/cyc7q2nlfa0bk2vqcj5s1ddw9ddsiak7-gopls-0.14.2" + }, + "x86_64-linux": { + "store_path": "/nix/store/n0ff21slx44ia16668zz060h94a8a6k4-gopls-0.14.2" + } + } + }, + "goreleaser@1.23.0": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#goreleaser", + "source": "devbox-search", + "version": "1.23.0", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/fza9lw9ld7qw4k80al4saam3gldc9izz-goreleaser-1.23.0" + }, + "aarch64-linux": { + "store_path": "/nix/store/bnmsfyfbh435jgps2vqi4cxgfb51fz8b-goreleaser-1.23.0" + }, + "x86_64-darwin": { + "store_path": "/nix/store/kl9kd32c6kd7y4bwi7m2wpwy8xjl4z3v-goreleaser-1.23.0" + }, + "x86_64-linux": { + "store_path": "/nix/store/acdq08cx9sv82585s98y763iq1ki4rgd-goreleaser-1.23.0" + } + } + }, + "hadolint@2.12.0": { + "last_modified": "2024-01-14T03:55:27Z", + "resolved": "github:NixOS/nixpkgs/dd5621df6dcb90122b50da5ec31c411a0de3e538#hadolint", + "source": "devbox-search", + "version": "2.12.0", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/aajh88229d5xddkg4lf8h0ghxxj47gza-hadolint-2.12.0" + }, + "aarch64-linux": { + "store_path": "/nix/store/z22a19r3nqvfz8j45a6fs3ipwbv71qbv-hadolint-2.12.0" + }, + "x86_64-darwin": { + "store_path": "/nix/store/367m9l47igbk5janz2sz0bd7wjpnsks2-hadolint-2.12.0" + }, + "x86_64-linux": { + "store_path": "/nix/store/0l9mbskrx57q44vdw0v59vmzlc750s9q-hadolint-2.12.0" + } + } + }, + "pre-commit@3.6.0": { + "last_modified": "2024-01-18T00:05:01Z", + "resolved": "github:NixOS/nixpkgs/921fb3319c2a296fc65048272d22f3db889d7292#pre-commit", + "source": "devbox-search", + "version": "3.6.0", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/i49v43p1a33gmdib1hg0fp9chn1bzakb-pre-commit-3.6.0" + }, + "aarch64-linux": { + "store_path": "/nix/store/pfhx6ckglrj4j0wv17nzms2qc3wrbszi-pre-commit-3.6.0" + }, + "x86_64-darwin": { + "store_path": "/nix/store/l0nf5ivi8vbc35r5ppm7ak5hx6c7nf50-pre-commit-3.6.0" + }, + "x86_64-linux": { + "store_path": "/nix/store/1j57wynzsd9a0fihjj21rj42m870a7sx-pre-commit-3.6.0" + } + } + } + } +} diff --git a/domaingraph.go.bak b/domaingraph.go.bak new file mode 100644 index 0000000..7d2bbc1 --- /dev/null +++ b/domaingraph.go.bak @@ -0,0 +1,89 @@ +/* +package servers + +import ( + "github.com/gyuho/goraph" + "strings" + "fmt" +) + + +type DomainGraph struct { + graph goraph.Graph + roots []goraph.Node +} + + +func NewDomainGraph() *DomainGraph { + res := &DomainGraph {} + res.graph = goraph.NewGraph() + return res +} + + +// +//type DomainGraphNode { +// name String +// children []*DomainGraphNode +//} +// +// +func (g *DomainGraph) AddDomain(domain string) { + splitted := strings.Split(domain,".") + var parent goraph.Node = nil + for i := len(splitted)-1; i >= 0; i-- { + var curComp = splitted[i] + node, err := g.graph.GetNode(goraph.StringID(curComp)) + if err != nil { + fmt.Printf("Node %s does not exist, add it\n", curComp) + node = goraph.NewNode(curComp) + g.graph.AddNode(node) + } + if parent == nil { + parent = node + g.roots = append(g.roots,node) + } else { + g.graph.AddEdge(parent.ID(),node.ID(),1) + fmt.Printf("Add edge from %s to %s \n", parent, node) + } + } +} + +func (g *DomainGraph) Display() { + for _, c := range g.roots { + g.displayNode(c) + } +} + +func (g *DomainGraph) displayNode(curNode goraph.Node) { + fmt.Println("Node: %s visited", curNode.ID()) + children, err := g.graph.GetTargets(curNode.ID()) + fmt.Printf("Number of children: %i\n", len(children)) + if err == nil { + for _,c := range children { + + g.displayNode(c) + } + } +} +// +// +//func (g DomainGraph) RemoveDomain(domain String) { +// +//} +// +//func (g DomainGraph) getNodes(query String) []*DomainGraphNode { +// splittedQuery = strings.Split(strings.ToLower(query), ".") +//} +// +//func resolveDomain(query []String, n *DomainGraphNode) +//{ +//} +// +//func (n DomainGraphNode) Name() String { +// return n.name +//} +// +//func (n DomainGraphNode) Children() []*DomainGraphNode { +// return n.children +//}*/ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5702e61 --- /dev/null +++ b/go.mod @@ -0,0 +1,30 @@ +module github.com/aacebedo/dnsdock + +go 1.21.5 + +require ( + github.com/docker/engine-api v0.3.2-0.20160615162419-f50fbe5f9c4c + github.com/gorilla/mux v0.0.0-20160605233521-9fa818a44c2b + github.com/miekg/dns v0.0.0-20160614162101-5d001d020961 + github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 + github.com/vdemeester/docker-events v0.0.0-20160621105736-be74d4929ec1 + golang.org/x/net v0.0.0-20160217011348-b6d7b1396ec8 + gopkg.in/alecthomas/kingpin.v2 v2.2.3 +) + +require ( + github.com/Microsoft/go-winio v0.3.6-0.20160621211438-ce2922f643c8 // indirect + github.com/Sirupsen/logrus v0.10.1-0.20160601113210-f3cfb454f4c2 // indirect + github.com/alecthomas/assert v1.0.0 // indirect + github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect + github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect + github.com/docker/distribution v2.5.0-rc.1.0.20160701175950-4e17ab5d319a+incompatible // indirect + github.com/docker/go-connections v0.2.1 // indirect + github.com/docker/go-units v0.3.0 // indirect + github.com/gorilla/context v0.0.0-20160525203319-aed02d124ae4 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/opencontainers/runc v1.0.0-rc1.0.20160701221151-7221e387826c // indirect + github.com/stevvooe/resumable v0.0.0-20180830230917-22b14a53ba50 // indirect + github.com/stretchr/testify v1.8.4 // indirect + golang.org/x/sys v0.13.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..73a53f3 --- /dev/null +++ b/go.sum @@ -0,0 +1,55 @@ +github.com/Microsoft/go-winio v0.3.6-0.20160621211438-ce2922f643c8 h1:Qp3i6ZUVcAOeTQj0KBsivXCfsnvsBASQYfXXS/N34NY= +github.com/Microsoft/go-winio v0.3.6-0.20160621211438-ce2922f643c8/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= +github.com/Sirupsen/logrus v0.10.1-0.20160601113210-f3cfb454f4c2 h1:3BYvDlSNPyoYk6lr17s9IueNAabOBur3f3uVULjbhTA= +github.com/Sirupsen/logrus v0.10.1-0.20160601113210-f3cfb454f4c2/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U= +github.com/alecthomas/assert v1.0.0 h1:3XmGh/PSuLzDbK3W2gUbRXwgW5lqPkuqvRgeQ30FI5o= +github.com/alecthomas/assert v1.0.0/go.mod h1:va/d2JC+M7F6s+80kl/R3G7FUiW6JzUO+hPhLyJ36ZY= +github.com/alecthomas/colour v0.1.0 h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk= +github.com/alecthomas/colour v0.1.0/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= +github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48= +github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/distribution v2.5.0-rc.1.0.20160701175950-4e17ab5d319a+incompatible h1:DfRH1jF28NhWMQ6vyEJdTelNZm6HywyGXS7MDOd+qAM= +github.com/docker/distribution v2.5.0-rc.1.0.20160701175950-4e17ab5d319a+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/engine-api v0.3.2-0.20160615162419-f50fbe5f9c4c h1:1QkBJs/GAU1pjGTb5K2/PnMpEacsc7dajoVXK5zNc/s= +github.com/docker/engine-api v0.3.2-0.20160615162419-f50fbe5f9c4c/go.mod h1:xtQCpzf4YysNZCVFfIGIm7qfLvYbxtLkEVVfKhTVOvw= +github.com/docker/go-connections v0.2.1 h1:XB0Pr+bR+RGw8D0C/ADeRiiPVyMftTtKFblUw3sNFXQ= +github.com/docker/go-connections v0.2.1/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.3.0 h1:69LhctGQbg0wZ2bTvwFsuPXPnhe6T2+0UMsxh+rBYZg= +github.com/docker/go-units v0.3.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/gorilla/context v0.0.0-20160525203319-aed02d124ae4 h1:3nOfQt8sRPYbXORD5tJ8YyQ3HlL2Jt3LJ2U17CbNh6I= +github.com/gorilla/context v0.0.0-20160525203319-aed02d124ae4/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v0.0.0-20160605233521-9fa818a44c2b h1:OFvZV3a+25cGJH9dETHw0nk0wV6hLZI7IJijOkXEFS0= +github.com/gorilla/mux v0.0.0-20160605233521-9fa818a44c2b/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/miekg/dns v0.0.0-20160614162101-5d001d020961 h1:vX2vkMipgQZ8gfmAsFeZdcgmhHoB7jMo6chAtajG3AI= +github.com/miekg/dns v0.0.0-20160614162101-5d001d020961/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88= +github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/opencontainers/runc v1.0.0-rc1.0.20160701221151-7221e387826c h1:5MxvsTN6f5Q3is0rlHpvUpAn6D5R4tW47AZMkLHz+XM= +github.com/opencontainers/runc v1.0.0-rc1.0.20160701221151-7221e387826c/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/stevvooe/resumable v0.0.0-20180830230917-22b14a53ba50 h1:4bT0pPowCpQImewr+BjzfUKcuFW+KVyB8d1OF3b6oTI= +github.com/stevvooe/resumable v0.0.0-20180830230917-22b14a53ba50/go.mod h1:1pdIZTAHUz+HDKDVZ++5xg/duPlhKAIzw9qy42CWYp4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/vdemeester/docker-events v0.0.0-20160621105736-be74d4929ec1 h1:kFsyaUAnFox5TJhHD0s3Ul0vPg9tOG1dNfhIWs0gU4s= +github.com/vdemeester/docker-events v0.0.0-20160621105736-be74d4929ec1/go.mod h1:yzWlPVyEah//aR7RqMj4F54qdNtB6NoGiyxKO6RxuuM= +golang.org/x/net v0.0.0-20160217011348-b6d7b1396ec8 h1:KmBIeT9k185ytk8+2smfknL7YXpZLu27pm22N10jqtc= +golang.org/x/net v0.0.0-20160217011348-b6d7b1396ec8/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/alecthomas/kingpin.v2 v2.2.3 h1:/L3oK40poPRwke0Ipa6qqf8n+awu60Vl3DMe+3jLDt4= +gopkg.in/alecthomas/kingpin.v2 v2.2.3/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/core/cmdline.go b/internal/core/cmdline.go similarity index 98% rename from src/core/cmdline.go rename to internal/core/cmdline.go index 0e2f634..240cee1 100644 --- a/src/core/cmdline.go +++ b/internal/core/cmdline.go @@ -10,7 +10,7 @@ package core import ( "fmt" - "github.com/aacebedo/dnsdock/src/utils" + "github.com/aacebedo/dnsdock/internal/utils" "gopkg.in/alecthomas/kingpin.v2" "strconv" ) diff --git a/src/core/docker.go b/internal/core/docker.go similarity index 90% rename from src/core/docker.go rename to internal/core/docker.go index 606e590..4068e09 100644 --- a/src/core/docker.go +++ b/internal/core/docker.go @@ -11,17 +11,19 @@ package core import ( "crypto/tls" "errors" - "github.com/aacebedo/dnsdock/src/servers" - "github.com/aacebedo/dnsdock/src/utils" + "fmt" + "net" + "regexp" + "strconv" + "strings" + + "github.com/aacebedo/dnsdock/internal/servers" + "github.com/aacebedo/dnsdock/internal/utils" "github.com/docker/engine-api/client" "github.com/docker/engine-api/types" eventtypes "github.com/docker/engine-api/types/events" "github.com/vdemeester/docker-events" "golang.org/x/net/context" - "net" - "regexp" - "strconv" - "strings" ) // DockerManager is the entrypoint to the docker daemon @@ -45,7 +47,7 @@ func NewDockerManager(c *utils.Config, list servers.ServiceListProvider, tlsConf } // Start starts the DockerManager -func (d *DockerManager) Start() error { +func (d *DockerManager) Start() (err error) { ctx, cancel := context.WithCancel(context.Background()) d.cancel = cancel startHandler := func(m eventtypes.Message) { @@ -54,14 +56,20 @@ func (d *DockerManager) Start() error { if err != nil { logger.Errorf("%s", err) } else { - d.list.AddService(m.ID, *service) + err = d.list.AddService(m.ID, *service) + if err != nil { + logger.Errorf("Error adding service: %s", err) + } } } stopHandler := func(m eventtypes.Message) { logger.Debugf("Stopped container '%s'", m.ID) if !d.config.All { - d.list.RemoveService(m.ID) + err = d.list.RemoveService(m.ID) + if err != nil { + logger.Errorf("%s", err) + } } else { logger.Debugf("Stopped container '%s' not removed as --all argument is true", m.ID) } @@ -72,12 +80,18 @@ func (d *DockerManager) Start() error { name, ok2 := m.Actor.Attributes["oldName"] if ok && ok2 { logger.Debugf("Renamed container '%s' into '%s'", oldName, name) - d.list.RemoveService(oldName) + err = d.list.RemoveService(oldName) + if err != nil { + logger.Errorf("%s", err) + } service, err := d.getService(m.ID) if err != nil { logger.Errorf("%s", err) } else { - d.list.AddService(m.ID, *service) + res := d.list.AddService(m.ID, *service) + if res != nil { + logger.Errorf("Error adding service: %s", res) + } } } } @@ -85,7 +99,10 @@ func (d *DockerManager) Start() error { destroyHandler := func(m eventtypes.Message) { logger.Debugf("Destroy container '%s'", m.ID) if d.config.All { - d.list.RemoveService(m.ID) + err := d.list.RemoveService(m.ID) + if err != nil { + logger.Errorf("%s", err) + } } } @@ -110,7 +127,10 @@ func (d *DockerManager) Start() error { logger.Errorf("%s", err) continue } - d.list.AddService(container.ID, *service) + err = d.list.AddService(container.ID, *service) + if err != nil { + return fmt.Errorf("Error adding service: %s", err) + } } return nil diff --git a/src/core/docker_test.go b/internal/core/docker_test.go similarity index 98% rename from src/core/docker_test.go rename to internal/core/docker_test.go index f624b65..f575878 100644 --- a/src/core/docker_test.go +++ b/internal/core/docker_test.go @@ -9,7 +9,7 @@ package core import ( - "github.com/aacebedo/dnsdock/src/servers" + "github.com/aacebedo/dnsdock/internal/servers" "reflect" "testing" ) diff --git a/src/core/loggers.go b/internal/core/loggers.go similarity index 100% rename from src/core/loggers.go rename to internal/core/loggers.go diff --git a/src/servers/dnsserver.go b/internal/servers/dnsserver.go similarity index 86% rename from src/servers/dnsserver.go rename to internal/servers/dnsserver.go index 03a0437..4ea681c 100644 --- a/src/servers/dnsserver.go +++ b/internal/servers/dnsserver.go @@ -11,7 +11,7 @@ package servers import ( "errors" "fmt" - "github.com/aacebedo/dnsdock/src/utils" + "github.com/aacebedo/dnsdock/internal/utils" "github.com/miekg/dns" "net" "regexp" @@ -44,7 +44,7 @@ func (s Service) String() string { // ServiceListProvider represents the entrypoint to get containers type ServiceListProvider interface { - AddService(string, Service) + AddService(string, Service) error RemoveService(string) error GetService(string) (Service, error) GetAllServices() map[string]Service @@ -85,17 +85,21 @@ func (s *DNSServer) Start() error { } // Stop stops the DNSServer -func (s *DNSServer) Stop() { - s.server.Shutdown() +func (s *DNSServer) Stop() error { + return s.server.Shutdown() } // AddService adds a new container and thus new DNS records -func (s *DNSServer) AddService(id string, service Service) { +func (s *DNSServer) AddService(id string, service Service) (err error) { if len(service.IPs) > 0 { defer s.lock.Unlock() s.lock.Lock() - id = s.getExpandedID(id) + id, err = s.getExpandedID(id) + if err != nil { + return err + } + s.services[id] = &service logger.Debugf(`Added service: '%s' @@ -106,16 +110,21 @@ func (s *DNSServer) AddService(id string, service Service) { s.mux.HandleFunc(alias+".", s.handleRequest) } } else { - logger.Warningf("Service '%s' ignored: No IP provided:", id, id) + return fmt.Errorf("Service '%s' ignored: No IP provided:", id) } + + return nil } // RemoveService removes a new container and thus DNS records -func (s *DNSServer) RemoveService(id string) error { +func (s *DNSServer) RemoveService(id string) (err error) { defer s.lock.Unlock() s.lock.Lock() - id = s.getExpandedID(id) + id, err = s.getExpandedID(id) + if err != nil { + return err + } if _, ok := s.services[id]; !ok { return errors.New("No such service: " + id) } @@ -136,7 +145,10 @@ func (s *DNSServer) GetService(id string) (Service, error) { defer s.lock.RUnlock() s.lock.RLock() - id = s.getExpandedID(id) + id, err := s.getExpandedID(id) + if err != nil { + return *new(Service), err + } if s, ok := s.services[id]; ok { return *s, nil } @@ -201,7 +213,11 @@ func (s *DNSServer) handleForward(w dns.ResponseWriter, r *dns.Msg) { rr.Header().Ttl = uint32(s.config.Ttl) } } - w.WriteMsg(in) + + res := w.WriteMsg(in) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } return } @@ -213,7 +229,10 @@ func (s *DNSServer) handleForward(w dns.ResponseWriter, r *dns.Msg) { m.SetReply(r) m.Ns = s.createSOA() m.SetRcode(r, dns.RcodeRefused) // REFUSED - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } } else { logger.Debugf("DNS fowarding failed: trying next Nameserver...") @@ -280,14 +299,20 @@ func (s *DNSServer) handleRequest(w dns.ResponseWriter, r *dns.Msg) { // Send empty response for empty requests if len(r.Question) == 0 { m.Ns = s.createSOA() - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } return } // respond to SOA requests if r.Question[0].Qtype == dns.TypeSOA { m.Answer = s.createSOA() - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } return } @@ -314,7 +339,10 @@ func (s *DNSServer) handleRequest(w dns.ResponseWriter, r *dns.Msg) { // immediately return an empty NOERROR reply. m.Ns = s.createSOA() m.MsgHdr.Authoritative = true - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } return } @@ -330,7 +358,10 @@ func (s *DNSServer) handleRequest(w dns.ResponseWriter, r *dns.Msg) { logger.Debugf("No DNS record found for query '%s'", query) } - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } } func (s *DNSServer) handleReverseRequest(w dns.ResponseWriter, r *dns.Msg) { @@ -341,7 +372,10 @@ func (s *DNSServer) handleReverseRequest(w dns.ResponseWriter, r *dns.Msg) { // Send empty response for empty requests if len(r.Question) == 0 { m.Ns = s.createSOA() - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } return } @@ -356,7 +390,10 @@ func (s *DNSServer) handleReverseRequest(w dns.ResponseWriter, r *dns.Msg) { for service := range s.queryIP(query) { if r.Question[0].Qtype != dns.TypePTR { m.Ns = s.createSOA() - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } return } @@ -382,7 +419,11 @@ func (s *DNSServer) handleReverseRequest(w dns.ResponseWriter, r *dns.Msg) { } if len(m.Answer) != 0 { - w.WriteMsg(m) + res := w.WriteMsg(m) + if res != nil { + logger.Errorf("Unable to write response: '%s' ", res) + } + } else { // We didn't find a record corresponding to the query, // try forwarding @@ -455,7 +496,7 @@ func (s *DNSServer) queryServices(query string) chan *Service { } // Checks for a partial match for container SHA and outputs it if found. -func (s *DNSServer) getExpandedID(in string) (out string) { +func (s *DNSServer) getExpandedID(in string) (out string, err error) { out = in // Hard to make a judgement on small image names. @@ -463,13 +504,18 @@ func (s *DNSServer) getExpandedID(in string) (out string) { return } - if isHex, _ := regexp.MatchString("^[0-9a-f]+$", in); !isHex { + re, err := regexp.Compile("^[0-9a-f]+$"); + if err != nil { + return "", err + } + + if isHex := re.MatchString(in); !isHex { return } for id := range s.services { if len(id) == 64 { - if isHex, _ := regexp.MatchString("^[0-9a-f]+$", id); isHex { + if isHex := re.MatchString(id); isHex { if strings.HasPrefix(id, in) { out = id return diff --git a/src/servers/dnsserver_test.go b/internal/servers/dnsserver_test.go similarity index 69% rename from src/servers/dnsserver_test.go rename to internal/servers/dnsserver_test.go index 2ec748a..abe799c 100644 --- a/src/servers/dnsserver_test.go +++ b/internal/servers/dnsserver_test.go @@ -9,7 +9,7 @@ package servers import ( - "github.com/aacebedo/dnsdock/src/utils" + "github.com/aacebedo/dnsdock/internal/utils" "github.com/miekg/dns" "net" "strings" @@ -24,15 +24,27 @@ func TestDNSResponse(t *testing.T) { config.DnsAddr = TestAddr server := NewDNSServer(config) - go server.Start() + go server.Start() //nolint:errcheck // Allow some time for server to start time.Sleep(250 * time.Millisecond) - server.AddService("foo", Service{Name: "foo", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - server.AddService("baz", Service{Name: "baz", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}, TTL: -1}) - server.AddService("biz", Service{Name: "hey", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.4")}}) - server.AddService("joe", Service{Name: "joe", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.5")}, Aliases: []string{"lala.docker", "super-alias", "alias.domain"}}) + res := server.AddService("foo", Service{Name: "foo", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("baz", Service{Name: "baz", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}, TTL: -1}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("biz", Service{Name: "hey", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.4")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("joe", Service{Name: "joe", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.5")}, Aliases: []string{"lala.docker", "super-alias", "alias.domain"}}) + if res != nil { + t.Error("Error adding service", res) + } var inputs = []struct { query string @@ -115,7 +127,10 @@ func TestServiceManagement(t *testing.T) { } A := Service{Name: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}} - list.AddService("foo", A) + res := list.AddService("foo", A) + if res != nil { + t.Error("Error adding service", res) + } if len(list.GetAllServices()) != 1 { t.Error("Service count should be 1.") @@ -138,7 +153,10 @@ func TestServiceManagement(t *testing.T) { t.Error("Request to boo should have failed") } - list.AddService("boo", Service{Name: "boo", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + res = list.AddService("boo", Service{Name: "boo", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } all := list.GetAllServices() @@ -168,7 +186,10 @@ func TestServiceManagement(t *testing.T) { t.Error("Item count after remove should be 1") } - list.AddService("416261e74515b7dd1dbd55f35e8625b063044f6ddf74907269e07e9f142bc0df", Service{Name: "mysql", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + res = list.AddService("416261e74515b7dd1dbd55f35e8625b063044f6ddf74907269e07e9f142bc0df", Service{Name: "mysql", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } if s1, _ = list.GetService("416261"); s1.Name != "mysql" { t.Error("Container can't be found by prefix") @@ -188,11 +209,22 @@ func TestServiceManagement(t *testing.T) { func TestDNSRequestMatch(t *testing.T) { server := NewDNSServer(utils.NewConfig()) - server.AddService("foo", Service{Name: "foo", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - server.AddService("baz", Service{Name: "baz", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - server.AddService("abc", Service{Name: "def", Image: "ghi", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - server.AddService("qux", Service{Name: "qux", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - + res := server.AddService("foo", Service{Name: "foo", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("baz", Service{Name: "baz", Image: "bar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("abc", Service{Name: "def", Image: "ghi", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("qux", Service{Name: "qux", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } inputs := []struct { query, domain string expected int @@ -222,7 +254,7 @@ func TestDNSRequestMatch(t *testing.T) { t.Log(input.query, input.domain) actual := 0 - for _ = range server.queryServices(input.query) { + for range server.queryServices(input.query) { actual++ } @@ -235,10 +267,22 @@ func TestDNSRequestMatch(t *testing.T) { func TestDNSRequestMatchNamesWithDots(t *testing.T) { server := NewDNSServer(utils.NewConfig()) - server.AddService("boo", Service{Name: "foo.boo", Image: "bar.zar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - server.AddService("baz", Service{Name: "baz", Image: "bar.zar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - server.AddService("abc", Service{Name: "bar", Image: "zar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) - server.AddService("qux", Service{Name: "qux.quu", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + res := server.AddService("boo", Service{Name: "foo.boo", Image: "bar.zar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("baz", Service{Name: "baz", Image: "bar.zar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("abc", Service{Name: "bar", Image: "zar", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("qux", Service{Name: "qux.quu", Image: "", IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } inputs := []struct { query, domain string @@ -265,7 +309,7 @@ func TestDNSRequestMatchNamesWithDots(t *testing.T) { t.Log(input.query, input.domain) actual := 0 - for _ = range server.queryServices(input.query) { + for range server.queryServices(input.query) { actual++ } @@ -275,12 +319,21 @@ func TestDNSRequestMatchNamesWithDots(t *testing.T) { } } -func TestgetExpandedID(t *testing.T) { +func TestGetExpandedID(t *testing.T) { server := NewDNSServer(utils.NewConfig()) - server.AddService("416261e74515b7dd1dbd55f35e8625b063044f6ddf74907269e07e9f142bc0df", Service{}) - server.AddService("316261e74515b7dd1dbd55f35e8625b063044f6ddf74907269e07e9f14nothex", Service{}) - server.AddService("abcdefabcdef", Service{}) + res := server.AddService("416261e74515b7dd1dbd55f35e8625b063044f6ddf74907269e07e9f142bc0df", Service{IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } + res = server.AddService("316261e74515b7dd1dbd55f35e8625b063044f6ddf74907269e07e9f14nothex", Service{IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", Service{IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + } + res = server.AddService("abcdefabcdef", Service{IPs: []net.IP{net.ParseIP("127.0.0.1")}}) + if res != nil { + t.Error("Error adding service", res) + } inputs := map[string]string{ "416": "416", @@ -292,7 +345,8 @@ func TestgetExpandedID(t *testing.T) { } for input, expected := range inputs { - if actual := server.getExpandedID(input); actual != expected { + res, _ := server.getExpandedID(input); + if actual := res; actual != expected { t.Error(input, "Expected:", expected, "Got:", actual) } } diff --git a/src/servers/http.go b/internal/servers/http.go similarity index 93% rename from src/servers/http.go rename to internal/servers/http.go index 14ff203..0bfc360 100644 --- a/src/servers/http.go +++ b/internal/servers/http.go @@ -10,7 +10,7 @@ package servers import ( "encoding/json" - "github.com/aacebedo/dnsdock/src/utils" + "github.com/aacebedo/dnsdock/internal/utils" "github.com/gorilla/mux" "net/http" ) @@ -111,7 +111,11 @@ func (s *HTTPServer) addService(w http.ResponseWriter, req *http.Request) { return } - s.list.AddService(id, *service) + err := s.list.AddService(id, *service) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } func (s *HTTPServer) removeService(w http.ResponseWriter, req *http.Request) { @@ -177,8 +181,11 @@ func (s *HTTPServer) updateService(w http.ResponseWriter, req *http.Request) { // todo: this probably needs to be moved. consider stop event in the // middle of sending PATCH. container would not be removed. - s.list.AddService(id, service) - + err = s.list.AddService(id, service) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } func (s *HTTPServer) setTTL(w http.ResponseWriter, req *http.Request) { diff --git a/src/servers/http_test.go b/internal/servers/http_test.go similarity index 95% rename from src/servers/http_test.go rename to internal/servers/http_test.go index 97a44b3..1355ba8 100644 --- a/src/servers/http_test.go +++ b/internal/servers/http_test.go @@ -9,8 +9,8 @@ package servers import ( - "github.com/aacebedo/dnsdock/src/utils" - "io/ioutil" + "github.com/aacebedo/dnsdock/internal/utils" + "io" "net/http" "strings" "testing" @@ -24,7 +24,7 @@ func TestServiceRequests(t *testing.T) { config.HttpAddr = TestAddr server := NewHTTPServer(config, NewDNSServer(config)) - go server.Start() + go server.Start() //nolint:errcheck // Allow some time for server to start time.Sleep(250 * time.Millisecond) @@ -66,7 +66,7 @@ func TestServiceRequests(t *testing.T) { continue } - actual, err := ioutil.ReadAll(resp.Body) + actual, err := io.ReadAll(resp.Body) if err != nil { t.Error(err) } diff --git a/src/servers/loggers.go b/internal/servers/loggers.go similarity index 100% rename from src/servers/loggers.go rename to internal/servers/loggers.go diff --git a/src/utils/config.go b/internal/utils/config.go similarity index 100% rename from src/utils/config.go rename to internal/utils/config.go diff --git a/src/utils/config_test.go b/internal/utils/config_test.go similarity index 100% rename from src/utils/config_test.go rename to internal/utils/config_test.go diff --git a/src/utils/loggers.go b/internal/utils/loggers.go similarity index 92% rename from src/utils/loggers.go rename to internal/utils/loggers.go index 357345a..58d08c4 100644 --- a/src/utils/loggers.go +++ b/internal/utils/loggers.go @@ -10,7 +10,7 @@ package utils import ( "github.com/op/go-logging" - "io/ioutil" + "io" "os" ) @@ -22,7 +22,7 @@ func InitLoggers(verbosity int) (err error) { switch { case verbosity == 0: - backend = logging.NewLogBackend(ioutil.Discard, "", 0) + backend = logging.NewLogBackend(io.Discard, "", 0) case verbosity >= 1: backend = logging.NewLogBackend(os.Stdout, "", 0) } diff --git a/readme.md b/readme.md index a547c79..3fa1ab0 100644 --- a/readme.md +++ b/readme.md @@ -33,7 +33,7 @@ if the crashed container is restarted. - No support for Javascript plugins. -- There's a slight difference in a way image names are extracted from a +- There’s a slight difference in a way image names are extracted from a container. Skydock uses the last tag set on image while dnsdock uses the specific tag that was used when the container was created. This means that if a new version of an image comes out and untags the image that your container @@ -41,27 +41,24 @@ still uses, the DNS requests for this old container still work. #### Build -##### Building without docker: +There are two ways to build the tool -Install a golang development environment on your host and type the following commands: +##### Building with devbox: + +Install [devbox](https://www.jetpack.io/devbox) on your host and execute the following commands: ``` -export GOPATH=/tmp/go -export PATH=${PATH}:${GOPATH}/bin -go get -v github.com/tools/godep -go get -d -v https://github.com/aacebedo/dnsdock -cd ${GOPATH}/src/github.com/aacebedo/dnsdock -godep restore -cd ${GOPATH}/src/github.com/aacebedo/dnsdock/src -go build -o ${GOPATH}/bin/dnsdock +$> devbox run test +$> devbox run --env GOARCH=[amd64|arm] build ``` -##### Building with docker: +##### Building using a devcontainer: -To build with docker you need [rocker](https://github.com/grammarly/rocker). Check the -website to install it and type the following commands: +Install [VSCode devcontainer +extension](https://code.visualstudio.com/docs/devcontainers/containers) + or [devpod](https://www.devpod.io) and execute the following commands: ``` -git clone https://github.com/aacebedo/dnsdock -rocker build -var ARCH=[amd64|arm] -var OUTPUT_DIR= +$> go get ./... +$> mkdir -p build && GOARCH=[amd64|arm] go build -o build/dnsdock ./cmd/dnsdock ``` #### Usage @@ -148,7 +145,7 @@ Additional configuration options to dnsdock command: --tlscert="$HOME/.docker/cert.pem": Path to client certificate --tlskey="$HOME/.docker/key.pem": Path to client certificate private key --all: Process all container even if they are stopped ---forcettl: Change TTL value of responses coming from remote servers +--forcettl: Change TTL value of responses coming from remote servers ``` If you also want to let the host machine discover the containers add `nameserver 172.17.0.1` to your `/etc/resolv.conf`. @@ -156,14 +153,14 @@ If you also want to let the host machine discover the containers add `nameserver #### SELinux and Fedora / RHEL / CentOS -Mounting docker daemon's unix socket may not work with default configuration on +Mounting docker daemon’s unix socket may not work with default configuration on these platforms. Please use [selinux-dockersock](https://github.com/dpw/selinux-dockersock) to fix this. More information in [#11](https://github.com/aacebedo/dnsdock/issues/11). #### TLS Authentication -Instead of connecting to the Docker daemon's UNIX socket, you may prefer to +Instead of connecting to the Docker daemon’s UNIX socket, you may prefer to connect via a TLS-protected TCP socket (for example, if you are running Swarm). The `-tlsverify` option enables TLS, and the three additional options (`-tlscacert`, `-tlscert` and `-tlskey`) must also be specified. Alternatively, @@ -234,7 +231,7 @@ docker run -e DNSDOCK_ALIAS=db.docker,sql.docker -e DNSDOCK_TTL=10 \ #### Overrides with docker labels -If you wish to fine tune the DNS response addresses you can define specific labels during +If you wish to fine tune the DNS response addresses you can define specific labels during container creation. This overrides the default matching scheme from container and image name. Supported labels are `com.dnsdock.ignore`, `com.dnsdock.alias`, `com.dnsdock.name`, `com.dnsdock.tags`, `com.dnsdock.image`, @@ -263,7 +260,7 @@ docker run -l com.dnsdock.tags=master -l com.dnsdock.name=mysql -l com.dnsdock.r If you want dnsdock to skip processing a specific container set its `com.dnsdock.ignore` label. -You can force the value of the IP address returned in the DNS record with the +You can force the value of the IP address returned in the DNS record with the `com.dnsdock.ip_addr` label. This can be useful if you have a reverse proxy such as traefik in a container with mapped port and you want to redirect your clients to the front server instead of an internal docker container ip address. #### OSX Usage