diff --git a/.gitignore b/.gitignore index a7376d1f..5715bdfe 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ node_modules venom.*.log docs/README.md +orb.yml diff --git a/Makefile b/Makefile index 3f6e4ba8..212edcde 100644 --- a/Makefile +++ b/Makefile @@ -32,5 +32,8 @@ build-windows: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME) -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -s -w" -v ./cmd/pluto/main.go build-docker: build-linux docker build --build-arg version=$(VERSION) --build-arg commit=$(COMMIT) -t us-docker.pkg.dev/fairwinds-ops/oss/pluto/$(BINARY_NAME):dev . +orb-validate: + circleci orb pack orb/ > orb.yml + circleci orb validate orb.yml circleci-validate: circleci config validate --org-slug github/FairwindsOps diff --git a/docs/contributing/guide.md b/docs/contributing/guide.md index 6de5eebe..d01f4b0c 100644 --- a/docs/contributing/guide.md +++ b/docs/contributing/guide.md @@ -90,6 +90,10 @@ Each new pull request should: - Contain a clear indication of if they're ready for review or a work in progress - Be up to date and/or rebased on the master branch +## Orb development + +There is a Makefile that can assist in validating and testing the orb locally. See the commands there for more info. + ## Creating a new release Push a new tag and Goreleaser will take care of the rest. diff --git a/docs/orb.md b/docs/orb.md new file mode 100644 index 00000000..00d2d42e --- /dev/null +++ b/docs/orb.md @@ -0,0 +1,8 @@ +--- +meta: + - name: description + content: "Fairwinds Pluto | Fairwinds publishes an orb called fairwinds/pluto to provide easier configuration inside of CircleCI." +--- +# Orb + +CircleCI has introduced the concept of reusable config in the form of [Orbs](https://circleci.com/orbs/). As of pluto v5.1, Fairwinds publishes an orb called [`fairwinds/pluto`](https://circleci.com/orbs/registry/orb/fairwinds/pluto) in order to provide easier configuration inside of CircleCI. diff --git a/orb/@orb.yml b/orb/@orb.yml new file mode 100644 index 00000000..35496be6 --- /dev/null +++ b/orb/@orb.yml @@ -0,0 +1,7 @@ +version: 2.1 + +description: | + Pluto is a utility to help users find deprecated Kubernetes apiVersions in their code repositories and their helm releases. +display: + home_url: https://pluto.docs.fairwinds.com + source_url: https://github.com/FairwindsOps/pluto diff --git a/orb/commands/configure_env.yml b/orb/commands/configure_env.yml new file mode 100644 index 00000000..df121e5f --- /dev/null +++ b/orb/commands/configure_env.yml @@ -0,0 +1,29 @@ +description: Configures pluto environment variables. +parameters: + executor: + description: The name of custom executor to use. Only recommended for development. + type: executor + default: default + ignore-deprecations: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if deprecated APIs are detected. + ignore-removals: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if removed APIs are detected. + target-versions: + description: You can target the Kubernetes version you are concerned with. If blank defaults to latest. + type: string + default: "" +steps: + - run: + name: configure Pluto env vars + command: | + #!/bin/bash + + set -e + + echo PLUTO_IGNORE_DEPRECATIONS=<> >> $BASH_ENV + echo PLUTO_IGNORE_REMOVALS=<> >> $BASH_ENV + echo PLUTO_TARGET_VERSIONS=<> >> $BASH_ENV diff --git a/orb/commands/detect.yml b/orb/commands/detect.yml new file mode 100644 index 00000000..95b9a245 --- /dev/null +++ b/orb/commands/detect.yml @@ -0,0 +1,16 @@ +description: Detecting deprecated Kubernetes apiVersions within your repository. +parameters: + file: + description: The file to scan. + type: string + default: "" + executor: + description: The name of custom executor to use. Only recommended for development. + type: executor + default: default +steps: + - run: + name: Pluto detect + environment: + PLUTO_FILE: <> + command: <> diff --git a/orb/commands/detect_files.yml b/orb/commands/detect_files.yml new file mode 100644 index 00000000..55f189e3 --- /dev/null +++ b/orb/commands/detect_files.yml @@ -0,0 +1,16 @@ +description: Detecting deprecated Kubernetes apiVersions within your repository. +parameters: + directory: + description: The directory to scan. If blank defaults to current directory. + type: string + default: "" + executor: + description: The name of custom executor to use. Only recommended for development. + type: executor + default: default +steps: + - run: + name: Pluto detect-files + environment: + PLUTO_DIRECTORY: <> + command: <> diff --git a/orb/commands/install.yml b/orb/commands/install.yml new file mode 100644 index 00000000..7d8daff3 --- /dev/null +++ b/orb/commands/install.yml @@ -0,0 +1,16 @@ +description: Installs the pluto command. +parameters: + executor: + description: The name of custom executor to use. Only recommended for development. + type: executor + default: default + version: + description: The version of pluto to install. Defaults to latest stable. + type: string + default: "" +steps: + - run: + name: Install Pluto + environment: + VERSION: <> + command: <> diff --git a/orb/examples/detect.yml b/orb/examples/detect.yml new file mode 100644 index 00000000..5f0e39b7 --- /dev/null +++ b/orb/examples/detect.yml @@ -0,0 +1,14 @@ +description: | + A workflow for detecting deprecated Kubernetes apiVersions for a specific file. +usage: + version: 2.1 + orbs: + pluto: fairwinds/pluto@5 + workflows: + detect_files: + jobs: + - pluto/detect_files: + file: ./K8s/Descriptors/ingress.yml + ignore-deprecations: true + ignore-removals: false + target-versions: "k8s=v1.21" diff --git a/orb/examples/detect_files.yml b/orb/examples/detect_files.yml new file mode 100644 index 00000000..29974b52 --- /dev/null +++ b/orb/examples/detect_files.yml @@ -0,0 +1,14 @@ +description: | + A workflow for detecting deprecated Kubernetes apiVersions within your repository. +usage: + version: 2.1 + orbs: + pluto: fairwinds/pluto@5 + workflows: + detect_files: + jobs: + - pluto/detect_files: + directory: ./K8s/Descriptors + ignore-deprecations: true + ignore-removals: false + target-versions: "k8s=v1.21" diff --git a/orb/executors/default.yml b/orb/executors/default.yml new file mode 100644 index 00000000..ec7317df --- /dev/null +++ b/orb/executors/default.yml @@ -0,0 +1,6 @@ +parameters: + version: + type: string + default: "stable" +docker: + - image: cimg/base:<> diff --git a/orb/jobs/detect.yml b/orb/jobs/detect.yml new file mode 100644 index 00000000..5c112c94 --- /dev/null +++ b/orb/jobs/detect.yml @@ -0,0 +1,53 @@ +description: > + A workflow for detecting deprecated Kubernetes apiVersions within your repository. +parameters: + checkout: + type: boolean + default: true + description: "Perform checkout as first step in job." + executor: + description: The name of custom executor to use. Only recommended for development. + type: executor + default: default + file: + description: The file to scan. Required. + type: string + default: "" + use-external-context: + type: boolean + default: false + description: If this is true, then the configure_env step will be skipped. + ignore-deprecations: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if deprecated APIs are detected. + ignore-removals: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if removed APIs are detected. + target-versions: + description: You can target the Kubernetes version you are concerned with. If blank defaults to latest. + type: string + default: "" + version: + description: Version of Pluto to use. Defaults to latest stable. + type: string + default: "" +executor: <> +steps: + - when: + condition: << parameters.checkout >> + steps: + - checkout + - install: + version: <> + - when: + condition: + not: << parameters.use-external-context >> + steps: + - configure_env: + ignore-deprecations: << parameters.ignore-deprecations >> + ignore-removals: << parameters.ignore-removals >> + target-versions: << parameters.target-versions >> + - detect: + file: <> diff --git a/orb/jobs/detect_files.yml b/orb/jobs/detect_files.yml new file mode 100644 index 00000000..1f851f85 --- /dev/null +++ b/orb/jobs/detect_files.yml @@ -0,0 +1,53 @@ +description: > + A workflow for detecting deprecated Kubernetes apiVersions within your repository. +parameters: + checkout: + type: boolean + default: true + description: "Perform checkout as first step in job." + directory: + description: The directory to scan. If blank defaults to current directory. + type: string + default: "" + executor: + description: The name of custom executor to use. Only recommended for development. + type: executor + default: default + use-external-context: + type: boolean + default: false + description: If this is true, then the configure_env step will be skipped. + ignore-deprecations: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if deprecated APIs are detected. + ignore-removals: + type: boolean + default: false + description: Exit Code 3 is ignored, useful if you do not want the job to fail if removed APIs are detected. + target-versions: + description: You can target the Kubernetes version you are concerned with. If blank defaults to latest. + type: string + default: "" + version: + description: Version of Pluto to use. Defaults to latest stable. + type: string + default: "" +executor: <> +steps: + - when: + condition: << parameters.checkout >> + steps: + - checkout + - install: + version: <> + - when: + condition: + not: << parameters.use-external-context >> + steps: + - configure_env: + ignore-deprecations: << parameters.ignore-deprecations >> + ignore-removals: << parameters.ignore-removals >> + target-versions: << parameters.target-versions >> + - detect_files: + directory: <> diff --git a/orb/scripts/detect.sh b/orb/scripts/detect.sh new file mode 100755 index 00000000..8d77bc0a --- /dev/null +++ b/orb/scripts/detect.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +if [[ -z "${PLUTO_FILE}" ]]; then + echo "Error: requires a file argument" + exit 1 +fi + +pluto detect "$PLUTO_FILE" diff --git a/orb/scripts/detect_files.sh b/orb/scripts/detect_files.sh new file mode 100755 index 00000000..8a95d7ae --- /dev/null +++ b/orb/scripts/detect_files.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +if [[ -n "${PLUTO_DIRECTORY}" ]]; then + PLUTO_ARGS="$PLUTO_ARGS --directory ${PLUTO_DIRECTORY}" +fi + +export PLUTO_ARGS + +pluto detect-files "$PLUTO_ARGS" diff --git a/orb/scripts/install.sh b/orb/scripts/install.sh new file mode 100755 index 00000000..6608e7fe --- /dev/null +++ b/orb/scripts/install.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [[ -z "${VERSION}" ]]; then + VERSION=latest +fi + +curl -s https://api.github.com/repos/FairwindsOps/pluto/releases/${VERSION} \ +| grep "browser_download_url.*linux_amd64.tar.gz" \ +| cut -d '"' -f 4 \ +| wget -qi - + +tarball="$(find . -name "*linux_amd64.tar.gz")" +tar -xzf $tarball + +sudo mv pluto /bin + +location="$(which pluto)" +echo "Pluto binary location: $location" + +version="$(pluto version)" +echo "Pluto binary version: $version" diff --git a/release-orb.sh b/release-orb.sh new file mode 100755 index 00000000..16309e51 --- /dev/null +++ b/release-orb.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +function version_gt() { + test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; +} + +echo "Starting release." + +command -v circleci >/dev/null 2>&1 || { echo >&2 "I require circleci but it's not installed. Aborting."; exit 1; } +echo "Found circleci command." + +cli_version=$(circleci version | cut -d+ -f1) +required_version=0.1.5705 + +if version_gt "$required_version" "$cli_version"; then + echo "This script requires circleci version greater than or equal to 0.1.5705!" + exit 1 +fi + +commit=$(git log -n1 --pretty='%h') +tag=$(git describe --exact-match --tags "$commit") + +retVal=$? +echo "retVal = $retVal" +if [ $retVal -ne 0 ]; then + echo "You need to checkout a valid tag for this to work." + exit $retVal +fi + +echo "Release: $commit - $tag" + +echo "Validating..." +make orb-validate || { echo 'Orb failed to validate.' ; exit 1; } + +echo "Releasing..." +circleci orb publish orb.yml "fairwinds/pluto@${tag:1}"