Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example: BitBucket Pipelines vs fortrabbit
image: php:7.1.1
pipelines:
default:
- step:
script:
- apt-get update && apt-get install -y unzip git rsync
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer install
- php deploy.php
<?php
$frApp = "the-app-name";
$frRegion = "eu2"; // or "us1"
$frRepoUrl = sprintf('%s@deploy.%s.frbit.com:%s.git', $frApp, $frRegion, $frApp);
$frRepoDir = sprintf('%s/fr-repo', sys_get_temp_dir());
$gitAuthorEmail = "deploy@bitbucket.com";
$gitAuthorName = "BitBucket";
$curDir = getcwd();
// Simulate changes, which are not in the Git repo, but generated in build
`date > the-current-date`;
// Get commit so it can be forwarded
echo "# Gathering commit message\n";
$lastCommitMessage =`git log -1 --pretty=%B`;
$lastCommitMessage = preg_replace('/["\'\n\r]/', '', $lastCommitMessage);
echo " > $lastCommitMessage\n\n";
// Update SSH config:
// StrictHostKeyChecking=no is not a secure setting, but "yes" or "ask" will
// require read from /dev/tty, which is not available.
// Should be replaced by adding the fingerprint to ~/.ssh/known_hosts instead.
echo "# Updating SSH config\n";
`grep -q PreferredAuthentications ~/.ssh/config || echo "PreferredAuthentications publickey" >> ~/.ssh/config`;
`grep -q StrictHostKeyChecking ~/.ssh/config || echo "StrictHostKeyChecking no" >> ~/.ssh/config`;
//`grep -q LogLevel ~/.ssh/config || echo "LogLevel DEBUG3" >> ~/.ssh/config`;
echo " > Done\n\n";
// Git author must be set, or STDIN is again required
echo "# Init git\n";
`git config --global user.email "$gitAuthorEmail"`;
`git config --global user.name "$gitAuthorName"`;
echo " > Done\n\n";
// make sure fortrabbit repo is cloned - or pulled
if (file_exists("$frRepoDir/.git")) {
chdir($frRepoDir);
echo "# Updating \"$frRepoUrl\" repo in \"$frRepoDir\"\n";
echo `git pull`;
} else {
echo "# Cloning \"$frRepoUrl\" repo into \"$frRepoDir\"\n";
chdir(dirname($frRepoDir));
$command = "git clone \"$frRepoUrl\" \"$frRepoDir\"";
echo `git clone "$frRepoUrl" "$frRepoDir"`;
}
echo " > Done\n\n";
// Abort in case previous clone failed
if (!file_exists("$frRepoDir/.git")) {
error_log("Could not clone/update repo from fortrabbit");
exit(1);
}
// Sync all changed files, including those which were generated during build
echo "# Syncing changes\n";
echo `rsync -avC --delete-after --exclude=/vendor/ "$curDir"/ "$frRepoDir"/`;
echo " > Done\n\n";
// Commit & push everything to fortrabbit
echo "# Deploying changes\n";
chdir($frRepoDir);
echo `git add -Av`;
echo `git commit -am "$lastCommitMessage"`;
echo `git push origin master`;
echo " > Done\n\n";
@svmotha

This comment has been minimized.

Copy link

commented Sep 14, 2017

Thank you for this. It was very useful.

@millman2394

This comment has been minimized.

Copy link

commented Apr 29, 2019

I receive this error during a pipeline build:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for craftcms/cms 3.1.24 -> satisfiable by craftcms/cms[3.1.24].
    - craftcms/cms 3.1.24 requires ext-zip * -> the requested PHP extension zip is missing from your system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.