From ccc1fd1207ab343ed95351297a3e735c59cd5bab Mon Sep 17 00:00:00 2001 From: Andrew Suderman Date: Thu, 9 May 2019 09:56:20 -0600 Subject: [PATCH] Adding circleci orb build and config Adding docker login. Adding a makefile for testing locally. Added notes to readme and contributing. Adding orb examples Updating Makefile to work with OSX Updating to v9.0 for the orb release --- .circleci/config.yml | 53 +++++++++++++++++++++++++-- .gitignore | 1 + CONTRIBUTING.md | 3 ++ Makefile | 9 +++-- README.md | 16 +++++++- docs/index.md | 16 +++++++- examples/ci/.circleci/config.yml | 4 +- examples/ci/.gitlab-ci.yml | 2 +- examples/minimal/.circleci/config.yml | 5 +-- examples/minimal/README.md | 2 +- orb/commands.yml | 47 ++++++++++++++++++++++++ orb/config.yml | 2 + orb/examples/docker-build-push.yml | 25 +++++++++++++ orb/jobs.yml | 47 ++++++++++++++++++++++++ 14 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 orb/commands.yml create mode 100644 orb/config.yml create mode 100644 orb/examples/docker-build-push.yml create mode 100644 orb/jobs.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index de0e8dab..28e08506 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,7 @@ -version: 2 +version: 2.1 + +orbs: + orb-tools: circleci/orb-tools@8.27.2 references: docker_login: &docker_login @@ -100,13 +103,12 @@ jobs: - *docker_build - *docker_push - workflows: - version: 2 build_and_test: jobs: - test - build + release: jobs: - release: @@ -115,3 +117,48 @@ workflows: ignore: /.*/ tags: only: /^v.*/ + + "Orb Test and Publish": + jobs: + - orb-tools/lint: + name: "lint-orb-files" + lint-dir: orb + filters: + branches: + only: /.*/ + tags: + only: /.*/ + - orb-tools/pack: + name: "pack-orb" + source-dir: orb + requires: + - "lint-orb-files" + filters: + branches: + only: /.*/ + tags: + only: /.*/ + - orb-tools/publish: + name: "publish-dev-branch-orb" + orb-ref: reactiveops/rok8s-scripts@dev:${CIRCLE_BRANCH} + publish-token-variable: CIRCLECI_DEV_API_TOKEN + attach-workspace: true + requires: + - "pack-orb" + filters: + branches: + only: /.*/ + tags: + ignore: /.*/ + - orb-tools/publish: + name: "publish-tagged-orb" + orb-ref: reactiveops/rok8s-scripts@${CIRCLE_TAG} + publish-token-variable: CIRCLECI_DEV_API_TOKEN + attach-workspace: true + requires: + - "pack-orb" + filters: + branches: + ignore: /.*/ + tags: + only: /^v.*/ diff --git a/.gitignore b/.gitignore index a0f0e538..abeb117f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode .DS_Store +orb.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 004e5960..b2d60cc6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,6 +36,9 @@ always necessary to create a new issue in GitHub. In these cases, a branch with * Submit a pull request. * Mention the issue in your PR description. I.E. `Fixes #42`. This will ensure that your issue gets tagged with the PR. +## Orb development + +There is a Makefile that can assist in validating and testing the orb locally. See the commands there for more info. Attribution =========== diff --git a/Makefile b/Makefile index 44d0fd72..42470106 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ docs-index: cat README.md \ - | sed 's/\[\(.*\)\](\(\w\+\.md\))/[\1](https:\/\/github.com\/reactiveops\/rok8s-scripts\/tree\/master\/\2)/g' \ - | sed 's/\[\(.*\)\](\/\?docs\/\(.*\))/[\1](\2)/g' \ - | sed 's/\[\(.*\)\](\(\/.*\))/[\1](https:\/\/github.com\/reactiveops\/rok8s-scripts\/tree\/master\2)/g' \ + | sed -E 's/\[(.*)\]\(([^\/]*\.md)\)/[\1](https:\/\/github.com\/reactiveops\/rok8s-scripts\/tree\/master\/\2)/g' \ + | sed -E 's/\[(.*)\]\(\/*docs\/(.*)\)/[\1](\2)/g' \ + | sed -E 's/\[(.*)\]\((\/.*)\)/[\1](https:\/\/github.com\/reactiveops\/rok8s-scripts\/tree\/master\2)/g' \ > docs/index.md +orb-validate: + circleci config pack orb/ > orb.yml + circleci orb validate orb.yml diff --git a/README.md b/README.md index 673ddeee..83d34787 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ There are many valid ways to configure CI pipelines, but to help you get started Each new release of rok8s-scripts generates CI images for common workflows. These images include a set of common CI/CD dependencies, including Docker, Kubernetes, Helm, AWS, and Google Cloud client libraries. Starting with these images as a base for deployment workflows ensures that you don't need to spend any build time installing extra dependencies. -We currently include CI Images based on Alpine and Debian Stretch as our recommended starting points. The latest Debian Stretch release can be pulled from `quay.io/reactiveops/ci-images:v8-stretch`. A full list of image tags is available on our [Quay repository](https://quay.io/repository/reactiveops/ci-images). +We currently include CI Images based on Alpine and Debian Stretch as our recommended starting points. The latest Debian Stretch release can be pulled from `quay.io/reactiveops/ci-images:v9-stretch`. A full list of image tags is available on our [Quay repository](https://quay.io/repository/reactiveops/ci-images). ## Versioning v8.0.0 and beyond @@ -80,6 +80,20 @@ You are okay with your pipeline breaking occasionally and having to upgrade thin In this case, go ahead and pin to a major version such as `v8-alpine` +## Orbs + +CircleCI has introduced the concept of reusable config in the form of [Orbs](https://circleci.com/orbs/). As of rok8s-scripts v9.0.0, ReactiveOps publishes an orb called `reactiveops/rok8s-scripts` in order to provide easier configuration inside of CircleCI. + +## Further Reading + +- [Building and Pushing Docker Images](/docs/docker.md) +- [Deploying to Kubernetes with Helm](/docs/helm.md) +- [Deploying to Kubernetes without Helm](/docs/without_helm.md) +- [Managing Kubernetes Secrets Securely](/docs/secrets.md) + +### Cloud Specific Documentation +- [Amazon Web Services](/docs/aws.md) +- [Google Cloud](/docs/gcp.md) ### Contributing - [Code of Conduct](CODE_OF_CONDUCT.md) diff --git a/docs/index.md b/docs/index.md index dfd97044..6813d058 100644 --- a/docs/index.md +++ b/docs/index.md @@ -58,7 +58,7 @@ There are many valid ways to configure CI pipelines, but to help you get started Each new release of rok8s-scripts generates CI images for common workflows. These images include a set of common CI/CD dependencies, including Docker, Kubernetes, Helm, AWS, and Google Cloud client libraries. Starting with these images as a base for deployment workflows ensures that you don't need to spend any build time installing extra dependencies. -We currently include CI Images based on Alpine and Debian Stretch as our recommended starting points. The latest Debian Stretch release can be pulled from `quay.io/reactiveops/ci-images:v8-stretch`. A full list of image tags is available on our [Quay repository](https://quay.io/repository/reactiveops/ci-images). +We currently include CI Images based on Alpine and Debian Stretch as our recommended starting points. The latest Debian Stretch release can be pulled from `quay.io/reactiveops/ci-images:v9-stretch`. A full list of image tags is available on our [Quay repository](https://quay.io/repository/reactiveops/ci-images). ## Versioning v8.0.0 and beyond @@ -80,6 +80,20 @@ You are okay with your pipeline breaking occasionally and having to upgrade thin In this case, go ahead and pin to a major version such as `v8-alpine` +## Orbs + +CircleCI has introduced the concept of reusable config in the form of [Orbs](https://circleci.com/orbs/). As of rok8s-scripts v9.0.0, ReactiveOps publishes an orb called `reactiveops/rok8s-scripts` in order to provide easier configuration inside of CircleCI. + +## Further Reading + +- [Building and Pushing Docker Images](docker.md) +- [Deploying to Kubernetes with Helm](helm.md) +- [Deploying to Kubernetes without Helm](without_helm.md) +- [Managing Kubernetes Secrets Securely](secrets.md) + +### Cloud Specific Documentation +- [Amazon Web Services](aws.md) +- [Google Cloud](gcp.md) ### Contributing - [Code of Conduct](https://github.com/reactiveops/rok8s-scripts/tree/master/CODE_OF_CONDUCT.md) diff --git a/examples/ci/.circleci/config.yml b/examples/ci/.circleci/config.yml index 82c065b3..57fbc6af 100644 --- a/examples/ci/.circleci/config.yml +++ b/examples/ci/.circleci/config.yml @@ -14,7 +14,7 @@ references: deploy_steps: &deploy_steps docker: - - image: quay.io/reactiveops/ci-images:v8-alpine + - image: quay.io/reactiveops/ci-images:v9-alpine steps: - checkout - *set_environment_variables @@ -24,7 +24,7 @@ references: jobs: imagebuild: docker: - - image: quay.io/reactiveops/ci-images:v8-alpine + - image: quay.io/reactiveops/ci-images:v9-alpine steps: - checkout - setup_remote_docker diff --git a/examples/ci/.gitlab-ci.yml b/examples/ci/.gitlab-ci.yml index 6c9546f2..c1f935aa 100644 --- a/examples/ci/.gitlab-ci.yml +++ b/examples/ci/.gitlab-ci.yml @@ -13,7 +13,7 @@ variables: DOCKER_HOST: tcp://localhost:2375 DOCKER_DRIVER: overlay2 -image: quay.io/reactiveops/ci-images:v8-alpine +image: quay.io/reactiveops/ci-images:v9-alpine services: - docker:dind diff --git a/examples/minimal/.circleci/config.yml b/examples/minimal/.circleci/config.yml index 3bf9d446..682360a0 100644 --- a/examples/minimal/.circleci/config.yml +++ b/examples/minimal/.circleci/config.yml @@ -30,7 +30,7 @@ references: jobs: build_image: docker: - - image: quay.io/reactiveops/ci-images:v8.0-stretch + - image: quay.io/reactiveops/ci-images:v9.0-stretch steps: - checkout - setup_remote_docker @@ -38,7 +38,7 @@ jobs: - *build_image deploy: docker: - - image: quay.io/reactiveops/ci-images:v8.0-stretch + - image: quay.io/reactiveops/ci-images:v9.0-stretch steps: - checkout - setup_remote_docker @@ -57,4 +57,3 @@ workflows: filters: branches: only: master - diff --git a/examples/minimal/README.md b/examples/minimal/README.md index 9b34670e..568e1484 100644 --- a/examples/minimal/README.md +++ b/examples/minimal/README.md @@ -17,7 +17,7 @@ we run some of the scripts provided by rok8s-scripts. In particular, we use: * `prepare-kubectl` to set up for pushing the latest image to our Kubernetes cluster * `k8s-deploy-and-verify` to push our image to Kubernetes and make sure the deployment succeeded -We also use the rok8s-scripts CI image, `quay.io/reactiveops/ci-images:v8-stretch`, +We also use the rok8s-scripts CI image, `quay.io/reactiveops/ci-images:v9-stretch`, to ensure rok8s-scripts and its dependencies are all available during the build and deploy jobs. ## Try it out diff --git a/orb/commands.yml b/orb/commands.yml new file mode 100644 index 00000000..1f1d5604 --- /dev/null +++ b/orb/commands.yml @@ -0,0 +1,47 @@ +commands: + set_env: + description: Sets the needed rok8s-scripts environment variables from Circle + steps: + - run: | + echo 'export CI_SHA1=$CIRCLE_SHA1' >> ${BASH_ENV} + echo 'export CI_BRANCH=$CIRCLE_BRANCH' >> ${BASH_ENV} + echo 'export CI_BUILD_NUM=$CIRCLE_BUILD_NUM' >> ${BASH_ENV} + echo 'export CI_TAG=$CIRCLE_TAG' >> ${BASH_ENV} + docker_login: + description: Log into a docker repo + parameters: + registry: + type: string + description: The name of the docker registry. + default: "quay.io" + username: + type: string + description: The username to use for the registry. + password-variable: + type: string + description: The environment variable name containing the password. + steps: + - run: | + docker login -u="<>" -p="$<>" <> + docker_push: + description: Pushes a docker image using rok8s-scripts + parameters: + config: + type: string + description: The location of the rok8s-scripts config file + default: "deploy/build.config" + steps: + - run: | + docker-push -f << parameters.config >> + + docker_build: + description: Builds a docker image using rok8s-scripts + parameters: + config: + type: string + description: The location of the rok8s-scripts config file + default: "deploy/build.config" + steps: + - setup_remote_docker + - run: | + docker-build -f << parameters.config >> diff --git a/orb/config.yml b/orb/config.yml new file mode 100644 index 00000000..ab519771 --- /dev/null +++ b/orb/config.yml @@ -0,0 +1,2 @@ +version: "2.1" +description: "ReactiveOps rok8s-scripts. https://github.com/reactiveops/rok8s-scripts" diff --git a/orb/examples/docker-build-push.yml b/orb/examples/docker-build-push.yml new file mode 100644 index 00000000..6505d01c --- /dev/null +++ b/orb/examples/docker-build-push.yml @@ -0,0 +1,25 @@ +description: > + Use this example to build and push a docker + image using rok8s-scripts. This assumes that you + have a working rok8s-scripts configuration already + in place. + +usage: + version: 2.1 + + orbs: + rok8s-scripts: reactiveops/rok8s-scripts@v9.0.0 + + workflows: + build_and_push: + jobs: + - rok8s/docker_build_and_push: + config_file: deploy/build.config + docker-login: true + username: "orgname+circleci" + registry: "quay.io" + password-variable: quay_token + context: org-global + filters: + branches: + only: master diff --git a/orb/jobs.yml b/orb/jobs.yml new file mode 100644 index 00000000..105b2695 --- /dev/null +++ b/orb/jobs.yml @@ -0,0 +1,47 @@ +jobs: + docker_build_and_push: + parameters: + config_file: + description: "The location of the rok8s-scripts config file." + type: string + default: deploy/build.config + docker-login: + type: boolean + default: true + description: When true(default), perform a docker login before build and push. + registry: + type: string + description: The name of the docker registry. Only used if docker-login is true. + default: "quay.io" + username: + type: string + description: The username to use for the registry. Only used if docker-login is true. + default: "" + password-variable: + type: string + description: The environment variable name containing the password. Only used if docker-login is true. + default: "" + executor: ci-images + steps: + - checkout + - setup_remote_docker + - set_env + - when: + condition: << parameters.docker-login >> + steps: + - docker_login: + username: <> + password-variable: <> + registry: <> + - docker_build: + config: <> + - docker_push: + config: <> +executors: + ci-images: + parameters: + version: + type: string + default: "v9.0-stretch" + docker: + - image: quay.io/reactiveops/ci-images:<>