---
# $ fly -t target sp -p apt_utils-cookbook -c concourse.yml -l fly-vars.yml -l ~/sec/credentials-prod.yml
resource_types:
- name: ya-git
  type: docker-image
  source:
    repository: whitestar/git-resource
    registry_mirror: https://((registry-mirror-domain))
    ca_certs:
    - domain: ((registry-mirror-domain))
      cert: ((docker-reg-ca-cert))

resources:
- name: src-git
  type: ya-git
  #type: git
  source:
    uri: git://git.osdn.net/gitroot/metasearch/grid-chef-repo.git
    branch: master
    paths:
    - cookbooks/((cookbook-name))
    private_key: ((git-private-key))
    git_user: ((git-user-osdn))
  #check_every: 1h  # default: 1m
- name: chefdk-cache
  type: docker-image
  source:
    repository: chef/chefdk
    tag: ((chefdk-version))
    # ((param)) style: fly >= 3.2.0
    registry_mirror: https://((registry-mirror-domain))  # e.g. https://registry.docker.example.com:5000
    ca_certs:
    - domain: ((registry-mirror-domain))  # e.g. registry.docker.example.com:5000
      cert: ((docker-reg-ca-cert))
  check_every: 12h  # default: 1m

jobs:
- name: test-cookbook
  plan:
  - aggregate:
    - get: src-git
      params:
        depth: 5
      trigger: true
    - get: chefdk-cache
  - task: ci-build
    image: chefdk-cache
    params:
      http_proxy: ((http-proxy))  # e.g. http://proxy.example.com:3128
      #HTTP_PROXY: ((http-proxy))
    config:
      platform: linux
      #image_resource:
      #  type: docker-image
      #  source:
      #    repository: chef/chefdk
      #    tag: ((chefdk-version))
          # NG, setting disable
          #registry_mirror: https://((registry-mirror-domain))
          #ca_certs:
          #- domain: ((registry-mirror-domain))
          #  cert: ((docker-reg-ca-cert))
      inputs:
      - name: src-git
      run:
        #dir: ./src-git/cookbooks/((cookbook-name))
        #path: rake
        path: /bin/bash
        args:
        - -c
        - |
          cd ./src-git/cookbooks/((cookbook-name))
          bundle install
          rake
- name: publish-cookbook
  plan:
  - aggregate:
    - get: src-git
      params:
        depth: 5
      trigger: false
    - get: chefdk-cache
  - task: publish
    image: chefdk-cache
    params:
      http_proxy: ((http-proxy))
      chef_username: ((chef-username))
      chef_client_key: ((chef-client-key))
    config:
      platform: linux
      inputs:
      - name: src-git
      run:
        path: /bin/bash
        args:
        - -c
        - |
          echo '{"username":"((chef-username))","key":"/root/chef-client-key.pem"}' > /root/.stove
          echo "$chef_client_key"  > /root/chef-client-key.pem
          cd ./src-git/cookbooks/((cookbook-name))
          bundle install
          rake publish
  - put: src-git
    params:
      repository: src-git
      tag_prefix: ((cookbook-name))-
      tag: src-git/cookbooks/((cookbook-name))/version
      only_tag: true
      annotate: src-git/cookbooks/((cookbook-name))/version
      #annotate:   # path to a file containing the annotation message.
