From ec756fca818c6a951580511478d08d9866d50ac4 Mon Sep 17 00:00:00 2001 From: Thomas Schaffter Date: Mon, 5 Jul 2021 15:09:41 -0700 Subject: [PATCH] Upgrade project (#16) * Update update workflow * Update README * Update CI workflow * Fix CI workflow * Update README and bump project version to 1.2.1 * Rename tag nightly to weekly --- DNSMASQ_VERSION => .dnsmasq-version | 0 .github/workflows/ci.yml | 103 ++++++++++++++++------------ .github/workflows/update.yml | 16 +++-- README.md | 50 ++++++++++---- 4 files changed, 105 insertions(+), 64 deletions(-) rename DNSMASQ_VERSION => .dnsmasq-version (100%) diff --git a/DNSMASQ_VERSION b/.dnsmasq-version similarity index 100% rename from DNSMASQ_VERSION rename to .dnsmasq-version diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5a1ad6..48ff7dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,6 @@ on: push: branches: - main - - develop tags: - '*.*.*' pull_request: @@ -15,68 +14,93 @@ env: docker_repository: tschaffter/dnsmasq jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Lint Dockerfiles - uses: docker://hadolint/hadolint:latest - with: - entrypoint: hadolint - args: Dockerfile - - name: Validate docker-compose.yml - run: | - docker-compose -f docker-compose.yml config >/dev/null - - docker: - needs: [lint] + configure: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Prepare - id: prep + - name: Create configuration run: | DOCKER_IMAGE=${{ env.docker_repository }} VERSION=noop PUSH=false if [ "${{ github.event_name }}" = "schedule" ]; then - VERSION=nightly + VERSION=weekly PUSH=true elif [[ $GITHUB_REF == refs/tags/* ]]; then - # VERSION=${GITHUB_REF#refs/tags/} - VERSION=$(cat DNSMASQ_VERSION) + # VERSION=${GITHUB_REF#refs/tags/} # use Dnsmasq version instead + VERSION=$(cat .dnsmasq-version) elif [[ $GITHUB_REF == refs/heads/* ]]; then VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then VERSION=edge PUSH=true fi - elif [[ $GITHUB_REF == refs/pull/* ]]; then - VERSION=pr-${{ github.event.number }} fi TAGS="${DOCKER_IMAGE}:${VERSION}" - if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + if [[ "$VERSION" =~ ^[0-9]{1,3}\.[0-9]{1,3}$ ]]; then MAJOR=${VERSION%.*} - TAGS="$TAGS,${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" + TAGS="$TAGS,${DOCKER_IMAGE}:latest" TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}-${GITHUB_SHA::8}" PUSH=true - # elif [ "${{ github.event_name }}" = "push" ]; then - # TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" + elif [ "$VERSION" = "edge" ]; then + TAGS="$TAGS,${DOCKER_IMAGE}:edge-${GITHUB_SHA::8}" + PUSH=true fi - echo ::set-output name=version::${VERSION} - echo ::set-output name=tags::${TAGS} - echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - echo ::set-output name=push::${PUSH} + printf "%s\n" \ + "version=${VERSION}" \ + "tags=${TAGS}" \ + "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \ + "push=${PUSH}" | tee -a .github_env + + - name: Upload .github_env + uses: actions/upload-artifact@v2 + with: + name: GITHUB_ENV + path: .github_env + + lint: + needs: [configure] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Lint Dockerfiles + uses: docker://hadolint/hadolint:latest + with: + entrypoint: hadolint + args: Dockerfile + + - name: Validate docker-compose.yml + run: | + docker-compose -f docker-compose.yml config >/dev/null + + docker: + needs: [lint] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Download .github_env + uses: actions/download-artifact@v2 + with: + name: GITHUB_ENV + path: . + + - name: Restore $GITHUB_ENV + run: cat .github_env >> $GITHUB_ENV + - name: Set up QEMU uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub if: steps.prep.outputs.push == 'true' uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push id: docker_build uses: docker/build-push-action@v2 @@ -84,18 +108,11 @@ jobs: context: . file: Dockerfile platforms: linux/amd64,linux/arm/v7,linux/arm64 - push: ${{ steps.prep.outputs.push }} - tags: ${{ steps.prep.outputs.tags }} + push: ${{ env.push }} + tags: ${{ env.tags }} labels: | - org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.created=${{ env.created }} org.opencontainers.image.source=${{ github.repositoryUrl }} - org.opencontainers.image.version=${{ steps.prep.outputs.version }} + org.opencontainers.image.version=${{ env.version }} org.opencontainers.image.revision=${{ github.sha }} org.opencontainers.image.licenses=${{ github.event.repository.license.name }} - # - name: Docker Hub Description - # if: steps.prep.outputs.push == 'true' - # uses: peter-evans/dockerhub-description@v2 - # with: - # username: ${{ secrets.DOCKERHUB_USERNAME }} - # password: ${{ secrets.DOCKERHUB_PASSWORD }} - # repository: ${{ env.docker_repository }} diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index c36a6a1..46ca8d5 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -1,4 +1,4 @@ -name: Update project release +name: Update to latest Dnsmasq version on: schedule: @@ -6,13 +6,14 @@ on: jobs: check-and-update: - name: Check and update Dnsmasq release + name: Check and update Dnsmasq runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: Get latest Dnsmasq release version + + - name: Get the latest release version of Dnsmasq run: | git clone git://thekelleys.org.uk/dnsmasq.git cd dnsmasq @@ -20,16 +21,19 @@ jobs: # Trim leading 'v' in semantic version new_version=${new_version:1} echo "NEW_VERSION=$(echo $new_version)" >> $GITHUB_ENV + - name: Update Dnsmasq config example run: | cp dnsmasq/dnsmasq.conf.example ../dnsmasq.conf.example rm -fr dnsmasq - - name: Update Docker image version + + - name: Update Dnsmasq version run: | - current_version=$(cat DNSMASQ_VERSION) - for f in DNSMASQ_VERSION Dockerfile docker-compose.yml; do + current_version=$(cat .dnsmasq-version) + for f in .dnsmasq-version README Dockerfile docker-compose.yml; do sed -i "s/${current_version}/${{env.NEW_VERSION}}/g" "$f" done + - name: Send pull request to update to new version uses: peter-evans/create-pull-request@v3 with: diff --git a/README.md b/README.md index 265c3ee..a93f564 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@ [![GitHub Release](https://img.shields.io/github/release/tschaffter/dnsmasq.svg?include_prereleases&color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/releases) [![GitHub CI](https://img.shields.io/github/workflow/status/tschaffter/dnsmasq/CI.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/actions) -[![GitHub License](https://img.shields.io/github/license/tschaffter/dnsmasq.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/blob/develop/LICENSE) +[![GitHub License](https://img.shields.io/github/license/tschaffter/dnsmasq.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/tschaffter/dnsmasq/blob/main/LICENSE) [![Docker Pulls](https://img.shields.io/docker/pulls/tschaffter/dnsmasq.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=pulls&logo=docker)](https://hub.docker.com/r/tschaffter/dnsmasq) -Docker image for Dnsmasq -## Overview +## Introduction [Dnsmasq] is a lightweight, easy to configure DNS forwarder, designed to provide DNS (and optionally DHCP and TFTP) services to a small-scale network. It can also serve the names of local machines which are not in the global DNS.If you own an Asus router, it is possible that [your Asus router is using Dnsmasq]. + ## Features This repository: @@ -25,6 +25,19 @@ This repository: Docker container (e.g. [tschaffter/getdns-stubby]), which is not (yet?) supported natively by Dnsmasq. + +## Specification + +- Dnsmasq version: 2.85 +- Project version: 1.2.1 +- Docker image: [tschaffter/dnsmasq] + + +## Requirements + +- [Docker Engine] >=19.03.0 + + ## Usage ### Configuration @@ -65,10 +78,13 @@ arguments. Start the Dnsmasq server. Add the option `-d` or `--detach` to run in the background. - docker-compose up --build +```console +docker compose up +``` + +To stop the server, enter `Ctrl+C` followed by `docker compose down`. If running +in detached mode, you will only need to enter `docker compose down`. -To stop the server, enter `Ctrl+C` followed by `docker-compose down`. If running -in detached mode, you will only need to enter `docker-compose down`. ## Resolving domain names @@ -107,6 +123,7 @@ the first lookup, and all subsequent lookups don't take any time because they are served from the cache. For more information on how to configure Dnsmasq cache, please read the article [How to Do DNS Caching with dnsmasq]. + ## Resolving a local domain name See example specified in @@ -124,6 +141,7 @@ myhost.example.com. 0 IN A 192.168.1.10 We can see above that the host name `myhost.example.com` has been successfully resolved to the local IP address `192.168.1.10`. + ## Versioning ### GitHub tags @@ -136,18 +154,19 @@ always point to the same git commit once it has been created. The artifact published by this repository is a Docker image. The versions of the image are aligned with the versions of Dnsmasq, not the GitHub tags of this -repository. The motivation behind this strategy is that the tag directly informs -the user on the version of Dnsmasq that is being deployed. +repository. The motivation behind this strategy is that this project is mainly a +wrapper for Dnsmasq and that it is more informative to the user to use a Docker +image tag that correspond to the version of Dnsmasq being deployed. The table below describes the image tags available. -| Tag name | Moving | Description | -|---|---|---| -| `latest` | Yes | Latest stable release | -| `edge` | Yes | Lastest commit made to the default branch | -| `` | Yes | Latest stable release for the Dnsmasq major version `` | -| `.` | Yes | Latest stable release for the Dnsmasq version `.` | -| `.-` | No | Same as above but with the reference to the git commit | +| Tag name | Moving | Description +|-----------------------------|--------|------------ +| `latest` | Yes | Latest stable release. +| `edge` | Yes | Latest commit made to the default branch. +| `edge-` | No | Same as above with the reference to the git commit. +| `.` | No | Stable release. +| `.-` | No | Same as above with the reference to the git commit. You should avoid using a moving tag like `latest` when deploying containers in production, because this makes it hard to track which version of the image is @@ -164,6 +183,7 @@ then it makes sense to use a moving tag. [Dnsmasq]: https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=summary [your Asus router is using Dnsmasq]: https://unfinishedbitness.info/2015/05/26/asuswrt-finalized-setup/ [Stubby]: https://github.com/getdnsapi/stubby +[tschaffter/dnsmasq]: https://hub.docker.com/repository/docker/tschaffter/dnsmasq [Dig]: https://en.wikipedia.org/wiki/Dig_(command) [semantic versioning]: https://semver.org/ [tschaffter/getdns-stubby]: https://github.com/tschaffter/getdns-stubby