Last active
October 2, 2023 18:58
-
-
Save developerinusa/c1c57a86eb658bf5561e1170724ebe8b to your computer and use it in GitHub Desktop.
bitbucket-pipelines.yml config for laravel multiple (test-staging-prod) environments
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
#use bitbucket development variables where you see in the yaml script ---> ${VARIABLE} or $VARIABLE | |
prepare-docker-image-for-laravel: &prepare-docker-image-for-laravel | |
name: prepare docker image | |
artifacts: | |
- vendor/** | |
- composer | |
#services: | |
# - mysql | |
script: | |
- apt-get update && apt-get install -qy git curl libmcrypt-dev default-mysql-client zip unzip libzip-dev libpng-dev libonig-dev libxml2-dev | |
#- yes | pecl install mcrypt-1.0.1 | |
- docker-php-ext-install pdo_mysql zip gd | |
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | |
- composer install | |
#- ln -f -s .env.pipelines .env | |
#- php artisan migrate | |
caches: | |
- composer | |
definitions: | |
services: | |
mysql: | |
image: mysql:5.7 | |
environment: | |
MYSQL_DATABASE: 'homestead' | |
MYSQL_RANDOM_ROOT_PASSWORD: 'yes' | |
MYSQL_USER: 'homestead' | |
MYSQL_PASSWORD: 'secret' | |
npm-install-script: &npm-install-script | |
- export NODE_OPTIONS=--max_old_space_size=8192 | |
- npm install | |
- npm run $NPM_ENVIRONMENT | |
env-scrip: &env-script | |
- cp .env.example .env | |
- sed -i "s/^DB_HOST=.*/DB_HOST=$DB_HOST/" .env | |
- sed -i "s/^DB_USERNAME=.*/DB_USERNAME=$DB_USERNAME/" .env | |
- sed -i "s/^DB_DATABASE=.*/DB_DATABASE=$DB_DATABASE/" .env | |
- sed -i "s/^DB_PASSWORD=.*/DB_PASSWORD=$DB_PASSWORD/" .env | |
- sed -i "s/^APP_URL=.*/APP_URL=${APP_URL}/" .env | |
- sed -i "s/^APP_KEY=.*/APP_KEY=${APP_KEY}/" .env | |
- sed -i "s/^APP_DEBUG=.*/APP_DEBUG=$APP_DEBUG/" .env | |
- sed -i "s/^LOG_CHANNEL=.*/LOG_CHANNEL=daily/" .env | |
- sed -i "s/^LOG_LEVEL=.*/LOG_LEVEL=error/" .env | |
- sed -i "s/^SENTRY_LARAVEL_DSN=.*/SENTRY_LARAVEL_DSN=${SENTRY_LARAVEL_DSN}/" .env | |
- cat .env | |
deploy: &deploy | |
- pipe: atlassian/rsync-deploy:0.5.0 | |
variables: | |
REMOTE_PATH: $REMOTE_PATH | |
LOCAL_PATH: '${BITBUCKET_CLONE_DIR}/' | |
USER: $SSH_USER | |
SSH_USER: $SSH_USER | |
SERVER: $SSH_SERVER | |
EXTRA_ARGS: '--quiet --include .env --exclude .gitattributes --exclude .git/ --exclude .bitbucket/ --exclude .env.pipelines' | |
- pipe: atlassian/ssh-run:0.4.2 | |
variables: | |
SSH_USER: $SSH_USER | |
SERVER: $SSH_SERVER | |
MODE: 'command' | |
COMMAND: "cd $REMOTE_PATH && php artisan optimize:clear && php artisan migrate && chmod u+x entrypoint.sh && ./entrypoint.sh" | |
npm-install-prod: &npm-install-prod | |
name: npm install | |
image: node:12.14 | |
deployment: prod-npm | |
script: *npm-install-script | |
artifacts: | |
- node_modules/ | |
- public/** | |
caches: | |
- node | |
npm-install-staging: &npm-install-staging | |
name: npm install | |
image: node:12.14 | |
deployment: staging-npm | |
script: *npm-install-script | |
artifacts: | |
- node_modules/ | |
- public/** | |
caches: | |
- node | |
npm-install-test: &npm-install-test | |
name: npm install | |
image: node:12.14 | |
deployment: test-npm | |
script: *npm-install-script | |
artifacts: | |
- node_modules/ | |
- public/** | |
caches: | |
- node | |
deploy-to-test-server: &deploy-to-test-server | |
name: deploy app to test-server | |
deployment: test-server-ssh | |
artifacts: | |
- storage/** | |
- public/** | |
script: *deploy | |
deploy-to-prod-server: &deploy-to-prod-server | |
name: deploy app to prod-server | |
deployment: prod-server-ssh | |
artifacts: | |
- storage/** | |
- public/** | |
script: *deploy | |
deploy-to-staging-server: &deploy-to-staging-server | |
name: deploy app to stage-server | |
deployment: staging-server-ssh | |
artifacts: | |
- storage/** | |
- public/** | |
script: *deploy | |
image: php:8.1-fpm | |
pipelines: | |
branches: | |
test: | |
- step: *prepare-docker-image-for-laravel | |
- step: | |
name: configure environment | |
deployment: test-env-file | |
artifacts: | |
- .env | |
script: *env-script | |
- step: *npm-install-test | |
- step: *deploy-to-test-server | |
staging: | |
- step: *prepare-docker-image-for-laravel | |
- step: | |
name: configure environment | |
deployment: staging-env-file | |
artifacts: | |
- .env | |
script: *env-script | |
- step: *npm-install-staging | |
- step: *deploy-to-staging-server | |
prod: | |
- step: *prepare-docker-image-for-laravel | |
- step: | |
name: configure environment | |
deployment: prod-env-file | |
artifacts: | |
- .env | |
script: *env-script | |
- step: *npm-install-prod | |
- step: *deploy-to-prod-server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment