1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Migrate Build and Integration Tests to CircleCI (#1292)

* Change the CI from GitHub Actions to [CircleCI](https://app.circleci.com/pipelines/github/StackExchange/dnscontrol?filter=all).
* Adds more platforms in the release as inspired by and discussed in #1260.
This commit is contained in:
Chris Hunt
2021-12-17 07:14:27 -05:00
committed by GitHub
parent 14c3014a2e
commit cc4eba6f16
6 changed files with 243 additions and 180 deletions

View File

@@ -1,5 +1,164 @@
version: 2.1
parameters:
cache-key:
type: integer
default: 1639697695
description: Change to force cache reset `pwsh > Get-Date -UFormat %s`
gover:
type: string
default: "1.17" # https://circleci.com/developer/images/image/cimg/go#image-tags
description: Go Version to use
jobs:
{}
build:
docker:
- image: cimg/go:<< pipeline.parameters.gover >>
resource_class: 2xlarge
environment: # environment variables for the build itself
TEST_RESULTS: /tmp/test-results
steps:
- checkout
- restore_cache: # restores saved cache if no changes are detected since last run
keys:
- linux-go-{{ checksum "go.sum" }}-<< pipeline.parameters.cache-key >>
- run:
name: Install goreleaser
command: go install github.com/goreleaser/goreleaser@latest
- run: mkdir -p "$TEST_RESULTS"
- run:
name: Run unit tests
# store the results of our tests in the $TEST_RESULTS directory
command: gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- $PACKAGE_NAMES
- store_test_results: # upload test results for display in Test Summary
path: /tmp/test-results
- run:
name: Build binaries
command: goreleaser build --snapshot
- save_cache: # restores saved cache if no changes are detected since last run
key: linux-go-{{ checksum "go.sum" }}-<< pipeline.parameters.cache-key >>
paths:
- /home/circleci/go/pkg/mod
integration-tests:
docker:
- image: cimg/go:<< pipeline.parameters.gover >>
environment: # environment variables for the build itself
TEST_RESULTS: /tmp/test-results
GOTESTSUM_FORMAT: testname
BIND_DOMAIN: example.com
# FYI: Hexonet provides these credentials for use for public testing. They give access to a test area, not a real system. It is not a security issue to expose them.
#
# FYI: The domain name name was selected at random. If it stops working, this command will list domains to choose from:
# echo '{ "hexo": { "apientity": "OTE", "apilogin": "test.user", "apipassword": "test.passw0rd" } }' > hexo-creds.json ; dnscontrol get-zones --creds hexo-creds.json --format=nameonly hexo HEXONET all
HEXONET_DOMAIN: a-b-c-movies.com
HEXONET_ENTITY: OTE
HEXONET_PW: test.passw0rd
HEXONET_UID: test.user
AZURE_DNS_RESOURCE_GROUP: DNSControl
GCLOUD_EMAIL: dnscontrol@dnscontrol-dev.iam.gserviceaccount.com
GCLOUD_PROJECT: dnscontrol-dev
GCLOUD_TYPE: service_account
NAMEDOTCOM_URL: api.name.com
NAMEDOTCOM_USER: dnscontroltest
parameters:
provider:
type: string
steps:
- checkout
- run: mkdir -p "$TEST_RESULTS"
- restore_cache: # restores saved cache if no changes are detected since last run
keys:
- linux-go-{{ checksum "go.sum" }}-<< pipeline.parameters.cache-key >>
- run:
name: Run integration tests for << parameters.provider >> provider
working_directory: integrationTest
no_output_timeout: 20m
command: |
if [ -n "$<< parameters.provider >>_DOMAIN" ] ; then
gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- -timeout 20m -v -verbose -provider << parameters.provider >> -cfworkers=false
else
echo "Skip test for << parameters.provider >> provider"
fi
- store_test_results: # upload test results for display in Test Summary
path: /tmp/test-results
release:
docker:
- image: cimg/go:<< pipeline.parameters.gover >>
resource_class: 2xlarge
steps:
- checkout
- restore_cache: # restores saved cache if no changes are detected since last run
keys:
- linux-go-{{ checksum "go.sum" }}-<< pipeline.parameters.cache-key >>
- setup_remote_docker:
version: 20.10.11
- run:
name: Install goreleaser
command: go install github.com/goreleaser/goreleaser@latest
- run: goreleaser release
workflows:
{}
version: 2
build:
jobs:
- build
- integration-tests:
requires: [build]
context: DNSProviders
matrix:
parameters:
provider:
# Providers that don't require secrets: (alphabetical)
- BIND
- HEXONET
# Providers designated "officially supported": (alphabetical)
- AZURE_DNS
- CLOUDFLAREAPI
- GCLOUD
- NAMEDOTCOM
- ROUTE53
# All others: (alphabetical)
- CLOUDNS
- DIGITALOCEAN
- GANDI_V5
- HEDNS
- INWX
- POWERDNS
- release:
requires: [integration-tests]
# Only run this job on git tag pushes
filters:
branches:
only: [main, master]
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/

View File

@@ -1,160 +0,0 @@
---
name: build
on:
pull_request:
branches: [ master ]
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2.4.0
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.15
- name: Cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build binaries
run: go run build/build.go
- name: Run unit tests
run: go test ./...
integration-tests:
runs-on: ubuntu-latest
needs: build
concurrency: ${{ matrix.provider }}
strategy:
fail-fast: false
matrix:
provider:
# Providers that don't require secrets: (alphabetical)
- BIND
- HEXONET
# Providers designated "officially supported": (alphabetical)
- AZURE_DNS
- CLOUDFLAREAPI
- GCLOUD
- NAMEDOTCOM
- ROUTE53
# All others: (alphabetical)
- CLOUDNS
- DIGITALOCEAN
- GANDI_V5
- HEDNS
- INWX
- POWERDNS
# Bring-Your-Own-Secrets:
# To reduce the risk of secrets being logged by third-parties, secrets
# come from the account of the fork. For example, the PR submitted by
# a member of the project has access to the secrets in
# github.com/StackExchange/dnscontrol. However a PR submitted by a
# third-party receives secrets from the account of their fork.
#
# If a test requires no secrets: List any parameters here in
# plaintext. (see BIND and HEXONET as examples).
# However secrets are needed for most tests. In that case, create a secret called
# ${PROVIDER}_DOMAIN and other env variables listed in
# integrationTest/providers.json for that provider. the test will only run on systems
# with access to those secrets (specifically, the ${PROVIDER}_DOMAIN secret).
# This way the main project can maintain its tests and secrets
# securely, plus forks can run their own tests.
#
# See https://stackexchange.github.io/dnscontrol/byo-secrets
#
# (Sort order: groups in the same order as the matrix; _DOMAIN first; sort the others alphabetically.)
env:
BIND_DOMAIN: example.com
#
HEXONET_DOMAIN: a-b-c-movies.com
HEXONET_ENTITY: OTE
HEXONET_PW: test.passw0rd
HEXONET_UID: test.user
#
AZURE_DNS_DOMAIN: ${{ secrets.AZURE_DNS_DOMAIN }}
AZURE_DNS_CLIENT_ID: ${{ secrets.AZURE_DNS_CLIENT_ID }}
AZURE_DNS_CLIENT_SECRET: ${{ secrets.AZURE_DNS_CLIENT_SECRET }}
AZURE_DNS_RESOURCE_GROUP: DNSControl
AZURE_DNS_SUBSCRIPTION_ID: ${{ secrets.AZURE_DNS_SUBSCRIPTION_ID }}
AZURE_DNS_TENANT_ID: ${{ secrets.AZURE_DNS_TENANT_ID }}
#
CLOUDFLAREAPI_DOMAIN: ${{ secrets.CLOUDFLAREAPI_DOMAIN }}
CLOUDFLAREAPI_KEY: ${{ secrets.CLOUDFLAREAPI_KEY }}
CLOUDFLAREAPI_TOKEN: ${{ secrets.CLOUDFLAREAPI_TOKEN }}
CLOUDFLAREAPI_USER: ${{ secrets.CLOUDFLAREAPI_USER }}
CLOUDFLAREAPI_ACCOUNTID: ${{ secrets.CLOUDFLAREAPI_ACCOUNTID }}
#
CLOUDNS_DOMAIN: ${{ secrets.CLOUDNS_DOMAIN }}
CLOUDNS_AUTH_ID: ${{ secrets.CLOUDNS_AUTH_ID }}
CLOUDNS_AUTH_PASSWORD: ${{ secrets.CLOUDNS_AUTH_PASSWORD }}
CLOUDNS_SUB_AUTH_ID: ${{ secrets.CLOUDNS_SUB_AUTH_ID }}
#
GCLOUD_DOMAIN: ${{ secrets.GCLOUD_DOMAIN }}
GCLOUD_EMAIL: dnscontrol@dnscontrol-dev.iam.gserviceaccount.com
GCLOUD_PRIVATEKEY: ${{ secrets.GCLOUD_PRIVATEKEY }}
GCLOUD_PROJECT: dnscontrol-dev
GCLOUD_TYPE: service_account
#
NAMEDOTCOM_DOMAIN: ${{ secrets.NAMEDOTCOM_DOMAIN }}
NAMEDOTCOM_KEY: ${{ secrets.NAMEDOTCOM_KEY }}
NAMEDOTCOM_URL: api.name.com
NAMEDOTCOM_USER: dnscontroltest
#
ROUTE53_DOMAIN: ${{ secrets.ROUTE53_DOMAIN }}
ROUTE53_KEY: ${{ secrets.ROUTE53_KEY }}
ROUTE53_KEY_ID: ${{ secrets.ROUTE53_KEY_ID }}
#
DIGITALOCEAN_DOMAIN: ${{ secrets.DIGITALOCEAN_DOMAIN }}
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
#
GANDI_V5_DOMAIN: ${{ secrets.GANDI_V5_DOMAIN }}
GANDI_V5_APIKEY: ${{ secrets.GANDI_V5_APIKEY }}
#
HEDNS_DOMAIN: ${{ secrets.HEDNS_DOMAIN }}
HEDNS_USERNAME: ${{ secrets.HEDNS_USERNAME }}
HEDNS_PASSWORD: ${{ secrets.HEDNS_PASSWORD }}
HEDNS_TOTP_SECRET: ${{ secrets.HEDNS_TOTP_SECRET }}
#
INWX_DOMAIN: ${{ secrets.INWX_DOMAIN }}
INWX_PASSWORD: ${{ secrets.INWX_PASSWORD }}
INWX_USER: ${{ secrets.INWX_USER }}
#
POWERDNS_DOMAIN: ${{ secrets.POWERDNS_DOMAIN }}
POWERDNS_APIURL: ${{ secrets.POWERDNS_APIURL }}
POWERDNS_APIKEY: ${{ secrets.POWERDNS_APIKEY }}
POWERDNS_SERVERNAME: ${{ secrets.POWERDNS_SERVERNAME }}
steps:
- name: Checkout repo
uses: actions/checkout@v2.4.0
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.15
- name: Cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Determining test viability for ${{ matrix.provider }} provider
run: if [ -n "$${{ matrix.provider }}_DOMAIN" ] ; then echo "CAN_CONTINUE=yes" >> "$GITHUB_ENV" ; fi
- name: Run integration tests for ${{ matrix.provider }} provider
if: env.CAN_CONTINUE == 'yes'
working-directory: integrationTest
run: go test -timeout 20m -v -verbose -provider ${{ matrix.provider }} -cfworkers=false
...

2
.gitignore vendored
View File

@@ -23,3 +23,5 @@ stack.sh
*.nupkg
.DS_Store
.vscode/launch.json
dist/

76
.goreleaser.yml Normal file
View File

@@ -0,0 +1,76 @@
env:
- GO111MODULE=on
builds:
-
id: build
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
- freebsd
ldflags:
- -s -w -X main.Version="{{ .Version }}" -X main.SHA="{{ .FullCommit }}" -X main.BuildTime={{ .Timestamp }}
changelog:
sort: asc
use: github
filters:
exclude:
- '^docs:'
- '^test:'
- '^chore'
- Merge pull request
- Merge branch
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
universal_binaries:
-
replace: true
id: build
nfpms:
- file_name_template: '{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
id: packages
homepage: https://stackexchange.github.io/dnscontrol/
description: "DNSControl: Infrastructure as Code for DNS Zones"
license: MIT
formats:
- deb
- rpm
#dockers:
# -
# id: docker-build
# goos: linux
# goarch: amd64
# image_templates:
# - "stackexchange/{{.ProjectName}}:latest"
# - "stackexchange/{{.ProjectName}}:{{ .Version }}"
# ids:
# - build
# build_flag_templates:
# - "--pull"
# - "--label=org.opencontainers.image.created={{.Date}}"
# - "--label=org.opencontainers.image.name={{.ProjectName}}"
# - "--label=org.opencontainers.image.revision={{.FullCommit}}"
# - "--label=org.opencontainers.image.version={{.Version}}"
# - "--label=org.opencontainers.image.source={{.GitURL}}"
# - "--platform=linux/amd64"
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
announce:
# Skip the announcing feature in some conditions, for instance, when publishing patch releases.
# Valid options are `true`, `false`, empty, or a template that evaluates to a boolean (`true` or `false`).
# Defaults to empty (which means false).
skip: true

View File

@@ -1,17 +1,3 @@
FROM golang:1.16-alpine AS build-env
WORKDIR /go/src/github.com/StackExchange/dnscontrol
ADD . .
RUN apk update && apk add git
RUN GO111MODULE=on go run build/build.go -os=linux
RUN cp dnscontrol-Linux /go/bin/dnscontrol
RUN dnscontrol version
RUN go build -o cmd/convertzone/convertzone cmd/convertzone/main.go
RUN cp cmd/convertzone/convertzone /go/bin/convertzone
FROM alpine
RUN apk add --no-cache ca-certificates
COPY --from=build-env /go/bin/dnscontrol /usr/local/bin
COPY --from=build-env /go/bin/convertzone /usr/local/bin
WORKDIR /dns
RUN dnscontrol version
CMD dnscontrol
FROM scratch
ENTRYPOINT ["/dnscontrol"]
COPY dnscontrol /

View File

@@ -1,6 +1,6 @@
# DNSControl
[![Build Status](https://github.com/StackExchange/dnscontrol/workflows/build/badge.svg)](https://github.com/StackExchange/dnscontrol/actions?query=workflow%3Abuild+branch%3Amaster)
[![CircleCI](https://circleci.com/gh/StackExchange/dnscontrol/tree/master.svg?style=svg)](https://circleci.com/gh/StackExchange/dnscontrol/tree/master)
[![Gitter chat](https://badges.gitter.im/dnscontrol/Lobby.png)](https://gitter.im/dnscontrol/Lobby)
[![Google Group](https://img.shields.io/badge/google%20group-chat-green.svg)](https://groups.google.com/forum/#!forum/dnscontrol-discuss)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/StackExchange/dnscontrol)](https://pkg.go.dev/github.com/StackExchange/dnscontrol)