### ***
### WARNING: DO NOT manually EDIT or MERGE this file, it is generated by 'make ci-config'.
### INSTEAD: Edit or merge the source in config/ then run 'make ci-config'.
### ***
# Orb 'circleci/slack@3.4.2' resolved to 'circleci/slack@3.4.2'
version: 2
jobs:
  build-common-layers:
    machine:
      image: ubuntu-1604:202007-01
    resource_class: xlarge
    shell: /usr/bin/env bash -euo pipefail -c
    steps:
    - add_ssh_keys:
        fingerprints:
        - c6:96:98:82:dc:04:6c:39:dd:ac:83:05:e3:15:1c:98
    - checkout
    - run:
        command: make -C packages*.lock write-builder-cache-keys
        name: Write builder layer cache keys
    - restore_cache:
        keys:
        - cache006-copy-source_dde4_{{checksum ".buildcache/cache-keys/copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3"}}
        - cache006-go-modules_694e_{{checksum ".buildcache/cache-keys/go-modules-694e8500194e3b187b35bd9a40229f3bd215710e"}}
        - cache006-ui_5f82_{{checksum ".buildcache/cache-keys/ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d"}}
        - cache006-base_aac1_{{checksum ".buildcache/cache-keys/base-aac1d959b4b3af1495941602b5e51fb6181baded"}}
        name: Restore build image cache
    - run:
        command: |
          if [ -f .buildcache/archives/03-copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3.tar.gz ]; then
            echo "Exact match found in cache, skipping build."
            circleci-agent step halt
          else
            echo "No exact match found, proceeding with build."
          fi
        name: Finish early if loaded exact match from cache.
    - run:
        command: |
          LAYER_SPEC_ID=03-copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3 make -C packages*.lock load-builder-cache
        name: Load whatever builder cache we have (if any) into the Docker daemon
        no_output_timeout: 30m
    - run:
        command: |2

          KEYFILE="$HOME/.ssh/id_rsa_c6969882dc046c39ddac8305e3151c98"
          eval "$(ssh-agent -s)"
          if [ -f "$KEYFILE" ]; then
            ssh-add "$KEYFILE"
          else
            echo "==> INFO: SSH key for github.com not found"
            echo "    Attempts to access private repositories from within"
            echo "    the build will fail, e.g. for private go modules, or"
            echo "    attempts to directly clone private repositories."
          fi

          make -f packages*.lock/layer.mk 00-base-aac1d959b4b3af1495941602b5e51fb6181baded-image
        name: Build base layer
    - run:
        command: |2

          KEYFILE="$HOME/.ssh/id_rsa_c6969882dc046c39ddac8305e3151c98"
          eval "$(ssh-agent -s)"
          if [ -f "$KEYFILE" ]; then
            ssh-add "$KEYFILE"
          else
            echo "==> INFO: SSH key for github.com not found"
            echo "    Attempts to access private repositories from within"
            echo "    the build will fail, e.g. for private go modules, or"
            echo "    attempts to directly clone private repositories."
          fi

          make -f packages*.lock/layer.mk 01-ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d-image
        name: Build ui layer
    - run:
        command: |2

          KEYFILE="$HOME/.ssh/id_rsa_c6969882dc046c39ddac8305e3151c98"
          eval "$(ssh-agent -s)"
          if [ -f "$KEYFILE" ]; then
            ssh-add "$KEYFILE"
          else
            echo "==> INFO: SSH key for github.com not found"
            echo "    Attempts to access private repositories from within"
            echo "    the build will fail, e.g. for private go modules, or"
            echo "    attempts to directly clone private repositories."
          fi

          make -f packages*.lock/layer.mk 02-go-modules-694e8500194e3b187b35bd9a40229f3bd215710e-image
        name: Build go-modules layer
    - run:
        command: |2

          KEYFILE="$HOME/.ssh/id_rsa_c6969882dc046c39ddac8305e3151c98"
          eval "$(ssh-agent -s)"
          if [ -f "$KEYFILE" ]; then
            ssh-add "$KEYFILE"
          else
            echo "==> INFO: SSH key for github.com not found"
            echo "    Attempts to access private repositories from within"
            echo "    the build will fail, e.g. for private go modules, or"
            echo "    attempts to directly clone private repositories."
          fi

          make -f packages*.lock/layer.mk 03-copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3-image
        name: Build copy-source layer
    - run:
        command: make -f packages*.lock/layer.mk 03-copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3-save
        name: Export builder image
    - save_cache:
        key: cache006-copy-source_dde4_{{checksum ".buildcache/cache-keys/copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3"}}
        name: Save layer copy-source to cache.
        paths:
        - .buildcache/archives/03-copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3.tar.gz
    - run:
        command: mv .buildcache/archives/03-copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3.tar.gz .buildcache/archives/02-go-modules-694e8500194e3b187b35bd9a40229f3bd215710e.tar.gz
        name: Prepare layer go-modules for caching
    - save_cache:
        key: cache006-go-modules_694e_{{checksum ".buildcache/cache-keys/go-modules-694e8500194e3b187b35bd9a40229f3bd215710e"}}
        name: Save layer go-modules to cache.
        paths:
        - .buildcache/archives/02-go-modules-694e8500194e3b187b35bd9a40229f3bd215710e.tar.gz
    - run:
        command: mv .buildcache/archives/02-go-modules-694e8500194e3b187b35bd9a40229f3bd215710e.tar.gz .buildcache/archives/01-ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d.tar.gz
        name: Prepare layer ui for caching
    - save_cache:
        key: cache006-ui_5f82_{{checksum ".buildcache/cache-keys/ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d"}}
        name: Save layer ui to cache.
        paths:
        - .buildcache/archives/01-ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d.tar.gz
    - run:
        command: mv .buildcache/archives/01-ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d.tar.gz .buildcache/archives/00-base-aac1d959b4b3af1495941602b5e51fb6181baded.tar.gz
        name: Prepare layer base for caching
    - save_cache:
        key: cache006-base_aac1_{{checksum ".buildcache/cache-keys/base-aac1d959b4b3af1495941602b5e51fb6181baded"}}
        name: Save layer base to cache.
        paths:
        - .buildcache/archives/00-base-aac1d959b4b3af1495941602b5e51fb6181baded.tar.gz
    environment:
    - AUTO_INSTALL_TOOLS: 'YES'
    - BUILDKIT_PROGRESS: plain
    - PRODUCT_REVISION: ''
  darwin_amd64_package:
    docker:
    - image: circleci/buildpack-deps
    shell: /usr/bin/env bash -euo pipefail -c
    environment:
    - AUTO_INSTALL_TOOLS: 'YES'
    - BUILDKIT_PROGRESS: plain
    - PRODUCT_REVISION: ''
    - PACKAGE_SPEC_ID: 3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3
    steps:
    - setup_remote_docker:
        version: 19.03.12
    - add_ssh_keys:
        fingerprints:
        - c6:96:98:82:dc:04:6c:39:dd:ac:83:05:e3:15:1c:98
    - checkout
    - run:
        command: make -C packages*.lock write-package-cache-key
        name: Write package cache key
    - restore_cache:
        key: cache006-package-3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3-{{checksum ".buildcache/cache-keys/package-3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3"}}
        name: Restore package cache
    - run:
        command: |
          if ! { PKG=$(find .buildcache/packages/store -maxdepth 1 -mindepth 1 -name '*.zip' 2> /dev/null) && [ -n "$PKG" ]; }; then
            echo "No package found, continuing with build."
            exit 0
          fi
          echo "Package already cached, skipping build."
          circleci-agent step halt
        name: Check the cache status.
    - run:
        command: make -C packages*.lock write-builder-cache-keys
        name: Write builder layer cache keys
    - restore_cache:
        keys:
        - cache006-copy-source_dde4_{{checksum ".buildcache/cache-keys/copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3"}}
        - cache006-go-modules_694e_{{checksum ".buildcache/cache-keys/go-modules-694e8500194e3b187b35bd9a40229f3bd215710e"}}
        - cache006-ui_5f82_{{checksum ".buildcache/cache-keys/ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d"}}
        - cache006-base_aac1_{{checksum ".buildcache/cache-keys/base-aac1d959b4b3af1495941602b5e51fb6181baded"}}
        name: Restore build layer cache
    - run:
        command: |
          make -C packages*.lock load-builder-cache
        name: Load whatever builder cache we have (if any) into the Docker daemon
        no_output_timeout: 30m
    - run:
        command: |2

          KEYFILE="$HOME/.ssh/id_rsa_c6969882dc046c39ddac8305e3151c98"
          eval "$(ssh-agent -s)"
          if [ -f "$KEYFILE" ]; then
            ssh-add "$KEYFILE"
          else
            echo "==> INFO: SSH key for github.com not found"
            echo "    Attempts to access private repositories from within"
            echo "    the build will fail, e.g. for private go modules, or"
            echo "    attempts to directly clone private repositories."
          fi

          make -C packages*.lock package
        name: Compile Package
    - run:
        command: ls -lahR .buildcache/packages
        name: List packages
    - save_cache:
        key: cache006-package-3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3-{{checksum ".buildcache/cache-keys/package-3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3"}}
        name: Saving package cache
        paths:
        - .buildcache/packages/store
  linux_amd64_package:
    docker:
    - image: circleci/buildpack-deps
    shell: /usr/bin/env bash -euo pipefail -c
    environment:
    - AUTO_INSTALL_TOOLS: 'YES'
    - BUILDKIT_PROGRESS: plain
    - PRODUCT_REVISION: ''
    - PACKAGE_SPEC_ID: 26ad460ac09efc9c56bdbb7a962ff92616c06c51
    steps:
    - setup_remote_docker:
        version: 19.03.12
    - add_ssh_keys:
        fingerprints:
        - c6:96:98:82:dc:04:6c:39:dd:ac:83:05:e3:15:1c:98
    - checkout
    - run:
        command: make -C packages*.lock write-package-cache-key
        name: Write package cache key
    - restore_cache:
        key: cache006-package-26ad460ac09efc9c56bdbb7a962ff92616c06c51-{{checksum ".buildcache/cache-keys/package-26ad460ac09efc9c56bdbb7a962ff92616c06c51"}}
        name: Restore package cache
    - run:
        command: |
          if ! { PKG=$(find .buildcache/packages/store -maxdepth 1 -mindepth 1 -name '*.zip' 2> /dev/null) && [ -n "$PKG" ]; }; then
            echo "No package found, continuing with build."
            exit 0
          fi
          echo "Package already cached, skipping build."
          circleci-agent step halt
        name: Check the cache status.
    - run:
        command: make -C packages*.lock write-builder-cache-keys
        name: Write builder layer cache keys
    - restore_cache:
        keys:
        - cache006-copy-source_dde4_{{checksum ".buildcache/cache-keys/copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3"}}
        - cache006-go-modules_694e_{{checksum ".buildcache/cache-keys/go-modules-694e8500194e3b187b35bd9a40229f3bd215710e"}}
        - cache006-ui_5f82_{{checksum ".buildcache/cache-keys/ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d"}}
        - cache006-base_aac1_{{checksum ".buildcache/cache-keys/base-aac1d959b4b3af1495941602b5e51fb6181baded"}}
        name: Restore build layer cache
    - run:
        command: |
          make -C packages*.lock load-builder-cache
        name: Load whatever builder cache we have (if any) into the Docker daemon
        no_output_timeout: 30m
    - run:
        command: |2

          KEYFILE="$HOME/.ssh/id_rsa_c6969882dc046c39ddac8305e3151c98"
          eval "$(ssh-agent -s)"
          if [ -f "$KEYFILE" ]; then
            ssh-add "$KEYFILE"
          else
            echo "==> INFO: SSH key for github.com not found"
            echo "    Attempts to access private repositories from within"
            echo "    the build will fail, e.g. for private go modules, or"
            echo "    attempts to directly clone private repositories."
          fi

          make -C packages*.lock package
        name: Compile Package
    - run:
        command: ls -lahR .buildcache/packages
        name: List packages
    - save_cache:
        key: cache006-package-26ad460ac09efc9c56bdbb7a962ff92616c06c51-{{checksum ".buildcache/cache-keys/package-26ad460ac09efc9c56bdbb7a962ff92616c06c51"}}
        name: Saving package cache
        paths:
        - .buildcache/packages/store
  windows_amd64_package:
    docker:
    - image: circleci/buildpack-deps
    shell: /usr/bin/env bash -euo pipefail -c
    environment:
    - AUTO_INSTALL_TOOLS: 'YES'
    - BUILDKIT_PROGRESS: plain
    - PRODUCT_REVISION: ''
    - PACKAGE_SPEC_ID: 6b5bf7794d67cf76b1b4772807af52deb1f6a808
    steps:
    - setup_remote_docker:
        version: 19.03.12
    - add_ssh_keys:
        fingerprints:
        - c6:96:98:82:dc:04:6c:39:dd:ac:83:05:e3:15:1c:98
    - checkout
    - run:
        command: make -C packages*.lock write-package-cache-key
        name: Write package cache key
    - restore_cache:
        key: cache006-package-6b5bf7794d67cf76b1b4772807af52deb1f6a808-{{checksum ".buildcache/cache-keys/package-6b5bf7794d67cf76b1b4772807af52deb1f6a808"}}
        name: Restore package cache
    - run:
        command: |
          if ! { PKG=$(find .buildcache/packages/store -maxdepth 1 -mindepth 1 -name '*.zip' 2> /dev/null) && [ -n "$PKG" ]; }; then
            echo "No package found, continuing with build."
            exit 0
          fi
          echo "Package already cached, skipping build."
          circleci-agent step halt
        name: Check the cache status.
    - run:
        command: make -C packages*.lock write-builder-cache-keys
        name: Write builder layer cache keys
    - restore_cache:
        keys:
        - cache006-copy-source_dde4_{{checksum ".buildcache/cache-keys/copy-source-dde49480ad145a6d7ce0f55c0d23e6f50c04d8d3"}}
        - cache006-go-modules_694e_{{checksum ".buildcache/cache-keys/go-modules-694e8500194e3b187b35bd9a40229f3bd215710e"}}
        - cache006-ui_5f82_{{checksum ".buildcache/cache-keys/ui-5f82d1f0cbf979ee051aa1ba0f7105483fa6947d"}}
        - cache006-base_aac1_{{checksum ".buildcache/cache-keys/base-aac1d959b4b3af1495941602b5e51fb6181baded"}}
        name: Restore build layer cache
    - run:
        command: |
          make -C packages*.lock load-builder-cache
        name: Load whatever builder cache we have (if any) into the Docker daemon
        no_output_timeout: 30m
    - run:
        command: |2

          KEYFILE="$HOME/.ssh/id_rsa_c6969882dc046c39ddac8305e3151c98"
          eval "$(ssh-agent -s)"
          if [ -f "$KEYFILE" ]; then
            ssh-add "$KEYFILE"
          else
            echo "==> INFO: SSH key for github.com not found"
            echo "    Attempts to access private repositories from within"
            echo "    the build will fail, e.g. for private go modules, or"
            echo "    attempts to directly clone private repositories."
          fi

          make -C packages*.lock package
        name: Compile Package
    - run:
        command: ls -lahR .buildcache/packages
        name: List packages
    - save_cache:
        key: cache006-package-6b5bf7794d67cf76b1b4772807af52deb1f6a808-{{checksum ".buildcache/cache-keys/package-6b5bf7794d67cf76b1b4772807af52deb1f6a808"}}
        name: Saving package cache
        paths:
        - .buildcache/packages/store
  bundle-releases:
    docker:
    - image: circleci/buildpack-deps
    shell: /usr/bin/env bash -euo pipefail -c
    steps:
    - checkout
    - run:
        command: make -C packages*.lock write-all-package-cache-keys
        name: Write all package cache keys
    - restore_cache:
        key: cache006-package-3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3-{{checksum ".buildcache/cache-keys/package-3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3"}}
    - run:
        command: |
          make package-meta
        environment:
          PACKAGE_SPEC_ID: 3f81e804b31cb70e63a9c834931d9a0a4c2e2bb3
        name: Write package metadata for darwin_amd64_package
    - restore_cache:
        key: cache006-package-26ad460ac09efc9c56bdbb7a962ff92616c06c51-{{checksum ".buildcache/cache-keys/package-26ad460ac09efc9c56bdbb7a962ff92616c06c51"}}
    - run:
        command: |
          make package-meta
        environment:
          PACKAGE_SPEC_ID: 26ad460ac09efc9c56bdbb7a962ff92616c06c51
        name: Write package metadata for linux_amd64_package
    - restore_cache:
        key: cache006-package-6b5bf7794d67cf76b1b4772807af52deb1f6a808-{{checksum ".buildcache/cache-keys/package-6b5bf7794d67cf76b1b4772807af52deb1f6a808"}}
    - run:
        command: |
          make package-meta
        environment:
          PACKAGE_SPEC_ID: 6b5bf7794d67cf76b1b4772807af52deb1f6a808
        name: Write package metadata for windows_amd64_package
    - run:
        command: make aliases
        name: Write package aliases
    - run:
        command: ls -lahR .buildcache
        name: List Build Cache
    - run:
        command: cp packages*.lock/pkgs.yml lockfile-standalone.yml
    - store_artifacts:
        destination: lockfile-standalone.yml
        path: lockfile-standalone.yml
    - store_artifacts:
        destination: packages-standalone
        path: .buildcache/packages
    - run:
        command: tar -czf packages-standalone.tar.gz .buildcache/packages lockfile-standalone.yml
    - store_artifacts:
        destination: packages-standalone.tar.gz
        path: packages-standalone.tar.gz
    - run:
        command: tar -czf meta-standalone.tar.gz .buildcache/packages/store/*.json lockfile-standalone.yml
    - store_artifacts:
        destination: meta-standalone.tar.gz
        path: meta-standalone.tar.gz
    environment:
    - AUTO_INSTALL_TOOLS: 'YES'
    - BUILDKIT_PROGRESS: plain
    - PRODUCT_REVISION: ''
  build:
    machine:
      image: ubuntu-1604:201903-01
    steps:
    - add_ssh_keys:
        fingerprints:
        - c6:96:98:82:dc:04:6c:39:dd:ac:83:05:e3:15:1c:98
    - checkout
    - run:
        command: |
          make test-ci
        name: Run Acceptance Tests
    - run:
        command: |
          echo 'export SLACK_BUILD_STATUS="fail"' >> $BASH_ENV
        name: Slack - Setting Failure Condition
        when: on_fail
    - run:
        command: |
          echo 'export SLACK_BUILD_STATUS="success"' >> $BASH_ENV
        name: Slack - Setting Success Condition
        when: on_success
    - run:
        command: |
          if [ ! -x /bin/bash ]; then
            echo Bash not installed.
            exit 1
          fi
        name: Provide error if non-bash shell
    - run:
        command: |
          current_branch_in_filter=false

          IFS="," read -ra BRANCH_FILTERS <<< "master"

          for i in "${BRANCH_FILTERS[@]}"; do
            if [ "${i}" == "${CIRCLE_BRANCH}" ]; then
              current_branch_in_filter=true
            fi
          done

          if [ "x" == "xmaster" ] || [ "$current_branch_in_filter" = true ]; then
            # Provide error if no webhook is set and error. Otherwise continue
            if [ -z "webhook" ]; then
              echo "NO SLACK WEBHOOK SET"
              echo "Please input your SLACK_WEBHOOK value either in the settings for this project, or as a parameter for this orb."
              exit 1
            else
              #Create Members string
              if [ -n "" ]; then
                IFS="," read -ra SLACK_MEMBERS <<< ""
                for i in "${SLACK_MEMBERS[@]}"; do
                  if [ $(echo ${i} | head -c 1) == "S" ]; then
                    SLACK_MENTIONS="${SLACK_MENTIONS}<!subteam^${i}> "
                  elif echo ${i} | grep -E "^(here|channel|everyone)$" > /dev/null; then
                    SLACK_MENTIONS="${SLACK_MENTIONS}<!${i}> "
                  else
                    SLACK_MENTIONS="${SLACK_MENTIONS}<@${i}> "
                  fi
                done
              fi
              #If successful
              if [ "$SLACK_BUILD_STATUS" = "success" ]; then
                #Skip if fail_only
                if [ true = true ]; then
                  echo "The job completed successfully"
                  echo '"fail_only" is set to "true". No Slack notification sent.'
                else
                  curl -X POST -H 'Content-type: application/json' \
                    --data "{ \
                              \"attachments\": [ \
                                { \
                                  \"fallback\": \":tada: A $CIRCLE_JOB job has succeeded!\", \
                                  \"text\": \":tada: A $CIRCLE_JOB job has succeeded! $SLACK_MENTIONS\", \
                                  \"fields\": [ \
                                    { \
                                      \"title\": \"Project\", \
                                      \"value\": \"$CIRCLE_PROJECT_REPONAME\", \
                                      \"short\": true \
                                    }, \
                                    { \
                                      \"title\": \"Job Number\", \
                                      \"value\": \"$CIRCLE_BUILD_NUM\", \
                                      \"short\": true \
                                    } \
                                  ], \
                                  \"actions\": [ \
                                    { \
                                      \"type\": \"button\", \
                                      \"text\": \"Visit Job\", \
                                      \"url\": \"$CIRCLE_BUILD_URL\" \
                                    } \
                                  ], \
                                  \"color\": \"#1CBF43\" \
                                } \
                              ] \
                            } " webhook
                  echo "Job completed successfully. Alert sent."
                fi
              else
                #If Failed
                curl -X POST -H 'Content-type: application/json' \
                  --data "{ \
                    \"attachments\": [ \
                      { \
                        \"fallback\": \":red_circle: A $CIRCLE_JOB job has failed!\", \
                        \"text\": \":red_circle: A $CIRCLE_JOB job has failed! $SLACK_MENTIONS\", \
                        \"fields\": [ \
                          { \
                            \"title\": \"Project\", \
                            \"value\": \"$CIRCLE_PROJECT_REPONAME\", \
                            \"short\": true \
                          }, \
                          { \
                            \"title\": \"Job Number\", \
                            \"value\": \"$CIRCLE_BUILD_NUM\", \
                            \"short\": true \
                          } \
                        ], \
                        \"actions\": [ \
                          { \
                            \"type\": \"button\", \
                            \"text\": \"Visit Job\", \
                            \"url\": \"$CIRCLE_BUILD_URL\" \
                          } \
                        ], \
                        \"color\": \"#ed5c5c\" \
                      } \
                    ] \
                  } " webhook
                echo "Job failed. Alert sent."
              fi
            fi
          else
            echo "Current branch is not included in only_for_branches filter; no status alert will be sent"
          fi
        name: Slack - Sending Status Alert
        shell: /bin/bash
        when: always
    working_directory: ~/boundary
workflows:
  build-standalone:
    jobs:
    - build-common-layers
    - darwin_amd64_package:
        requires:
        - build-common-layers
    - linux_amd64_package:
        requires:
        - build-common-layers
    - windows_amd64_package:
        requires:
        - build-common-layers
    - bundle-releases:
        requires:
        - darwin_amd64_package
        - linux_amd64_package
        - windows_amd64_package
  default:
    jobs:
    - build
  version: 2
