From ea3c2ca837496bbe412dfff00945542c1ecda06f Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Thu, 5 Sep 2024 17:35:56 +0300 Subject: [PATCH] Added docker image --- .github/workflows/build.yaml | 4 +-- .github/workflows/docker.yaml | 53 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 8 +++++- Dockerfile | 33 ++++++++++++++++++++++ Makefile | 2 +- README.md | 22 ++++++++++++--- 6 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/docker.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c9e144b..ce98e07 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -25,7 +25,7 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: 1.x + go-version: 1.23 - name: Run tests run: |- @@ -49,7 +49,7 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: 1.x + go-version: 1.23 - name: Prepare environment run: |- diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..70609b5 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,53 @@ +name: Docker + +on: + push: + tags: + - 'v*' + branches: + - 'master' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: "VERSION=${GITHUB_REF##*/}" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2320e11..98ffd2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,15 @@ adheres to [Semantic Versioning][semver]. ## [Unreleased] +### Added + +* Added [Docker image][dockerimage]. + +[dockerimage]: https://github.com/ameshkov/godnsbench/pkgs/container/godnsbench + ### Changed -* Updated dependencies +* Updated dependencies. [unreleased]: https://github.com/ameshkov/godnsbench/compare/v1.8.1...HEAD diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..310f923 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Step 1: Use the official Golang image as the build environment. +# This image includes all the tools needed to compile Go applications. +FROM golang:1.23 as builder + +# Version will be passed as a part of the build. +ARG VERSION=dev + +# Set the Current Working Directory inside the container. +WORKDIR /app + +# Copy the local package files to the container's workspace. +COPY . . + +# Build the Go app for a Linux system. +RUN VERSION=${VERSION} make build + +# Step 2: Use a builder image to get the latest certificates. +FROM alpine:latest as certs + +# Download the latest CA certificates +RUN apk --update add ca-certificates + +# Step 3: Use a Docker multi-stage build to create a lean production image. +# Start from a scratch (empty) image to keep the image size small. +FROM scratch + +# Copy the binary from the builder stage to the production image. +COPY --from=builder /app/godnsbench / + +# Copy the CA certificates from the certs image. +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ + +ENTRYPOINT ["/godnsbench"] \ No newline at end of file diff --git a/Makefile b/Makefile index 18c2fc5..aed1a88 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ endif default: build build: clean - go build -ldflags "-X main.VersionString=$(VERSION)" + CGO_ENABLED=0 go build -ldflags "-X main.VersionString=$(VERSION)" release: check-env-release mkdir -p $(BUILDDIR) diff --git a/README.md b/README.md index 4167df4..7342793 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,29 @@ # godnsbench -A very simple DNS benchmarking tool based on [dnsproxy](https://github.com/AdguardTeam/dnsproxy). +A very simple DNS benchmarking tool based on [dnsproxy][dnsproxy]. + +[dnsproxy]: https://github.com/AdguardTeam/dnsproxy ## How to install * Using homebrew: - ``` + ```shell brew install ameshkov/tap/godnsbench ``` * From source: - ``` + ```shell go install github.com/ameshkov/godnsbench@latest ``` -* You can get a binary from the [releases page](https://github.com/ameshkov/godnsbench/releases). +* You can use [a Docker image][dockerimage]: + ```shell + docker run --rm ghcr.io/ameshkov/godnsbench --help + ``` +* You can get a binary from the [releases page][releases]. + +[dockerimage]: https://github.com/ameshkov/godnsbench/pkgs/container/godnsbench +[releases]: https://github.com/ameshkov/godnsbench/releases ## Usage @@ -44,29 +53,34 @@ Help Options: ## Examples 10 connections, 1000 queries to Google DNS using DNS-over-TLS: + ```shell godnsbench -a tls://dns.google -p 10 -c 1000 ``` 10 connections, 1000 queries to Google DNS using DNS-over-HTTPS with rate limit not higher than 10 queries per second: + ```shell godnsbench -a https://dns.google/dns-query -p 10 -c 1000 -r 10 ``` 10 connections, 1000 queries for `example.net` to Google DNS using DNS-over-TLS: + ```shell godnsbench -a https://dns.google/dns-query -p 10 -c 1000 -q example.net ``` 10 connections, 1000 queries for `example.net` with timeout 1 second to AdGuard DNS using DNS-over-QUIC: + ```shell godnsbench -a quic://dns.adguard.com -p 10 -c 1000 -t 1 -q example.net ``` 10 connections, 1000 queries for random subdomains of `example.net` with timeout 1 second to Google DNS using DNS-over-TLS: + ```shell godnsbench -a tls://dns.google -p 10 -c 1000 -t 1 -q {random}.example.net ```