kind: pipeline
type: docker
name: build

steps:
- name: build
  image: docker/compose:latest
  environment:
    SMTP_PROXY_EMAIL:
      from_secret: SMTP_PROXY_EMAIL
    SMTP_RECIPIENT_EMAIL:
      from_secret: SMTP_RECIPIENT_EMAIL
    SMTP_HOST:
      from_secret: SMTP_HOST
    SMTP_PORT:
      from_secret: SMTP_PORT
    SMTP_USERNAME:
      from_secret: SMTP_USERNAME
    SMTP_PASSWORD:
      from_secret: SMTP_PASSWORD
    NEXT_PUBLIC_GOOGLE_APPOINTMENTS_LINK:
      from_secret: NEXT_PUBLIC_GOOGLE_APPOINTMENTS_LINK
    RECAPTCHA_SECRET_KEY:
      from_secret: RECAPTCHA_SECRET_KEY
    NEXT_PUBLIC_RECAPTCHA_SITE_KEY:
      from_secret: NEXT_PUBLIC_RECAPTCHA_SITE_KEY
  volumes:
  - name: docker_sock
    path: /var/run/docker.sock
  commands:
  - docker-compose -f ./docker-compose.drone.yaml
  - docker tag oonyeje-portfolio:${DRONE_COMMIT_SHA:0:7} gitea.bsidesolutions.net/oonyeje/oonyeje-portfolio:${DRONE_COMMIT_SHA:0:7}
- name: push-image
  image: docker/compose:latest
  environment:
    SMTP_PROXY_EMAIL:
      from_secret: SMTP_PROXY_EMAIL
    SMTP_RECIPIENT_EMAIL:
      from_secret: SMTP_RECIPIENT_EMAIL
    SMTP_HOST:
      from_secret: SMTP_HOST
    SMTP_PORT:
      from_secret: SMTP_PORT
    SMTP_USERNAME:
      from_secret: SMTP_USERNAME
    SMTP_PASSWORD:
      from_secret: SMTP_PASSWORD
    NEXT_PUBLIC_GOOGLE_APPOINTMENTS_LINK:
      from_secret: NEXT_PUBLIC_GOOGLE_APPOINTMENTS_LINK
    RECAPTCHA_SECRET_KEY:
      from_secret: RECAPTCHA_SECRET_KEY
    NEXT_PUBLIC_RECAPTCHA_SITE_KEY:
      from_secret: NEXT_PUBLIC_RECAPTCHA_SITE_KEY
    REGISTRY_USER:
      from_secret: DOCKER_USERNAME
    REGISTRY_PASS:
      from_secret: DOCKER_PASSWORD
  volumes:
  - name: docker_sock
    path: /var/run/docker.sock
  commands:
  - docker login gitea.bsidesolutions.net --username $REGISTRY_USER --password $REGISTRY_PASS
  - docker-compose -f ./docker-compose.drone.yaml push

# - name: deploy-staging
#   image: plugins/ansible:latest
#   settings:
#     playbook: ansible/playbook.staging.yml
#     galaxy: ansible/requirements.yml
#     inventory: ansible/inventory.yml
#     become_user: bside
#     user: bside
#     verbose: 4
#     become: true
#     list_tasks: true
#     list_hosts: true
#     private_key:
#       from_secret: STAGING_SERVER_PRIVATE_KEY
# trigger:
#   branch:
#   - master
#   - prod
#   - qa
#   - feature/*
#   event:
#   - push
#   - pull_request
# ---
# kind: pipeline
# type: exec
# name: staging-deploy

# platform:
#   os: linux
#   arch: amd64

# steps:
# - name: ansible-deploy
#   commands:
#   - ansible --version
#   - ansible-galaxy install --force --role-file ansible/requirements.yml -vvvv
#   - ansible-playbook --inventory ansible/inventory.yml --list-hosts ansible/playbook.staging.yml
# trigger:
#   branch:
#   - master
#   - prod
#   - qa
#   - feature/*
#   event:
#   - push
#   - pull_request

volumes:
  - name: docker_sock
    host:
      path: /var/run/docker.sock