Last active
January 19, 2024 10:46
-
-
Save Bhavya8181/e394913814e2da06ab15afc68e5278a3 to your computer and use it in GitHub Desktop.
CI/CD Pipeline with Laravel & Bitbucket for Setup new Laravel Project
This file contains 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
Ref Link : https://support.atlassian.com/bitbucket-cloud/docs/laravel-with-bitbucket-pipelines/ | |
========================================================================================================== | |
Enable Pipeline in BitBucket | |
Create bitbucket-pipelines.yml file and paste below code (code will change base on perticular language) | |
# 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.4 | |
pipelines: | |
branches: | |
main: | |
- step: | |
name: Pulling code to server | |
# caches: | |
# - composer | |
script: | |
- apt-get update && apt-get install -y unzip | |
#- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | |
#- composer install | |
- apt-get install openssh-server -y | |
#- echo $REPO_ORIGIN_URL | |
#- echo $REPO_GIT_USER_TOKEN | |
#- echo $REPO_GIT_USERNAME | |
#- echo $DEPLOY_USER_J | |
#- echo $DEPLOY_HOST_J | |
- echo $PROJECT_FOLDER_PATH | |
- ssh $DEPLOY_USER_J@$DEPLOY_HOST_J 'bash -s' < execute.sh $REPO_ORIGIN_URL $PROJECT_FOLDER_PATH | |
Note( to login server without password you must be add your bitbuket ssh key into server autherised key) | |
Add yout bitbuket ssh key into server usnign below command | |
login to server after run below command | |
sudo nano ~/.ssh/authorized_keys | |
and add your bitbuket public ssh key which is located to bitbuket/yourrepostiry/repository_seeting/sshkey |
This file contains 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
When Newly Project Setup Time (Add .env file with data configuration & .htaccess file in root of project after clone) | |
============================= | |
cd /var/www/html | |
# git clone https://Bhavya_Neuramonks:ATBBSJZtHPZMaDhfcmeN8uXNvYf869CB452D@bitbucket.org/bhavyaneuramonks/test-repository.git | |
cd test-repository | |
sudo chmod -R 777 storage | |
sudo chmod -R 777 public/assets | |
sudo chmod -R 777 bootstrap/cache | |
git fetch | |
git checkout main | |
git pull https://Bhavya_Neuramonks:ATBBSJZtHPZMaDhfcmeN8uXNvYf869CB452D@bitbucket.org/bhavyaneuramonks/test-repository.git | |
composer install | |
php artisan config:cache | |
php artisan migrate | |
php artisan storage:link | |
php artisan db:seed --class=CreateAdminUserSeeder | |
exit | |
Every git Push time Auto run command | |
======================================= | |
echo "Folder path -> " . $2 | |
cd $2 | |
#git fetch | |
#git checkout main | |
#echo "pulling from -> " . $1 | |
git pull $1 | |
composer install | |
php artisan config:cache | |
php artisan migrate | |
php artisan storage:link | |
chmod -R 777 storage/ | |
exit |
This file contains 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
Note (We Use variable Insted of actual value you can store your variable in your pipeline ) | |
Ref Link To Store Variable: https://docs.veracode.com/r/Set_a_Bitbucket_Repository_Environment_Variable | |
Test YML Editor: https://bitbucket-pipelines.atlassian.io/validator | |
========================================================================================================== | |
1. First Enable Your repository Pipeline | |
2. Create varibles into bitbucket repo settings | |
REPO_ORIGIN_URL -> url to git pull with username and password | |
https://Bhavya_Neuramonks:ATBBSJZtHPZMaDhfcmeN8uXNvYf869CB452D@bitbucket.org/bhavyaneuramonks/test-repository.git | |
DEPLOY_USER_J -> server username | |
root | |
DEPLOY_HOST_J -> server ip address to connect | |
194.163.165.59 | |
PROJECT_FOLDER_PATH -> navigate path to take pull | |
/var/www/html/test-repository |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment