Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xERR0R committed Jan 12, 2020
0 parents commit 01a8a40
Show file tree
Hide file tree
Showing 43 changed files with 4,999 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
.idea
.github
testdata/
40 changes: 40 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI Build
on: [push]
jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.21.0

- name: Run golangci-lint
run: make lint

- name: Test
run: make test

- name: Build
run: make build

- name: Docker images
run: make docker-build
54 changes: 54 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release

on:
push:
tags:
- v*

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- uses: actions/checkout@v1

- name: Build
run: make build

- name: Test
run: make test

- name: Build multiarch binaries
run: make buildMultiArchRelease

- name: Upload amd64 binary to release
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: bin/blocky_amd64
asset_name: blocky_amd64
tag: ${{ github.ref }}
overwrite: true

- name: Upload arm32v6 binary to release
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: bin/blocky_arm32v6
asset_name: blocky_arm32v6
tag: ${{ github.ref }}
overwrite: true

- name: Build the Docker image and push
run: |
mkdir -p ~/.docker && echo "{\"experimental\": \"enabled\"}" > ~/.docker/config.json
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
make docker-build
make dockerManifestAndPush
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/
*.iml
bin/
config.yml
todo.txt
53 changes: 53 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
linters:
enable:
- govet
- errcheck
- staticcheck
- unused
- gosimple
- structcheck
- varcheck
- ineffassign
- deadcode
- typecheck
- bodyclose
- golint
- stylecheck
- gosec
- interfacer
- unconvert
- dupl
- goconst
- gocyclo
- gocognit
- gofmt
- goimports
- maligned
- depguard
- misspell
- lll
- unparam
- dogsled
- funlen
- gochecknoglobals
- gochecknoinits
- gocritic
- godox
- nakedret
- prealloc
- whitespace
- wsl

disable-all: false
presets:
- bugs
- unused
fast: false

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gochecknoglobals
- dupl
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# build stage
FROM golang:alpine AS build-env
RUN apk add --no-cache \
git \
make \
gcc \
libc-dev \
tzdata \
zip \
ca-certificates

ENV GO111MODULE=on \
CGO_ENABLED=0

WORKDIR /src

COPY go.mod .
COPY go.sum .
RUN go mod download

# add source
ADD . .

ARG opts
RUN env ${opts} make build

# final stage
FROM scratch
COPY --from=build-env /src/bin/blocky /app/blocky

# the timezone data:
COPY --from=build-env /usr/share/zoneinfo /usr/share/zoneinfo
# the tls certificates:
COPY --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

WORKDIR /app

ENTRYPOINT ["/app/blocky"]
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.PHONY: all clean build test lint run buildMultiArchRelease docker-build dockerManifestAndPush help
.DEFAULT_GOAL := help

VERSION := $(shell git describe --always --tags)
BUILD_TIME=$(shell date '+%Y%m%d-%H%M%S')
DOCKER_IMAGE_NAME="spx01/blocky"
BINARY_NAME=blocky
BIN_OUT_DIR=bin

all: test lint build ## Build binary (with tests)

clean: ## cleans output directory
$(shell rm -rf $(BIN_OUT_DIR)/*)

build: ## Build binary
go build -v -ldflags="-w -s -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}" -o $(BIN_OUT_DIR)/$(BINARY_NAME)$(BINARY_SUFFIX)

test: ## run tests
go test -v -cover ./...

lint: ## run golangcli-lint checks
$(shell go env GOPATH)/bin/golangci-lint run

run: build ## Build and run binary
./$(BIN_OUT_DIR)/$(BINARY_NAME)

buildMultiArchRelease: ## builds binary for multiple archs
$(MAKE) build GOARCH=arm GOARM=6 BINARY_SUFFIX=_arm32v6
$(MAKE) build GOARCH=amd64 BINARY_SUFFIX=_amd64

docker-build: ## Build multi arch docker images
docker build --build-arg opts="GOARCH=arm GOARM=6" --pull --tag ${DOCKER_IMAGE_NAME}:${VERSION}-arm32v6 .
docker build --build-arg opts="GOARCH=amd64" --pull --tag ${DOCKER_IMAGE_NAME}:${VERSION}-amd64 .

dockerManifestAndPush: ## create manifest for multi arch images and push to docker hub
docker push ${DOCKER_IMAGE_NAME}:${VERSION}-arm32v6
docker push ${DOCKER_IMAGE_NAME}:${VERSION}-amd64

docker manifest create ${DOCKER_IMAGE_NAME}:${VERSION} ${DOCKER_IMAGE_NAME}:${VERSION}-amd64 ${DOCKER_IMAGE_NAME}:${VERSION}-arm32v6
docker manifest annotate ${DOCKER_IMAGE_NAME}:${VERSION} ${DOCKER_IMAGE_NAME}:${VERSION}-arm32v6 --os linux --arch arm
docker manifest push ${DOCKER_IMAGE_NAME}:${VERSION} --purge
docker manifest create ${DOCKER_IMAGE_NAME}:latest ${DOCKER_IMAGE_NAME}:${VERSION}-amd64 ${DOCKER_IMAGE_NAME}:${VERSION}-arm32v6
docker manifest annotate ${DOCKER_IMAGE_NAME}:latest ${DOCKER_IMAGE_NAME}:${VERSION}-arm32v6 --os linux --arch arm
docker manifest push ${DOCKER_IMAGE_NAME}:latest --purge

help: ## Shows help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
47 changes: 47 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
upstream:
externalResolvers:
# - udp:8.8.8.8
# - udp:8.8.4.4
- tcp-tls:1.1.1.1:853
- tcp-tls:1.0.0.1:853
customDNS:
mapping:
spx.duckdns.org: 192.168.178.3
conditional:
mapping:
fritz.box: udp:192.168.178.1
blocking:
blackLists:
ads:
- https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt
- https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
- https://mirror1.malwaredomains.com/files/justdomains
- http://sysctl.org/cameleon/hosts
- https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist
- https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt
special:
- https://hosts-file.net/ad_servers.txt
whiteLists:
ads:
- whitelist.txt
clientGroupsBlock:
default:
- ads
- special
Laptop-D.fritz.box:
- ads
blockType: zeroIp

clientLookup:
upstream: udp:192.168.178.1
singleNameOrder:
- 2
- 1

#queryLog:
# dir: /tmp
# perClient: true
# logRetentionDays: 7

port: 55555
logLevel: info
Loading

0 comments on commit 01a8a40

Please sign in to comment.