|
- pipeline: "Build and deploy to [environment]" |
|
trigger_mode: "MANUAL" |
|
ref_name: "develop" |
|
actions: |
|
- action: "Init Atomic Deployment" |
|
type: "SSH_COMMAND" |
|
working_directory: "${remote_path}/" |
|
login: "${user}" |
|
host: "${host}" |
|
port: "22" |
|
env_key: "id_rsa" |
|
authentication_mode: "ENV_KEY" |
|
commands: |
|
- "if [ ! -d \"${remote_path}\" ];" |
|
- "then" |
|
- "echo \"ERROR: Remote path ${remote_path} does not exist.\"" |
|
- "exit 1" |
|
- "fi" |
|
- "mkdir -p deploy-cache" |
|
- "mkdir -p releases" |
|
- "mkdir -p _config" |
|
- "mkdir -p _storage" |
|
- "mkdir -p _data" |
|
run_as_script: true |
|
shell: "BASH" |
|
trigger_condition: "ALWAYS" |
|
- action: "Execute: yarn craft" |
|
type: "BUILD" |
|
docker_image_name: "library/node" |
|
docker_image_tag: "6" |
|
execute_commands: |
|
- "yarn" |
|
- "yarn craft" |
|
setup_commands: |
|
- "npm install -g gulp" |
|
trigger_condition_paths: |
|
- "/src" |
|
shell: "SH" |
|
trigger_condition: "ON_CHANGE_AT_PATH" |
|
- action: "Execute: composer install" |
|
type: "BUILD" |
|
docker_image_name: "library/php" |
|
docker_image_tag: "7.1" |
|
execute_commands: |
|
- "cd craft" |
|
- "composer install --ignore-platform-reqs --no-interaction --optimize-autoloader" |
|
setup_commands: |
|
- "apt-get update && apt-get install -y git zip" |
|
- "curl -L https://phar.phpunit.de/phpunit.phar -o /usr/local/bin/phpunit" |
|
- "chmod +x /usr/local/bin/phpunit" |
|
- "curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer" |
|
services: |
|
- type: "MYSQL" |
|
version: "5.7" |
|
persistent: true |
|
connection: |
|
host: "mysql" |
|
port: 3306 |
|
user: "root" |
|
password: "qwerty" |
|
shell: "SH" |
|
trigger_condition: "ALWAYS" |
|
- action: "Execute: backup_db.sh" |
|
type: "SSH_COMMAND" |
|
working_directory: "${remote_path}" |
|
login: "${user}" |
|
host: "${host}" |
|
port: "22" |
|
env_key: "id_rsa" |
|
authentication_mode: "ENV_KEY" |
|
commands: |
|
- "if [ -f \"releases/${execution.to_revision.revision}/scripts/backup_db.sh\" ];" |
|
- "then" |
|
- "echo \"Backup database\"" |
|
- "${remote_path}/releases/${execution.to_revision.revision}/scripts/backup_db.sh" |
|
- "fi" |
|
run_as_script: true |
|
shell: "BASH" |
|
trigger_condition: "ALWAYS" |
|
- action: "Rsync to Host" |
|
type: "RSYNC" |
|
local_path: "craft/" |
|
remote_path: "${remote_path}/deploy-cache" |
|
login: "${user}" |
|
host: "${host}" |
|
port: "22" |
|
env_key: "id_rsa" |
|
authentication_mode: "ENV_KEY" |
|
archive: true |
|
delete_extra_files: true |
|
compress: true |
|
deployment_excludes: |
|
- "/.git/" |
|
- "/node_modules/" |
|
- "/storage/" |
|
- "/${webroot}/cpresources/" |
|
- "/${webroot}/files/" |
|
- ".env" |
|
trigger_condition: "ALWAYS" |
|
- action: "Post-deployment action" |
|
type: "SSH_COMMAND" |
|
working_directory: "${remote_path}/" |
|
login: "${user}" |
|
password: "${ssh_password}" |
|
host: "${host}" |
|
port: "22" |
|
env_key: "id_rsa" |
|
authentication_mode: "ENV_KEY" |
|
commands: |
|
- "if [ -d \"releases/${execution.to_revision.revision}\" ] && [ \"${execution.refresh}\" = \"true\" ];" |
|
- "then" |
|
- "echo \"Removing: releases/${execution.to_revision.revision}\"" |
|
- "rm -rf releases/${execution.to_revision.revision};" |
|
- "fi" |
|
- "if [ ! -d \"releases/${execution.to_revision.revision}\" ];" |
|
- "then" |
|
- "echo \"Creating: releases/${execution.to_revision.revision}\"" |
|
- "cp -dR deploy-cache/ releases/${execution.to_revision.revision};" |
|
- "fi" |
|
- "echo \"Linking current to revision: ${execution.to_revision.revision}\"" |
|
- "rm -f current" |
|
- "ln -s releases/${execution.to_revision.revision} current" |
|
- "echo \"Creating: persistent directories\"" |
|
- "mkdir -p _storage/craft" |
|
- "mkdir -p _storage/cpresources" |
|
- "mkdir -p _data/files" |
|
- "echo \"Symlinking: persistent directories\"" |
|
- "ln -nfs ${remote_path}/_storage/craft ${remote_path}/releases/${execution.to_revision.revision}/storage" |
|
- "ln -nfs ${remote_path}/_storage/cpresources ${remote_path}/releases/${execution.to_revision.revision}/${webroot}/cpresources" |
|
- "ln -nfs ${remote_path}/_data/files ${remote_path}/releases/${execution.to_revision.revision}/${webroot}/files" |
|
- "echo \"Creating: config directories\"" |
|
- "mkdir -p _config" |
|
- "echo \"Symlinking: config files\"" |
|
- "ln -nfs ${remote_path}/_config/.env ${remote_path}/releases/${execution.to_revision.revision}/" |
|
- "ln -nfs ${remote_path}/_config/.env.php ${remote_path}/releases/${execution.to_revision.revision}/" |
|
- "ln -nfs ${remote_path}/_config/.env.sh ${remote_path}/releases/${execution.to_revision.revision}/scripts/" |
|
- "echo \"Removing old releases\"" |
|
- "cd releases && ls -t | tail -n +6 | xargs rm -rf" |
|
run_as_script: true |
|
shell: "SH" |
|
trigger_condition: "ALWAYS" |