---
kind: pipeline
type: docker
name: Build

steps:
- name: build_release
  image: plugins/docker
  commands:
  - sleep 5
  - docker build -t docker.pbiernat.dev/nginx-php .
  - docker images | grep nginx-php
  when:
    event: tag
  volumes:
  - name: docker-sock
    path: /var/run

- name: publish_release
  image: plugins/docker
  environment:
    DOCKER_USERNAME:
      from_secret: registry_username
    DOCKER_PASSWORD:
      from_secret: registry_password
  commands:
  - sleep 5
#  - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
#  - docker push docker.pbiernat.dev/nginx-php
  when:
    event: tag
  volumes:
  - name: docker-sock
    path: /var/run

- name: build_develop
  image: plugins/docker
  commands:
  - sleep 5
  #- env
  - ./scripts/drone-build.sh
  when:
    branch: develop
    event: 
    - push
  volumes:
  - name: docker-sock
    path: /var/run

- name: publish_develop
  image: plugins/docker
#  privileged: true
  environment:
    DOCKER_USERNAME:
      from_secret: registry_username
    DOCKER_PASSWORD:
      from_secret: registry_password
  commands:
  - sleep 5
#  - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
#  - docker push docker.pbiernat.dev/nginx-php:dev
  - ./scripts/drone-publish.sh
  when:
    branch: develop
    event:
    - push
  volumes:
  - name: docker-sock
    path: /var/run

- name: build_feature
  image: plugins/docker
  commands:
  - env
  - sleep 5
  #- docker build -t docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH .
  #- docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:${CI_COMMIT_BRANCH}
  - ./scripts/drone-build.sh
  when:
    branch:
    - feature_*
    - develop
    event:
    - push
    - pull_request
  volumes:
  - name: docker-sock
    path: /var/run

- name: publish_feature
  image: plugins/docker
#  privileged: true
  environment:
    DOCKER_USERNAME:
      from_secret: registry_username
    DOCKER_PASSWORD:
      from_secret: registry_password
  commands:
#  - env
  - sleep 5
  #- docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
  #- docker push docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH
  - ./scripts/drone-publish.sh
  when:
    branch: develop
    event:
    - pull_request
  volumes:
  - name: docker-sock
    path: /var/run

services:
- name: docker
  image: docker:dind
  privileged: true
  volumes:
  - name: docker-sock
    path: /var/run

volumes:
- name: docker-sock
  temp: {}