diff --git a/.circleci/config.yml b/.circleci/config.yml index 75a360f..b2ac7c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,13 +26,20 @@ executors: resource_class: windows.medium shell: bash.exe -eo pipefail + +release_filter: &release_filter + filters: + tags: + only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ + branches: + ignore: /.*/ + workflows: version: 2 build-and-test: jobs: - lint - check-openapi - - build-all - test-race: name: test-linux-amd64 - test-build: @@ -70,6 +77,24 @@ workflows: arch: amd64 requires: - test-build-amd64-windows + - build: + name: build-<< matrix.os >>-<< matrix.arch >> + matrix: + parameters: + os: [ linux, darwin, windows ] + arch: [ amd64, arm64 ] + exclude: + - os: darwin + arch: arm64 + - os: windows + arch: arm64 + - build-packages: + sign: false + requires: + - build-darwin-amd64 + - build-linux-amd64 + - build-linux-arm64 + - build-windows-amd64 release-nightly: triggers: - schedule: @@ -119,6 +144,24 @@ workflows: arch: amd64 requires: - test-build-amd64-windows + - build: + name: build-<< matrix.os >>-<< matrix.arch >> + matrix: + parameters: + os: [ linux, darwin, windows ] + arch: [ amd64, arm64 ] + exclude: + - os: darwin + arch: arm64 + - os: windows + arch: arm64 + - build-packages: + sign: true + requires: + - build-darwin-amd64 + - build-linux-amd64 + - build-linux-arm64 + - build-windows-amd64 - release: is-nightly: true requires: @@ -129,39 +172,20 @@ workflows: - test-linux-arm64 - test-mac - test-windows + - build-packages release-tag: jobs: - changelog: - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ + <<: *release_filter - lint: - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ + <<: *release_filter - check-openapi: - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ + <<: *release_filter - test-race: name: test-linux-amd64 - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ + <<: *release_filter - test-build: - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ + <<: *release_filter matrix: parameters: os: [ linux, darwin, windows ] @@ -176,47 +200,51 @@ workflows: - os: linux arch: amd64 - test-prebuilt: + <<: *release_filter name: test-linux-arm64 - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ executor: linux-arm64 os: linux arch: arm64 requires: - test-build-arm64-linux - test-prebuilt: + <<: *release_filter name: test-mac - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ executor: mac os: darwin arch: amd64 requires: - test-build-amd64-darwin - test-prebuilt: + <<: *release_filter name: test-windows - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ executor: windows os: windows arch: amd64 requires: - test-build-amd64-windows + - build: + <<: *release_filter + name: build-<< matrix.os >>-<< matrix.arch >> + matrix: + parameters: + os: [ linux, darwin, windows ] + arch: [ amd64, arm64 ] + exclude: + - os: darwin + arch: arm64 + - os: windows + arch: arm64 + - build-packages: + <<: *release_filter + sign: true + requires: + - build-darwin-amd64 + - build-linux-amd64 + - build-linux-arm64 + - build-windows-amd64 - release: - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/ + <<: *release_filter is-nightly: false requires: - changelog @@ -226,6 +254,7 @@ workflows: - test-linux-arm64 - test-mac - test-windows + - build-packages commands: setup: @@ -247,11 +276,6 @@ commands: echo 'export PATH=${GOPATH}/bin:${PATH}' >> $BASH_ENV mkdir -p ${HOME}/.cache echo 'export GOCACHE=${HOME}/.cache' >> $BASH_ENV - install-goreleaser: - steps: - - run: - name: Install goreleaser - command: ./scripts/ci/download-goreleaser.sh v1.14.0 jobs: lint: @@ -289,23 +313,6 @@ jobs: command: git submodule update --init --recursive - run: make checkopenapi - build-all: - executor: linux-amd64 - steps: - - checkout - - setup - - install-goreleaser - - run: - name: Make a pseudo-tag for the snapshot build - command: | - latest_tag=$(git describe --tags --abbrev=0) - git tag ${latest_tag}+SNAPSHOT.$(git rev-parse --short HEAD) - - run: - name: Cross-build all targets - command: IS_SNAPSHOT=1 goreleaser release --rm-dist --skip-publish --skip-sign --skip-validate - - store_artifacts: - path: dist - release: parameters: is-nightly: @@ -315,38 +322,25 @@ jobs: - checkout - attach_workspace: at: . - - setup - run: - name: Import GPG key command: | - echo -e "$GPG_PRIVATE_KEY" > private.key - gpg --batch --import private.key - - install-goreleaser + export DEBIAN_FRONTEND=noninteractive + sudo apt-get update -y + sudo apt-get install -y awscli gnupg + + gpg --import --batch \<<<"${GPG_PRIVATE_KEY//$'\\n'/$'\n'}" - when: condition: << parameters.is-nightly >> steps: - run: - name: Make a pseudo-tag for the nightly build - command: | - latest_tag=$(git describe --tags --abbrev=0) - git tag ${latest_tag}+nightly.$(date +%Y.%m.%d) - - run: - name: Publish nightly snapshot release - command: IS_NIGHTLY=1 goreleaser release --rm-dist + command: .circleci/scripts/upload-artifacts nightly - unless: condition: << parameters.is-nightly >> steps: - run: - name: Publish tagged release - command: goreleaser release --rm-dist - - run: - command: | - export DEBIAN_FRONTEND=noninteractive - sudo apt-get update - sudo apt-get install awscli - .circleci/scripts/upload-latest-artifacts + command: .circleci/scripts/upload-artifacts release - store_artifacts: - path: dist + path: packages test-build: executor: cross-builder @@ -403,6 +397,68 @@ jobs: - store_test_results: path: ./test-results + build: + executor: cross-builder + parameters: + os: + type: string + arch: + type: string + steps: + - checkout + - run: + name: Build Binaries + command: | + GOOS=<> GOARCH=<> make + - store_artifacts: + path: bin + - persist_to_workspace: + root: . + paths: bin + + build-packages: + docker: + - image: ubuntu:latest + resource_class: small + parameters: + sign: + type: boolean + steps: + - attach_workspace: + at: /tmp/workspace + - checkout + - run: + name: Build Packages + command: | + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install --yes \ + build-essential \ + git \ + gnupg \ + rpm \ + ruby-dev + gem install fpm + + if [[ "<< parameters.sign >>" == "true" ]] + then + gpg --import --batch \<<<"${GPG_PRIVATE_KEY//$'\\n'/$'\n'}" + + export SIGN_PACKAGES=1 + fi + + mkdir -p packages + OS=darwin ARCH=amd64 scripts/ci/build-packages /tmp/workspace/bin/darwin/amd64/influx "${PWD}/packages" + OS=linux ARCH=amd64 scripts/ci/build-packages /tmp/workspace/bin/linux/amd64/influx "${PWD}/packages" + OS=linux ARCH=arm64 scripts/ci/build-packages /tmp/workspace/bin/linux/arm64/influx "${PWD}/packages" + OS=windows ARCH=amd64 scripts/ci/build-packages /tmp/workspace/bin/windows/amd64/influx "${PWD}/packages" + - store_artifacts: + path: packages/ + - persist_to_workspace: + root: . + paths: + - packages + changelog: docker: - image: quay.io/influxdb/changelogger:a20523cf8594eb93920e74d0189d6602a76a6146 diff --git a/.circleci/scripts/upload-artifacts b/.circleci/scripts/upload-artifacts new file mode 100755 index 0000000..b464178 --- /dev/null +++ b/.circleci/scripts/upload-artifacts @@ -0,0 +1,52 @@ +#!/bin/bash +set -o errexit \ + -o nounset \ + -o pipefail + +# Determine if "${CIRCLE_TAG}" matches the semantic version regex. Otherwise, +# assume that "${CIRCLE_TAG}" is not intended to tag a release. The regex is +# permissive of what occurs after the semantic version. This allows for +# alphas, betas, and release candidates. +if [[ "${CIRCLE_TAG:-}" =~ ^v[0-9]+.[0-9]+.[0-9]+ ]] +then + VERSION_REGEX="${CIRCLE_TAG/#v/}" +else + # When "${CIRCLE_TAG}" cannot be used to construct the package version, + # use "${CIRCLE_SHA1}". Since "${CIRCLE_SHA1}" can start with an alpha + # (non-numeric) character, prefix it with "2.x-". + VERSION_REGEX="2.x[-_]${CIRCLE_SHA1:0:8}" +fi + +REGEX='^packages/influxdb2-client[-_]'"${VERSION_REGEX}"'(.*)' + +for target in packages/* +do + if [[ "${target}" =~ ${REGEX} ]] + then + # After renaming the artifact to the "latest/nightly" version, append + # the artifact to the `invalidations` file. Since `dl.influxdata.com` + # contains many 100GBs, this should only invalidate artifacts + # that have changed. + case ${1} in + nightly) + mv -v "${target}" "packages/influxdb2-client-nightly${BASH_REMATCH[1]}" + printf '/platform/nightlies/influxdb2-client-nightly%s\n' "${BASH_REMATCH[1]}" >>invalidations + ;; + release) + cp -v "${target}" "packages/influxdb2-client-latest${BASH_REMATCH[1]}" + printf '/influxdb/releases/influxdb2-client-latest%s\n' "${BASH_REMATCH[1]}" >>invalidations + ;; + esac + fi +done + +case ${1} in + nightly) + aws s3 sync packages s3://dl.influxdata.com/platform/nightlies + ;; + release) + aws s3 sync packages s3://dl.influxdata.com/influxdb/releases + ;; +esac + +aws cloudfront create-invalidation --distribution-id "${AWS_DISTRIBUTION_ID}" --paths $(>invalidations - fi -done - -aws s3 sync dist 's3://dl.influxdata.com/influxdb/releases/' - -aws cloudfront create-invalidation --distribution-id "${AWS_DISTRIBUTION_ID}" --paths $("${1}.md5" + sha256sum "${1}" >"${1}.sha256" +} + +case ${OS} in + linux) + build_archive + build_package_linux + ;; + darwin) + build_archive + ;; +esac diff --git a/scripts/ci/download-goreleaser.sh b/scripts/ci/download-goreleaser.sh deleted file mode 100755 index 407508a..0000000 --- a/scripts/ci/download-goreleaser.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -o nounset \ - -o errexit \ - -o pipefail - -case ${1} in -v1.14.0) - CHECKSUM=5f832026b88340318caaec5bd985951e7d363bd248bf49f25239ebb802304bcb - ;; -v1.13.1) - CHECKSUM=136fecfb2e2f3a7965274ad5e2571985d8b2fa724b6536874f082e4b0bb9f344 - ;; -v1.13.0) - CHECKSUM=743dea6fa96f3acdf0fe99ce5f8c83f43afe72efedeb1506f88f5321a18f63f2 - ;; -*) - printf 'Could not validate goreleaser version %s...\n' "${1}" 1>&2 ; exit 1 - ;; -esac - -curl -LO "https://github.com/goreleaser/goreleaser/releases/download/${1}/goreleaser_Linux_x86_64.tar.gz" - -printf '%s goreleaser_Linux_x86_64.tar.gz' "${CHECKSUM}" | sha256sum --check - -tar -xf goreleaser_Linux_x86_64.tar.gz -C "${GOPATH}/bin" diff --git a/support.mk b/support.mk new file mode 100644 index 0000000..1d74d6c --- /dev/null +++ b/support.mk @@ -0,0 +1,17 @@ + +# Add quotes to a string and escape any internal quotes. +# $(call with-quotes,alice bob) -> "alice bob" +# $(call with-quotes,) -> "" +# $(call with-quotes,Bobby "Drop Tables") -> "Bobby \"Drop Tables\"" +define with-quotes +$(if $(1),"$(subst ",\",$(1))") +endef + +# Generate a command line option in the form $(1)"$(2)", but only if $(2) +# is not empty. +# $(call with-param,-t=,) -> +# $(call with-param,-t=,Ralph Wiggum) -> -t="Ralph Wiggum" +# $(call with-param,-t=,Bobby "Drop Tables") -> -t="Bobby \"Drop Tables\"" +define with-param +$(if $(2),$(1)$(call with-quotes,$(2))) +endef