Skip to content

Commit

Permalink
dns check init
Browse files Browse the repository at this point in the history
  • Loading branch information
cpnviz committed Oct 18, 2021
0 parents commit 4af5fbd
Show file tree
Hide file tree
Showing 10 changed files with 969 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
app.json
app2.json
cloudbuild.yaml
dist/
dns-check
deployment.yaml
Makefile
bin/
ignored.json
89 changes: 89 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at https://goreleaser.com

project_name: dns-check
env:
- GO111MODULE=on

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
binary: dns-check
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
dockers:
- image_templates:
- ghcr.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-amd64
- docker.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-amd64
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --platform=linux/amd64
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/chandanpasunoori/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/chandanpasunoori/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT
- image_templates:
- ghcr.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-arm64v8
- docker.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-arm64v8
goarch: arm64
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- --platform=linux/arm64/v8
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/chandanpasunoori/{{ .ProjectName }}
- --label=org.opencontainers.image.source=https://github.com/chandanpasunoori/{{ .ProjectName }}
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.licenses=MIT
docker_manifests:
- name_template: ghcr.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-arm64v8
- name_template: ghcr.io/chandanpasunoori/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-arm64v8
- name_template: docker.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}
image_templates:
- docker.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-amd64
- docker.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-arm64v8
- name_template: docker.io/chandanpasunoori/{{ .ProjectName }}:latest
image_templates:
- docker.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-amd64
- docker.io/chandanpasunoori/{{ .ProjectName }}:{{ .Version }}-arm64v8
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:latest as alpine_builder
RUN apk --no-cache add ca-certificates
RUN apk --no-cache add tzdata

FROM scratch
COPY --from=alpine_builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=alpine_builder /usr/share/zoneinfo /usr/share/zoneinfo
ENTRYPOINT ["/dns-check"]
COPY dns-check /
73 changes: 73 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cmd

import (
"encoding/json"
"io/ioutil"
"os"

"github.com/chandanpasunoori/dns-check/pkg"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

const (
version = "0.0.1"
)

var verbose bool
var configDoc string
var config pkg.Config

var rootCmd = &cobra.Command{
Use: "dns-check",
Short: "Built to ease process of checking list domains dns pointing periodically and alert",
Version: version,
Run: func(cmd *cobra.Command, args []string) {
if verbose {
logger.SetLevel(log.DebugLevel)
}
configBytes, err := ioutil.ReadFile(configDoc)
if err != nil {
logger.WithError(err).Errorf("config file not found at " + configDoc)
os.Exit(1)
}
if err := json.Unmarshal(configBytes, &config); err != nil {
logger.WithError(err).Errorf("error parsing config")
os.Exit(1)
}
logger.Info(
"dns-check " + version + " is ready to check domain",
)
pkg.CheckDNSTarget(config)
},
}

var logger = log.Logger{
Out: os.Stdout,
Formatter: &log.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05.000",
},
Level: log.InfoLevel,
}

func Execute() {
//@todo: provide usage documentation with config examples
if genDoc := os.Getenv("GEN_DOC"); genDoc == "true" {
err := doc.GenMarkdownTree(rootCmd, "./docs")
if err != nil {
log.Errorf("Failed generating docs: %v", err)
}
}

if err := rootCmd.Execute(); err != nil {
logger.WithError(err).Errorf("error executing command")
os.Exit(1)
}
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose mode")
rootCmd.PersistentFlags().StringVarP(&configDoc, "config", "c", "app.json", "job configuration file path")
_ = rootCmd.MarkFlagRequired("config")
}
20 changes: 20 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/chandanpasunoori/dns-check

go 1.17

require (
github.com/aws/aws-sdk-go v1.41.4
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit 4af5fbd

Please sign in to comment.