kind: pipeline
name: default

workspace:
  base: /drone/garage

steps:
  - name: restore-cache
    image: meltwater/drone-cache:dev
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: cache_aws_access_key_id
      AWS_SECRET_ACCESS_KEY:
        from_secret: cache_aws_secret_access_key
    pull: true
    settings:
      restore: true
      archive_format: "gzip"
      bucket: drone-cache
      cache_key: '{{ .Repo.Name }}_{{ checksum "garage/Cargo.lock" }}_{{ arch }}_{{ os }}_gzip'
      region: garage
      mount:
        - 'target'
        - '/drone/cargo/registry/index'
        - '/drone/cargo/registry/cache'
        - '/drone/cargo/bin'
        - '/drone/cargo/git/db'
      path_style: true
      endpoint: https://garage.deuxfleurs.fr

  - name: build
    image: rust:buster
    environment:
      CARGO_HOME: /drone/cargo
    commands:
      - apt-get update
      - apt-get install --yes libsodium-dev
      - pwd
      - cargo build

  - name: cargo-test
    image: rust:buster
    environment:
      CARGO_HOME: /drone/cargo
    commands:
      - apt-get update
      - apt-get install --yes libsodium-dev
      - cargo test

  - name: rebuild-cache
    image: meltwater/drone-cache:dev
    environment:
      AWS_ACCESS_KEY_ID:
        from_secret: cache_aws_access_key_id
      AWS_SECRET_ACCESS_KEY:
        from_secret: cache_aws_secret_access_key
    pull: true
    settings:
      rebuild: true
      archive_format: "gzip"
      bucket: drone-cache
      cache_key: '{{ .Repo.Name }}_{{ checksum "garage/Cargo.lock" }}_{{ arch }}_{{ os }}_gzip'
      region: garage
      mount:
        - 'target'
        - '/drone/cargo/registry/index'
        - '/drone/cargo/registry/cache'
        - '/drone/cargo/git/db'
        - '/drone/cargo/bin'
      path_style: true
      endpoint: https://garage.deuxfleurs.fr

  - name: smoke-test
    image: rust:buster
    environment:
      CARGO_HOME: /drone/cargo
    commands:
      - apt-get update
      - apt-get install --yes libsodium-dev awscli python-pip
      - pip install s3cmd
      - ./script/test-smoke.sh || (cat /tmp/garage.log; false)