Last active
October 17, 2019 21:12
-
-
Save ukautz/4f3219c3eb5d97fbd018027dca4b8808 to your computer and use it in GitHub Desktop.
Example: BitBucket Pipelines vs fortrabbit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = "[email protected]"; | |
$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"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this. It was very useful.