diff --git a/.circleci/config.yml b/.circleci/config.yml index 9a01ffb8..1215782d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,28 +1,77 @@ -version: 2 - -resource_job_defaults: &resource_job_defaults - docker: - - image: 'cimg/base:2021.02-20.04' - steps: - - run: - name: verify required Environment Variables - command: | - if [ -z "${CIRCLE_HOSTNAME}" -o -z "${CIRCLE_TOKEN}" ];then - echo "You must provide 2 Environment Variables in project settings for this job to run." - echo "CIRCLE_HOSTNAME: Should be the scheme://domain of your install. \"https://ci.example.com\"" - echo "CIRCLE_TOKEN: Should be the API Key of an admin or project level with Scope:All" - exit 1 - fi - - run: - name: verify that job ran with the requested resource_class option - command: | - curl -k \ - "${CIRCLE_HOSTNAME%/}/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/$CIRCLE_BUILD_NUM?\ - circle-token=$CIRCLE_TOKEN" | \ - jq '.picard.resource_class.class' | grep $CIRCLE_JOB +version: 2.1 + +executors: + docker: # Docker using the Base Convenience Image + parameters: + resource_class: + type: string + default: "small" + docker: + - image: 'cimg/base:2025.02-20.04' + resource_class: <<parameters.resource_class>> + windows: # Windows using the default windows image + parameters: + resource_class: + type: string + default: "medium" + machine: + image: windows-default + shell: 'powershell.exe -ExecutionPolicy Bypass' + resource_class: <<parameters.resource_class>> + +commands: + # resource_class verification commands to execute depending on executor_type + verify_resource_class: + parameters: + resource_class: + type: string + default: "small" + executor_type: + type: string + default: "docker" + steps: + - when: + condition: + equal: [ "docker", << parameters.executor_type >> ] + steps: + - run: + name: verify required Environment Variables + command: | + if [ -z "${CIRCLE_HOSTNAME}" -o -z "${CIRCLE_TOKEN}" ];then + echo "You must provide 2 Environment Variables in project settings for this job to run." + echo "CIRCLE_HOSTNAME: Should be the scheme://domain of your install. \"https://ci.example.com\"" + echo "CIRCLE_TOKEN: Should be the API Key of an admin or project level with Scope:All" + exit 1 + fi + - run: + name: Verify that job ran with the requested resource_class option + command: | + curl -k \ + "${CIRCLE_HOSTNAME%/}/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/$CIRCLE_BUILD_NUM?\ + circle-token=$CIRCLE_TOKEN" | \ + jq '.picard.resource_class.class' | grep <<parameters.resource_class>> + - when: + condition: + equal: [ "windows", << parameters.executor_type >> ] + steps: + - run: + name: verify required Environment Variables + command: | + if (!((Test-Path env:CIRCLE_HOSTNAME) -and (Test-Path env:CIRCLE_TOKEN))) { + Write-Host "You must provide 2 Environment Variables in project settings for this job to run." + Write-Host "CIRCLE_HOSTNAME: Should be the scheme://domain of your install. "https://ci.example.com"" + Write-Host "CIRCLE_TOKEN: Should be the API Key of an admin or project level with Scope:All" + Exit 1 + } + - run: + name: Verify that job ran with the requested resource_class option + command: | + $job = Invoke-RestMethod -URI "$env:CIRCLE_HOSTNAME/api/v2/project/gh/$env:CIRCLE_PROJECT_USERNAME/$env:CIRCLE_PROJECT_REPONAME/job/$env:CIRCLE_BUILD_NUM" ` + -Headers @{ "Circle-Token" = "$env:CIRCLE_TOKEN" } + $job.executor.resource_class | Select-String -Pattern "<<parameters.resource_class>>" remote_docker_defaults: &remote_docker_defaults - docker: [{image: 'docker:17.06-git'}] + docker: [{image: 'docker:25.0-git'}] basic_docker_build: &basic_docker_build name: "Build a really basic docker image" @@ -42,26 +91,79 @@ workspaces_defaults: &workspaces_defaults working_directory: ~/foo/bar jobs: - # resource class jobs - small: # 1 vCPU, 2GB RAM - <<: *resource_job_defaults - resource_class: small - - medium: # 2 vCPUs, 4GB RAM - <<: *resource_job_defaults - resource_class: medium + env-subst-example: + executor: docker + environment: + foo: bar + alpha: beta + steps: + - checkout + - run: + command: echo 'the value of foo is "$foo" and next to alpha is "$alpha"' > template.tmpl + - run: + command: cat template.tmpl + - run: + command: circleci env subst < template.tmpl > output.txt + - run: + command: grep "bar" output.txt | grep "beta" + + # job definition for verifying the resource_class per each executor_type + executor_resource_class: + parameters: + resource_class: + type: string + default: "small" + executor_type: + type: string + default: "docker" + executor: + name: <<parameters.executor_type>> + resource_class: <<parameters.resource_class>> + steps: + - verify_resource_class: + resource_class: <<parameters.resource_class>> + executor_type: <<parameters.executor_type>> - medium+: # 3 vCPUs, 6GB RAM - <<: *resource_job_defaults - resource_class: medium+ + check_if_environment_is_aws: + executor: docker + steps: + - run: + name: Verify AWS Environment + command: | + if [ -z "${CIRCLE_CLOUD_PROVIDER}" ];then + echo "You must provide the CIRCLE_CLOUD_PROVIDER environment variable in project settings for this job to run."; + exit 1; + fi + if [[ "${CIRCLE_CLOUD_PROVIDER}" != 'aws' ]]; then + echo "This installation is not in an AWS environment. Cancelling downstream workflow."; + curl -X POST "${CIRCLE_HOSTNAME%/}/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel?circle-token=$CIRCLE_TOKEN" + fi - large: # 4 vCPUs, 8GB RAM - <<: *resource_job_defaults - resource_class: large + check_if_environment_is_gcp: + executor: docker + steps: + - run: + name: Verify GCP Environment + command: | + if [ -z "${CIRCLE_CLOUD_PROVIDER}" ];then + echo "You must provide the CIRCLE_CLOUD_PROVIDER environment variable in project settings for this job to run."; + exit 1; + fi + if [[ "${CIRCLE_CLOUD_PROVIDER}" != 'gcp' ]]; then + echo "This installation is not in an GCP environment. Cancelling downstream workflow."; + curl -X POST "${CIRCLE_HOSTNAME%/}/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel?circle-token=$CIRCLE_TOKEN" + fi - xlarge: # 8 vCPUs, 16GB RAM - <<: *resource_job_defaults - resource_class: xlarge + check_if_windows_is_enabled: + executor: docker + steps: + - run: + name: Verify if Windows enabled env flag is set to true + command: | + if [[ "${CIRCLE_WINDOWS_EXECUTOR}" != "true" ]]; then + echo "Windows executor environment flag is not set to \"true\". Cancelling downstream workflow." + curl -X POST "${CIRCLE_HOSTNAME%/}/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel?circle-token=$CIRCLE_TOKEN" + fi # vm jobs machine: @@ -77,6 +179,37 @@ jobs: echo 'Done sleeping.' environment: SLEEP: 1 + + android_machine: + machine: + image: android-default + steps: + - run: + <<: *basic_docker_build + - run: | + echo $SLEEP + date + sleep $SLEEP + date + echo 'Done sleeping.' + environment: + SLEEP: 1 + + aws_arm: + machine: + image: arm-default + resource_class: arm.medium + steps: + - run: + <<: *basic_docker_build + - run: | + echo $SLEEP + date + sleep $SLEEP + date + echo 'Done sleeping.' + environment: + SLEEP: 1 remote_docker: <<: *remote_docker_defaults @@ -175,7 +308,7 @@ jobs: artifacts_test_results: docker: - - image: python:3.6.0 + - image: python:3.13.2 working_directory: ~/realitycheck steps: - checkout @@ -198,14 +331,24 @@ jobs: path: test-results workflows: - version: 2 - resource_class_jobs: + docker_resource_class_jobs: jobs: - - small - - medium - - medium+ - - large - - xlarge + - executor_resource_class: + matrix: + parameters: + resource_class: [small, medium, medium+, large, xlarge] + executor_type: [docker] # default, but re-defining for clarity + + windows_resource_class_jobs: + jobs: + - check_if_windows_is_enabled + - executor_resource_class: + matrix: + parameters: + resource_class: [windows.medium, windows.large, windows.xlarge] + executor_type: [windows] + requires: + - check_if_windows_is_enabled vm_jobs: jobs: @@ -213,6 +356,20 @@ workflows: - remote_docker - docker_layer_caching - machine_dlc + + aws_jobs: + jobs: + - check_if_environment_is_aws + - aws_arm: + requires: + - check_if_environment_is_aws + + gcp_jobs: + jobs: + - check_if_environment_is_gcp + - android_machine: + requires: + - check_if_environment_is_gcp feature_jobs: jobs: @@ -227,3 +384,6 @@ workflows: - write_workspace - artifacts_test_results + other_jobs: + jobs: + - env-subst-example diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1936f7bf..4fc92ab4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @circleci/release-engineering @circleci/server +* @circleci/on-prem diff --git a/README.md b/README.md index 75085578..6280b219 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,77 @@ -# realitycheck +# CircleCI Reality Check +This repository is used to check for a proper installation of CircleCI Server. It implements a sample app that validates some basic CircleCI features in parallel workflows. -## Summary -A sample app that validates some basic CircleCI features in three parallel workflows. + -**NOTE**: Please read the entirety of this README before continuing. There are some important prerequisites. +--- -To run realitycheck, fork the repository and start building it on your installation of CircleCI. See [Using realitycheck to validate your CircleCI installation](https://support.circleci.com/hc/en-us/articles/360011235534), in the CircleCI Support Center, for details on forking the project and building it on your CircleCI installation. +## Installation +To install and run reality check on your CircleCI Server installation, follow these steps. +1. Fork this repository to the GitHub environment tied to your server installation. [See here for more information](https://support.circleci.com/hc/en-us/articles/360011235534). + +2. Set up your repository project in your CircleCI Server installation. + +3. Generate a **personal api token - not a project token**, and add it as an environment variable in your project with the name `CIRCLE_TOKEN`. + +4. Determine the base URL of your install, including protocol, and remove the trailing slash and "app" subdomain if present. Add it as an environment variable in your project with the name `CIRCLE_HOSTNAME`. + + > *Note*: As an example, if your dashboard is accessible at `https://app.server.example.com/dashboard/` your `CIRCLE_HOSTNAME` is `https://server.example.com` + + +5. Set the environment variable in your project with the name `CIRCLE_CLOUD_PROVIDER` as either `gcp`, `aws`, or `other`. depending on your installation. + +6. You can __optionally__ set `CIRCLE_WINDOWS_EXECUTOR` to `true` in order to run a set of verification jobs for the windows execution environment. This requires a supported CircleCI Windows image, see instructions in [CircleCI-Public/circleci-server-windows-image-builder](https://github.com/CircleCI-Public/circleci-server-windows-image-builder). + +7. Configure the following contexts and keys (their values can be anything). Docs on how to set up contexts [can be found here](https://circleci.com/docs/2.0/contexts/). + +Context Name | Environment Variable Key Name | Value +-------------------|------------------------------- |----------------------------- +`org-global` | `CONTEXT_END_TO_END_TEST_VAR` | `1` +`individual-local` | `MULTI_CONTEXT_END_TO_END_VAR` | `1` + +### Example AWS Server Installation +```bash +# Project Environment Variables +CIRCLE_TOKEN=123456789-personal-access-token +CIRCLE_HOSTNAME=https://aws-server-install.example.com +CIRCLE_CLOUD_PROVIDER=aws +CIRCLE_WINDOWS_EXECUTOR=true # Optional, only if using a Windowws AMI + +# org-global context environment variables +CONTEXT_END_TO_END_TEST_VAR=1 + +# individual-local context environment variables +MULTI_CONTEXT_END_TO_END_VAR=1 +``` + +### Example GCP Server Installation +```bash +# Project Environment Variables +CIRCLE_TOKEN=123456789-personal-access-token +CIRCLE_HOSTNAME=https://gcp-server-install.example.com +CIRCLE_CLOUD_PROVIDER=gcp +CIRCLE_WINDOWS_EXECUTOR=true # Optional, only if using a Windows AMI + +# org-global context environment variables +CONTEXT_END_TO_END_TEST_VAR=1 + +# individual-local context environment variables +MULTI_CONTEXT_END_TO_END_VAR=1 +``` + +--- + +## Running Reality Check +Once installed, to run reality check, make any commit to the default branch of your forked repository. If installed correctly, your CircleCI Server Installation will pick up the commit and build it in parallel workflows. + +```bash +git commit --allow-empty -m "Trigger Build, Empty commit" && git push +``` + +--- + +## Reality Check Workflows Descriptions of the three workflows follow. ## `resource_class` workflow @@ -18,7 +83,6 @@ Tests all known `resource_class` options—queries the CircleCI API to verify th - The base URL of your CircleCI installation (e.g. https://circleci.com) must be specified via a `CIRCLE_HOSTNAME` project environment variable - A personal API token (see `CIRCLE_HOSTNAME/account/api` URL endpoint) must be stored as a `CIRCLE_TOKEN` project environment variable - ## VM service workflow Tests the functionality of the [`machine` executor](https://circleci.com/docs/2.0/executor-types/#using-machine), [Remote Docker Environment](https://circleci.com/docs/2.0/building-docker-images), and [Docker Layer Caching](https://circleci.com/docs/2.0/docker-layer-caching). @@ -29,14 +93,20 @@ Tests the functionality of the [`machine` executor](https://circleci.com/docs/2 - Tests multiple contexts (*NOTE:* needs a key called `MULTI_CONTEXT_END_TO_END_VAR` to exist in a context called `individual-local`) - Tests upload/storage of [artifacts](https://circleci.com/docs/2.0/artifacts) and [test results](https://circleci.com/docs/2.0/collect-test-data) + +## GCP Jobs Workflow +Tests android machine images on Google Cloud Platform. First checks if the environment is configured for GCP with the CIRCLE_CLOUD_PROVIDER environment variable. + ### Prerequisites -You will need to configure the following contexts and keys (their values can be anything). Docs on how to set up contexts [can be found here](https://circleci.com/docs/2.0/contexts/). +You will need to have your CIRCLE_TOKEN environment variable set to a personal access token, and will need your CIRCLE_CLOUD_PROVIDER set to `gcp` in lower-case. You must also have nomad clients configured, and your vm-service configured. + +## AWS Jobs Workflow +Tests ARM based images on AWS. First checks if the environment is configured for AWS with the CIRCLE_CLOUD_PROVIDER environment variable. -Context Name | Key Name ------------------|----------------------------- -org-global | CONTEXT_END_TO_END_TEST_VAR -individual-local | MULTI_CONTEXT_END_TO_END_VAR +### Prerequisites +You will need to have your CIRCLE_TOKEN environment variable set to a personal access token, and will need your CIRCLE_CLOUD_PROVIDER set to `aws` in lower-case. You must also have nomad clients configured, and your vm-service configured. +--- ## Contributing If you have more ideas for things that should tested, please submit a PR against the open-source repository on GitHub where this project is maintained: <https://github.com/circleci/realitycheck>. diff --git a/misc/reality_check.png b/misc/reality_check.png new file mode 100644 index 00000000..8d007dac Binary files /dev/null and b/misc/reality_check.png differ diff --git a/renovate.json b/renovate.json new file mode 100644 index 00000000..5db72dd6 --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended" + ] +}