diff --git a/.drone.yml b/.drone.yml index 06734e42..a1733213 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,74 +1,112 @@ --- kind: pipeline -name: amd64 +name: default platform: os: linux arch: amd64 steps: -- name: build +- name: build-release-binary image: rancher/dapper:v0.5.8 + environment: + CROSS: 1 commands: - - dapper precheck + - dapper ci volumes: - name: docker path: /var/run/docker.sock + when: + event: + - tag -- name: stage-binaries +- name: gpg-sign-release + image: plugins/gpgsign + settings: + key: + from_secret: gpg_private_key + passphrase: + from_secret: gpg_passphrase + files: + - dist/artifacts/terraform-provider-harvester_*_SHA256SUMS + detach_sign: true + armor: false + when: + event: + - tag + +- name: github-binary-prerelease + image: plugins/github-release + settings: + prerelease: true + files: + - dist/artifacts/terraform-provider-harvester_* + api_key: + from_secret: github_token + when: + ref: + include: + - "refs/tags/*rc*" + event: + - tag + +- name: github-binary-release + image: plugins/github-release + settings: + files: + - dist/artifacts/terraform-provider-harvester_* + api_key: + from_secret: github_token + when: + ref: + exclude: + - "refs/tags/*rc*" + event: + - tag + +- name: build image: rancher/dapper:v0.5.8 commands: - - "cp -r ./bin/* ./package/" + - dapper ci + volumes: + - name: docker + path: /var/run/docker.sock when: event: - push - - tag + - pull_request -- name: docker-publish-master - image: plugins/docker - settings: - build_args: - - ARCH=amd64 - context: package/ - custom_dns: 1.1.1.1 - dockerfile: package/Dockerfile - password: - from_secret: docker_password - repo: "rancher/terraform-provider-harvester" - tag: ${DRONE_BRANCH}-head-amd64 - username: - from_secret: docker_username +- name: stage-binaries + image: rancher/dapper:v0.5.8 + commands: + - "cp -r ./bin/terraform-provider-harvester ./package/" when: ref: include: - "refs/heads/master" - - "refs/heads/v*" event: - push -- name: docker-publish +- name: docker-publish-master image: plugins/docker settings: build_args: - ARCH=amd64 - - "VERSION=${DRONE_TAG}" context: package/ custom_dns: 1.1.1.1 dockerfile: package/Dockerfile + username: + from_secret: docker_username password: from_secret: docker_password repo: "rancher/terraform-provider-harvester" - tag: "${DRONE_TAG}-amd64" - username: - from_secret: docker_username + tag: ${DRONE_BRANCH}-head-amd64 when: - instance: - - drone-publish.rancher.io ref: - - refs/head/master - - refs/tags/* + include: + - "refs/heads/master" event: - - tag + - push volumes: - name: docker @@ -99,29 +137,8 @@ steps: ref: include: - "refs/heads/master" - - "refs/heads/v*" event: - push -- name: manifest - image: plugins/manifest - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - platforms: - - linux/amd64 - target: "rancher/terraform-provider-harvester:${DRONE_TAG}" - template: "rancher/terraform-provider-harvester:${DRONE_TAG}-ARCH" - when: - instance: - - drone-publish.rancher.io - ref: - - refs/head/master - - refs/tags/* - event: - - tag - depends_on: -- amd64 +- default diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index e8eadfa6..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This GitHub action can publish assets for release when a tag is created. -# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). -# -# This uses an action (hashicorp/ghaction-import-gpg) that assumes you set your -# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` -# secret. If you would rather own your own GPG handling, please fork this action -# or use an alternative one for key handling. -# -# You will need to pass the `--batch` flag to `gpg` in your signing step -# in `goreleaser` to indicate this is being used in a non-interactive mode. -# -name: release -on: - push: - tags: - - 'v*' -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2.3.4 - - - name: Unshallow - run: git fetch --prune --unshallow - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - - name: Import GPG key - id: import_gpg - uses: hashicorp/ghaction-import-gpg@v2.1.0 - env: - # These secrets will need to be configured for the repository: - GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - PASSPHRASE: ${{ secrets.PASSPHRASE }} - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2.7.0 - with: - version: latest - args: release --rm-dist - env: - GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} - # GitHub sets this automatically - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml index 25c2d11c..83a20b47 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,8 +13,6 @@ linters: - unused - unparam - ineffassign - - scopelint - - maligned - prealloc - stylecheck - goconst diff --git a/.goreleaser.yml b/.goreleaser.yml deleted file mode 100644 index be63fbe0..00000000 --- a/.goreleaser.yml +++ /dev/null @@ -1,47 +0,0 @@ -# Visit https://goreleaser.com for documentation on how to customize this -# behavior. -before: - hooks: - # this is just an example and not a requirement for provider building/publishing - - go mod tidy -builds: -- env: - # goreleaser does not work with CGO, it could also complicate - # usage by users in CI/CD systems like Terraform Cloud where - # they are unable to install libraries. - - CGO_ENABLED=0 - mod_timestamp: '{{ .CommitTimestamp }}' - flags: - - -trimpath - ldflags: - - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - binary: '{{ .ProjectName }}_v{{ .Version }}' -archives: -- format: zip - name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' -checksum: - name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' - algorithm: sha256 -signs: - - artifacts: checksum - args: - # if you are using this in a GitHub action or some other automated pipeline, you - # need to pass the batch flag to indicate its not interactive. - - "--batch" - - "--local-user" - - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key - - "--output" - - "${signature}" - - "--detach-sign" - - "${artifact}" -release: - # If you want to manually examine the release before its live, uncomment this line: - # draft: true -changelog: - skip: true diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 69937226..a772d2a8 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -3,19 +3,19 @@ FROM golang:1.16.5-alpine3.13 ARG DAPPER_HOST_ARCH ENV ARCH $DAPPER_HOST_ARCH -RUN apk update && apk -U add bash git gcc musl-dev docker vim less file curl wget ca-certificates +RUN apk update && apk -U add bash git gcc musl-dev docker vim less file curl wget ca-certificates zip perl-utils # install goimports -RUN GO111MODULE=on go get golang.org/x/tools/cmd/goimports@v0.1.2 +RUN GO111MODULE=on go get golang.org/x/tools/cmd/goimports@v0.1.9 ## install golangci-lint RUN if [ "${ARCH}" = "amd64" ]; then \ - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b "$(go env GOPATH)/bin" v1.27.0; \ + curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b "$(go env GOPATH)/bin" v1.44.0; \ fi ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS ENV DAPPER_SOURCE /go/src/github.com/harvester/terraform-provider-harvester -ENV DAPPER_OUTPUT ./bin ./dist +ENV DAPPER_OUTPUT ./bin ./dist ./build ENV DAPPER_DOCKER_SOCKET true ENV HOME ${DAPPER_SOURCE} diff --git a/scripts/archive b/scripts/archive new file mode 100755 index 00000000..add41834 --- /dev/null +++ b/scripts/archive @@ -0,0 +1,52 @@ +#!/bin/bash +set -e + +source $(dirname $0)/version + +cd $(dirname $0)/.. + +BIN_NAME_PREFIX="terraform-provider-harvester" +BUILD_DIR="./build" +BUILD_BIN_DIR="${BUILD_DIR}/bin" +if [ -z "$(ls -A ${BUILD_BIN_DIR})" ]; then + exit 0 +fi + +VERSION_NO_V=${VERSION/[v|V]/} +echo "==> Packaging binaries version ${VERSION_NO_V} ..." + +DIST=$(pwd)/dist/artifacts + +mkdir -p "${DIST}" + +for i in "${BUILD_BIN_DIR}"/*; do + if [ ! -e "${i}" ]; then + continue + fi + + ARCHIVE_DIR=${BUILD_DIR}/archive + + rm -rf "${ARCHIVE_DIR}" + mkdir -p "${ARCHIVE_DIR}" + + EXT= + if [[ $i =~ .*windows.* ]]; then + EXT=.exe + fi + + cp "${i}" "${ARCHIVE_DIR}/${BIN_NAME_PREFIX}_${VERSION}${EXT}" + + ( + cd "${ARCHIVE_DIR}" + NAME=$(basename "${i}" | cut -f1 -d_) + ARCH=$(basename "${i}" | cut -f2,3 -d_ | cut -f1 -d.) + ARCHIVE_FILE="${NAME}_${VERSION_NO_V}_${ARCH}.zip" + echo "Packaging $DIST/${ARCHIVE_FILE} ..." + zip -q "${DIST}/${ARCHIVE_FILE}" ./* + ) +done + +( + cd "${DIST}" + shasum -a 256 ./* > "${BIN_NAME_PREFIX}_${VERSION_NO_V}_SHA256SUMS" +) \ No newline at end of file diff --git a/scripts/build b/scripts/build index 35087e58..71e777db 100755 --- a/scripts/build +++ b/scripts/build @@ -5,6 +5,33 @@ source $(dirname $0)/version cd $(dirname $0)/.. +declare -A OS_ARCH_ARG + +OS_PLATFORM_ARG=(linux darwin) +OS_ARCH_ARG[linux]="amd64 arm64" +OS_ARCH_ARG[darwin]="amd64 arm64" + +BIN_NAME="terraform-provider-harvester" +BUILD_DIR="./build" +BUILD_BIN_DIR="${BUILD_DIR}/bin" + mkdir -p bin [ "$(uname)" != "Darwin" ] && LINKFLAGS="-extldflags -static -s" -CGO_ENABLED=0 go build -ldflags "-X main.VERSION=$VERSION $LINKFLAGS" -o bin/terraform-provider-harvester +CGO_ENABLED=0 go build -ldflags "-X main.VERSION=${VERSION} ${LINKFLAGS}" -o bin/${BIN_NAME} + +if [ -n "${CROSS}" ]; then + rm -rf "${BUILD_BIN_DIR}" + mkdir -p "${BUILD_BIN_DIR}" + for OS in "${OS_PLATFORM_ARG[@]}"; do + for ARCH in ${OS_ARCH_ARG[${OS}]}; do + OUTPUT_BIN="${BUILD_BIN_DIR}/${BIN_NAME}_${OS}_${ARCH}" + if test "${OS}" = "windows"; then + OUTPUT_BIN="${OUTPUT_BIN}.exe" + fi + echo "Building binary for ${OS}/${ARCH}..." + GOARCH=${ARCH} GOOS=${OS} CGO_ENABLED=0 go build \ + -ldflags="-w -X main.VERSION=$VERSION" \ + -o "${OUTPUT_BIN}" ./ + done + done +fi \ No newline at end of file diff --git a/scripts/ci b/scripts/ci index e6fae796..a407bcb6 100755 --- a/scripts/ci +++ b/scripts/ci @@ -6,4 +6,5 @@ cd $(dirname $0) ./build ./test ./validate +./archive ./package diff --git a/scripts/default b/scripts/default index e6fae796..a407bcb6 100755 --- a/scripts/default +++ b/scripts/default @@ -6,4 +6,5 @@ cd $(dirname $0) ./build ./test ./validate +./archive ./package diff --git a/scripts/package b/scripts/package index 1cee90bb..8b10208e 100755 --- a/scripts/package +++ b/scripts/package @@ -8,18 +8,9 @@ cd $(dirname $0)/.. if [ "${GIT_TAG}" != "${VERSION}" ]; then PROVIDER_VERSION="0.0.0-master" else - PROVIDER_VERSION=${VERSION#"v"} + PROVIDER_VERSION=${VERSION/[v|V]/} fi -TAG=${TAG:-${VERSION}${SUFFIX}} - -if echo $TAG | grep -q dirty; then - TAG=dev -fi - -mkdir -p dist/artifacts -cp bin/terraform-provider-harvester dist/artifacts/terraform-provider-harvester${SUFFIX} - cd $(dirname $0)/package IMAGE=${REPO}/terraform-provider-harvester:${TAG} diff --git a/scripts/precheck b/scripts/precheck deleted file mode 100755 index 348bd8e9..00000000 --- a/scripts/precheck +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0) - -./build -./test -./validate \ No newline at end of file