variables:
  # Ownership/permission conflicts in /tmp/terragrunt-download are possible, so set TMPDIR to a path inside the build.
  TMPDIR: "$CI_PROJECT_DIR/gitlab-tmp"

before_script:
  - echo "$TMPDIR"  # So it's visible in the log
  - mkdir "$TMPDIR"

stages:
  - setup
  - dev
  - promote-to-stg
  - stg

setup:
  stage: setup
  script:
    - terraform -version
    - terragrunt -version
    - kubectl version --client
    - kops version
    - aws --version
    - jq --version
    - ruby --version
    - bundle version
    - rake --version

dev:
  stage: dev
  script:
    - cd dev
    - bundle install --path "$TMPDIR/vendor/bundle"
    - rake dev

promote-to-stg:
  stage: promote-to-stg
  script:
    - export DATESTAMP="$(date -u '+%Y%m%d%H%M%S')"  # e.g. 20170603220542. Uses UTC.
    - echo "$DATESTAMP"  # So it's visible in the log
    - git tag "deploy-stg-$DATESTAMP"
    # gitlab is not clever enough to clean up an added remote and git complains
    # if we add a remote that already exists.
    - git remote | grep -q "^origin-rw" || git remote add origin-rw git@github.com:gpii-ops/gpii-terraform-live
    - git push --tags origin-rw

stg:
  stage: stg
  script:
    - cd stg
    - rake stg

stages:
  - setup
  - dev
  - promote-to-stg
  - stg

setup:
  stage: setup
  script:
    - terraform -version
    - terragrunt -version
    - kubectl version --client
    - kops version
    - aws --version
    - jq --version
    - ruby --version
    - bundle version
    - rake --version

dev:
  stage: dev
  script:
    - cd dev
    - bundle install --path "vendor/bundle"
    - rake dev

promote-to-stg:
  stage: promote-to-stg
  script:
    - export DATESTAMP="$(date -u '+%Y%m%d%H%M%S')"  # e.g. 20170603220542. Uses UTC.
    - echo "$DATESTAMP"  # So it's visible in the log
    - git tag "deploy-stg-$DATESTAMP"
    # gitlab is not clever enough to clean up an added remote and git complains
    # if we add a remote that already exists.
    - git remote | grep -q "^origin-rw" || git remote add origin-rw git@github.com:gpii-ops/gpii-terraform-live
    - git push --tags origin-rw

stg:
  stage: stg
  script:
    - cd stg
    - rake stg

Remove TMPDIR handling (rakefiles take care of it).
Remove TMPDIR handling (rakefiles take care of it).
