Package: crc-bonfire
bonfireA CLI tool used by Red Hat engineers to deploy console.redhat.com applications into kubernetes/OpenShift. This tool is mainly used for the purpose of creating ephemeral test environments.As an example, typingbonfire deploy host-inventoryleads to the host-inventory application and all its dependencies being deployed and ready to run in under 4 minutes:Table of ContentsAboutInstallationQuick StartDeployingNamespace ManagementNamespace ContextExamples for Common Use CasesCommonly Used CLI OptionsDeploying/ProcessingInteractions with Ephemeral Namespace OperatorInteractions with Clowder OperatorClowdEnvironmentsDependency ProcessingConfiguration DetailsUsing a local configLocal config examplesDeploying local repo changesDeploying changes changes in a remote git branchAdvancedRunning a local qontract-serverAboutbonfireinteracts with a running instance ofqontract-server(the component that powers theAppSRE team's internalapp-interfacegraphql API) to obtain applications' OpenShift templates, process them, and deploy them. A local configuration file can be defined that allows you to override an application config if you wish.It also interacts with theephemeral namespace operatorto manage the reservation of ephemeral namespaces for testing.It has special functionality related to theClowder operatorandFrontend operatorsuch as auto-deploying ClowdApp dependencies.A wide range of CLI options allow you to customize exactly what combination of components get deployed into a namespace.NOTE: for information related to app-interface configurations, see the internalConsoleDot DocsInstallationInstalling locallyWe'd recommend setting up a virtual environment for bonfire:VENV_DIR=~/bonfire_venv
mkdir-p$VENV_DIRpython3-mvenv$VENV_DIR.$VENV_DIR/bin/activate
pipinstallcrc-bonfireTo prevent GitHub rate limiting issues when bonfire reaches out to GitHub APIs,create a personal access tokenon your GitHub account which grants bonfire read access to your repos.Configure bonfire to use the token with:echo 'GITHUB_TOKEN=<your api token>' >> ~/.config/bonfire/envPlease note: When using the Github token (classic), itmust havetheread:projectscope for the template fetching to work!Using a container image (podman/docker)We provide a container image at quay.io/cloudservices/bonfire. The image wraps a Python virtual environment withcrc-bonfireinstalled on it.In order to use Bonfire you have to provide either a valid KUBECONFIG or a URL and a TOKEN to connect to the target OpenShift cluster.The container's entrypoint already invokes thebonfireCLI with the arguments passed to the container, so you should be able to run any bonfire command you'd typically run, for example:podman run -it --rm quay.io/cloudservices/bonfire versionUsing credentialsThe Bonfire image can use theOC_LOGIN_SERVERandOC_LOGIN_TOKENvariables to connect to an Openshift cluster.podman run -it --rm -e OC_LOGIN_SERVER=https://api.openshift.example.com:6443 \
    -e OC_LOGIN_TOKEN=some-api-token \
    quay.io/cloudservices/bonfire namespace listYou can also make use of the kubeconfig file on your host by mounting it into the container's$HOMEdirectory:podman run -it --rm --userns=keep-id:uid=1000,gid=1000 -v ${KUBECONFIG:="$HOME/.kube/config"}:/opt/bonfire/.kube/config:Z \
    quay.io/cloudservices/bonfire namespace listIf you desire for the kubeconfig to live in a non-standard location in the container, you can mount the kubeconfig into another path in the container, and set the KUBECONFIG environment variable:podman run -it --rm --userns=keep-id:uid=1000,gid=1000 -v $HOME/.kube/config:/opt/kubeconfig:Z \
    -e KUBECONFIG=/opt/kubeconfig \
    quay.io/cloudservices/bonfire namespace listQuick StartStart withbonfire --helpto familiarize yourself with the basic command groups. Don't forget to use the--helpflag on sub-commmands as well if you are curious to learn more about different CLI commands, options, and arguments.DeployingThe command you are most likely to use isbonfire deploy.If you are on the Red Hat VPN,bonfirewill communicate with an internal instance of the App-SRE team'sqontract-serverAPI. You need to useoc loginto log in to the ephemeral cluster.Once logged in, you should be able to typebonfire deploy advisorThis will causebonfireto do the following:reserve a namespacefetch the templates for all components in the 'advisor' app and process them. By default, bonfire will look up the template and commit hash using the 'main'/'master' branch of each component defined in the app. It will look up the git commit hash for this branch and automatically set theIMAGE_TAGparameter passed to the templates.if ClowdApp resources are found, figure out which additional ClowdApps to fetch and processapply all the processed template resources into your reserved namespacewait for all the resources to reach a 'ready' stateRunbonfire namespace list --mineand you will see your namespace.Switch into that namespace withoc project <NAMESPACE>Runoc get clowdappin your namespace and you should see several ClowdApps have been deployed.If you want to to extend the time you have to work with your namespace, usebonfire namespace extend <NAMESPACE>When you are done working with your namespace, typebonfire namespace release <NAMESPACE>to instruct the ephemeral namespace operator to delete your reservation.The deploy command is an 'all-in-one' command that ties together 4 steps:bonfire namespace reserveto reserve a namespacebonfire processto fetch and process app templatesoc applyto apply the processed app templates into the namespacebonfire namespace wait-on-resources <NAMESPACE>to wait on all resources in the namespace to reach 'ready' stateNamespace ManagementReserve a namespace with:bonfire namespace reserveBy default, the duration is 1 hour. Increase it with-d/--duration <time>-- example time format:48hDifferent namespace pools are set up to provide different test environment configurations. Use--pool <pool>if you need to select a non-default pool. To get a list of valid pools, usebonfire pool listLook up namespaces with:bonfire namespace listuse--mineto see only ones reserved in your nameExtend your reservation with:bonfire namespace extend <NAMESPACE> -d <time>-- example time format:48hRelease your namespace reservation with:bonfire namespace release <NAMESPACE>Namespace ContextAs of v4.12.0,bonfirenow analyzes the namespace set in your oc/kubectl context. This means you can run commands such asnamespace extend,namespace release, ordeployafter you have switched into a namespace usingoc projectand you no longer need to specify the namespace on the CLI.bonfirewill attempt to use your current namespace (it will run checks to ensure that you own it first and warn if you do not). In addition, when a new namespace is reserved usingbonfire deployorbonfire namespace reserve, bonfire will also go ahead and runoc project <NAMESPACE>for you to switch your context into that new namespace.Thedeploycommand can be run using the--reserveflag if you wish to ignore the current namespace and force a namespace reservation to occur.The automatic 'oc' context switching into a newly reserved namespace is disabled when bonfire is operating in "bot" mode (i.e. when the env varBONFIRE_BOTis set totrue). When using bonfire in an automated CI/CD environment such as Jenkins, you should run in bot mode to disable automatic context switching.Examples for Common Use CasesIn these examples, we will use the 'advisor' app which has a ClowdApp component named 'advisor-backend'Deploy advisor-backend using a custom git branch:bonfire deploy advisor --set-template-ref advisor-backend=custom_branchDeploy advisor-backend using a custom git commit:bonfire deploy advisor --set-template-ref advisor-backend=df0d7a620b1ac02e59c5718eb22fe82b8a4cfd3dUse a certain branch to process the advisor-backend template, but set a different image tag on the container:bonfire deploy advisor --set-template-ref advisor-backend=some_branch --set-parameter advisor-backend/IMAGE_TAG=some_tagDeploy the production version of advisor and its dependencies:bonfire deploy advisor --ref-env insights-productionDeploy the production version of everything but use a dev branch for advisor-backend:bonfire deploy advisor --ref-env insights-production --set-template-ref advisor-backend=dev_branchAdjust the 'REPLICAS' parameter value at deploy time:bonfire deploy advisor --set-parameter advisor-backend/REPLICAS=3Override the tag for all occurences of a specific container image:bonfire deploy advisor --set-image-tag quay.io/cloudservices/advisor-backend=my_tagCommonly Used CLI OptionsDeploying/Processing--frontends=true-- by default, bonfire will not deploy Frontend resources. Use this flag to enable the deployment of app frontends.--set-image-tag <image uri>=<tag>-- use this to change the image tag of a container image that appears in your templates. This does a search/replace for all occurences of<image uri>and sets the tag to be<tag>--target-env-- this changes which deploy targetbonfirelooks up to determine the parameters to apply when processing app templates. By default, the target env is set toinsights-ephemeral--ref-env-- this changes which deploy targetbonfirelooks up to determine the git ref to fetch for your app configuration. For example, using--ref-env insights-stagewould cause bonfire to deploy the stage git ref of your app and--ref-env insights-productionwould cause bonfire to deploy the production git ref of your app. If a target matching the environment is not found,bonfiredefaults back to deploying the 'main'/'master' branch.--set-template-ref <component>=<ref>-- use this to change the git ref deployed for just a single component.--set-parameter <component>/<name>=<value>-- use this to set a parameter value on a specific component's template.--optional-deps-method <hybrid|all|none>-- change the way that bonfire processes ClowdApp optional dependencies (see "Dependency Processing" section)--prefer PARAM_NAME=PARAM_VALUE-- in cases where bonfire finds more than one deployment target, use this to set the parameter names and values that should be used to select a "preferred" deployment target. This option can be passed in multiple times.bonfirewill select the target with the highest amount of "preferred parameters" on it. Default is currently set toENV=frontendsto select "stable" frontends in the consoledot environments.Interactions with Ephemeral Namespace Operatorbonfirecreates/modifiesNamespaceReservationresources on the cluster to reserve and release namespaces. The template for the object that bonfire applies into the cluster can be foundhereFor more information about how the ephemeral namespace operator works, see its documentationhereInteractions with Clowder OperatorClowdEnvironmentsbonfireexpects a ClowderClowdEnvironmentresource to be created for a namespace before it can deploy into it. ThisClowdEnvironmentis already created by the ephemeral namespace operator.Whenbonfire deployis executed for a namespace, it will attempt to find the ClowdEnvironment associated with that namespace and set theENV_NAMEparameter accordingly for all templates it processes. All templates that define aClowdAppresource should set theenvironmentmapping in their spec using a parameter named${ENV_NAME}.Dependency ProcessingIn a ClowdApp definition, an app listed underdependenciesis considered an app that MUST be present for your app to function, while an app listed underoptionalDependenciesis considered an app that might be absent, but your app could still come up and function without it.When bonfire processes templates, if it finds a ClowdApp, it will do the following:if the ClowdApp hasdependencies, it will try to look up the config for that ClowdApp in app-interface and also fetch its templatesif the ClowdApp hasoptionalDependencies, it will behave differently based on which optional dependencies method is selected:hybrid(default): if an app group was explicitly specified on the CLI (example: when runningbonfire deploy app-athe app group 'app-a' is being explicitly specified) then theoptionalDependencieswill be deployed for it. For any ClowdAppbonfirecomes across that is not a member of an explicitly specified app group, theoptionalDependencieswill NOT be deployed. As an example:app-ahasapp-b-clowdapplisted underoptionalDependenciesapp-b-clowdapphasapp-c-clowdapplisted under itsoptionalDependenciesYou will end up with all components ofapp-aandapp-b-clowdappin your namespace.app-c-clowdappwould NOT be deployed into the namespace.all:bonfirewill deploy alloptionalDependenciesfor all ClowdApps it encounters. It will recursively process dependencies. As an example:app-ahasapp-b-clowdapplisted underoptionalDependenciesapp-b-clowdapphasapp-c-clowdapplisted under itsoptionalDependenciesYou will end up with all components ofapp-a,app-b-clowdapp, ANDapp-c-clowdappdeployed into the namespace.none:bonfirewill ignore theoptionalDependencieson all ClowdApps that it encountersConfiguration DetailsNOTE: for information related to app-interface configurations, see the internalConsoleDot DocsWhen runningbonfire process/bonfire deploy, by default the app-sre team's internal GraphQL API server is used.bonfirewill query the GraphQL API and read the application's deploy configuration.NOTE: You need to be on the internal VPN in order to access the default GraphQL API URL.bonfirerelies on a few key pieces of info to process app configs:The application name. This is typically the name of the listed inapp.yamlinapp-interfaceA 'target env' -- the name of theapp-interfaceenvironment that bonfire looks at to determine the parameters to apply when processing app templates. An app's config will only be processed if it has a deploy target set up that is pointing to a namespace in this environment (default: "ephemeral")A 'ref env' -- the name of theapp-interfaceenvironment that we want to use in order to figure out which git ref of the components to deploy and whichIMAGE_TAGvalue to set. By default, none is set which causes bonfire to use the 'main'/'master' git branch for all components.Any template refs you wish to override (optional)Any image tags you wish to override (optional)Any parameters you wish to override (optional)By default, if app components useClowdAppresources in their templates, thenbonfirewill dynamically load dependencies (see "Dependency Processing" section)Using a local configbonfireships with adefault configthat should be enough to get started for most internal Red Hat employees.By default, the configuration file will be stored in~/.config/bonfire/config.yaml.If you wish to override any app configurations, you can edit your local configuration file by typingbonfire config edit. You can then define an app under theappskey of the config. You can reset the config to default at any time usingbonfire config write-default.As ofbonfirev5, there are two options for how the local configuration is loaded (controlled by the--local-config-methodCLI option). Let's say we have an app configured in app-interface like this:resourceTemplates:
- name: mycomponent1
  path: /deployment.yaml
  url: https://github.com/myorg/myrepo1
  targets:
  - namespace:
      $ref: /services/insights/ephemeral/namespaces/ephemeral-base.yml
    parameters:
      MIN_REPLICAS: 1
- name: mycomponent2
  path: /deployment.yaml
  url: https://github.com/myorg/myrepo2
  targets:
  - namespace:
      $ref: /services/insights/ephemeral/namespaces/ephemeral-base.yml
    parameters:
      MIN_REPLICAS: 2
      SOME_OTHER_PARAM: some_other_valueand the local config file has this entry:apps:
- name: myapp
  components:
  - name: mycomponent2
    parameters:
      MIN_REPLICAS: 10bonfirecan override the remote configuration using one of two methods:--local-config-method merge(default). In this mode, the apps config in your local config is merged with the configuration that bonfire fetched remotely. With the above config, only the 'MIN_REPLICAS' parameter of 'mycomponent2' within app 'myapp' will be overridden. The 'SOME_OTHER_PARAM' parameter will still be present, and 'mycomponent1' would be unchanged.--local-config-method override. In this mode, the local app configuration will take precedence over the app's configuration that bonfire fetched remotely. In other words, defining a local app configuration will replace the configuration defined in app-interface for ALL components within that app. So 'mycomponent1' would be completely removed, and 'mycomponent2' would only have the parameters you defined in the local config.Local config examplesDeploying local repo changesIf you wanted to test out some changes you're making to an app but you have not yet pushed these changes to a git repo, the local config could look similar to:apps:
- name: my_app
  components:
    - name: service
      host: local
      repo: ~/dev/projects/my-app
      path: /clowdapp.yaml
      parameters:
        SOME_PARAMETER: some_valueWherehostsetlocalindicates to look for the repo in a local directoryWhererepoindicates the path to your git repo folderWherepathspecifies the relative path to your ClowdApp template file in your git repoBy default,bonfirewill rungit rev-parseto determine the current working commit hash in your repo folder, and this determines what IMAGE_TAG to set when the template is deployed. This means you would need to have a valid container image pushed for this commit hash. However, you can use--set-image-tag/--set-parameteror define theIMAGE_TAGparameter in your config in order to override the image you wish to use during the deployment.Deploying changes changes in a remote git branchIf you wanted to deploy changes to your app that you were working on which have been pushed to a PR/branch, the local config could look similar to:apps:
- name: my_app
  components:
    - name: service
      host: github
      repo: MyOrg/MyRepo
      ref: my_branch
      path: /clowdapp.yamlWherehostset togithuborgitlabindicates where the repo is hostedWhererepoindicates theOrganizationName/RepoNameWherepathspecifies the relative path to your ClowdApp template file in your git repoWhererefspecifies the branch or commit of the repo you want to deployBy default, bonfire will use the latest commit hash found at the specified git ref to determine what IMAGE_TAG pass on to the deployment templates.AdvancedRunning a local qontract-serverbonfire is configured to point to the app-sre team's internal GraphQL API by default, but by using env variables you can point to your your own instance ofqontract-server:exportQONTRACT_BASE_URL="https://localhost:4000/graphql"exportQONTRACT_USERNAME=myUsernameexportQONTRACT_PASSWORD=myPasswordFor testing/debug purposes, instead of committing changes directly to app-interface, you can run your own local copy of the app-interface API server.Clonehttps://github.com/app-sre/qontract-serverClone the internalapp-interfacerepoInqontract-server, run:npm install yarn
yarn install
yarn build
make bundle APP_INTERFACE_PATH=/path/to/app-interface
LOAD_METHOD=fs DATAFILES_FILE=bundle/bundle.json yarn run server