start_buildx:
  stage: prepare
  environment:
    name: buildx_${CI_COMMIT_REF_SLUG}
    auto_stop_in: "${BUILDX_K8S_AUTOSTOP_IN}"
    action: start
    on_stop: stop_buildx
  script:
    - echo "Initialized buildx_${CI_COMMIT_REF_SLUG} environment"
  rules:
   - !reference [.skip_if_chart_version_pipeline]
   - !reference [build_branch_image, rules]
   - !reference [build_tag_image, rules]
   - !reference [build_latest_image, rules]

stop_buildx:
  stage: cleanup
  image: "registry.gitlab.com/gitlab-org/gitlab-omnibus-builder/distribution_ci_tools:${CI_TOOLS_VERSION}"
  needs: []
  script:
    - source ./ci/scripts/buildx/lib/configure.sh
    - ci/scripts/buildx/teardown.sh
  retry: 2
  environment:
    name: buildx_${CI_COMMIT_REF_SLUG}
    action: stop
  when: manual
  rules:
   - !reference [start_buildx, rules]
  
