# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: php:7.1.29

pipelines:
  default:
    - step:
        name: Deploy to test
        deployment: test
        # trigger: manual  # Uncomment to make this a manual deployment.
        script:
          - pipe: atlassian/scp-deploy:0.3.12
            variables:
              USER: $USER
              SERVER: $SERVER
              REMOTE_PATH: $TMP_FOLDER
              LOCAL_PATH: "${BITBUCKET_CLONE_DIR}/*"
              SSH_KEY: $MY_SSH_KEY
              DEBUG: "true"
              EXTRA_ARGS: "-o ServerAliveInterval=10"
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: "find $TMP_FOLDER -type d -print0 | xargs -0 chmod 775"
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: "find $TMP_FOLDER -type f -print0 | xargs -0 chmod 664"
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: "find $TMP_FOLDER/images -type d -print0 | xargs -0 chmod 777"
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: 'find $TMP_FOLDER -type f -name "*.php" -print0 | xargs -0 chmod 775'
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: "chmod 777 $TMP_FOLDER/system/user/cache"
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: "chmod 776 $TMP_FOLDER/system/user/config/config.php"
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: "sudo cp -Rp $TMP_FOLDER/* $TARGET_FOLDER"
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $USER
              SERVER:  $SERVER
              COMMAND: "sudo chown -R nginx:nginx $TARGET_FOLDER"
