Skip to content

Instantly share code, notes, and snippets.

@juniorb2ss
Last active February 8, 2024 10:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save juniorb2ss/1c166d7743c65055e7fac4f323bb25d3 to your computer and use it in GitHub Desktop.
Save juniorb2ss/1c166d7743c65055e7fac4f323bb25d3 to your computer and use it in GitHub Desktop.
Bitbucket Pipeline Deploy Laravel to Elasticbeanstalk using parallel steps
image: atlassian/default-image:2
definitions:
services:
redis:
image: redis:3.2
memory: 512
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'homestead'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: 'homestead'
MYSQL_PASSWORD: 'secret'
steps:
- step: &composer
name: Composer & Migrations
image: php:7.2
caches:
- composer
script:
- php -v
- apt-get update
# Installing first the libraries necessary to configure and install gd
- apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
# Now we can configure and install the extension
- docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
- docker-php-ext-install -j$(nproc) gd
- docker-php-ext-install pcntl
- docker-php-ext-install zip
- docker-php-ext-install pdo_mysql
- docker-php-ext-install exif
- docker-php-ext-install bcmath
- php -i | grep 'GD\|ImageMagick'
- php -i | grep 'pcntl'
- php -i | grep 'zip'
- php -i | grep 'pdo_mysql'
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer -V
- php -r "file_exists('.env') || copy('.env.example', '.env');"
- composer install
# library to check code security
- composer outdated
- php artisan key:generate
- php artisan migrate
artifacts:
- .env
- vendor/**
services:
- mysql
- redis
- docker
- step: &test
name: Testing Application
image: php:7.2
script:
#- sed -i 's/DB_HOST=127.0.0.1/DB_HOST=mysql/g' .env
- cat .env
- vendor/bin/phpunit
services:
- mysql
- redis
- docker
- step: &build
name: Building Application
image: atlassian/default-image:2
script:
# zipping application and removing .env file
- zip -r application.zip . -x .env
artifacts:
- application.zip
services:
- docker
- step: &deploy
name: Deploy to Elasticbeanstalk
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.2.5
variables:
ENVIRONMENT_NAME: $ENVIRONMENT_NAME
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: "us-east-1"
S3_BUCKET: $S3_BUCKET
APPLICATION_NAME: $APPLICATION_NAME
ZIP_FILE: "application.zip"
VERSION_LABEL: "$BITBUCKET_COMMIT-$BITBUCKET_BUILD_NUMBER"
services:
- docker
- step: &push-bugsnag
name: Sending Release Bugsnag
script:
- pipe: bugsnag-integrations/bugsnag-build-report:0.2.2
variables:
API_KEY: $BUGSNAG_API_KEY
RELEASE_STAGE: $BITBUCKET_BRANCH
APP_VERSION: $(cat .short-commit)
services:
- docker
- step: &short-commit
name: Short Commit
script:
- echo $(echo $BITBUCKET_COMMIT | cut -c1-7) > .short-commit
artifacts:
- .short-commit
push-staging: &push-staging
step:
<<: *deploy
deployment: staging
push-production: &push-production
step:
<<: *deploy
deployment: production
sentry-release: &sentry-release
step:
name: Sentry Release
image: getsentry/sentry-cli
script:
- sentry-cli releases -o "${SENTRY_ORG}" new -p "${SENTRY_PROJECT}" "$(cat .short-commit)"
- sentry-cli releases -o "${SENTRY_ORG}" set-commits --auto "$(cat .short-commit)"
sentry-deploy: &sentry-deploy
step:
name: Sentry Finalize Release & Deploy
image: getsentry/sentry-cli
script:
- sentry-cli releases -o "${SENTRY_ORG}" finalize "$(cat .short-commit)"
- sentry-cli releases -o "${SENTRY_ORG}" deploys "$(cat .short-commit)" new -e $BITBUCKET_BRANCH
security: &security
step:
name: security:checker
script:
- curl -sS https://get.symfony.com/cli/installer | bash
- export PATH="$HOME/.symfony/bin:$PATH"
- symfony security:check
pipelines:
default:
- <<: *security
custom:
security:
- <<: *security
test:
- step:
<<: *composer
- step:
<<: *test
deployment-production:
- parallel:
- step:
<<: *short-commit
- step:
<<: *composer
- <<: *security
- step:
<<: *test
- parallel:
- step:
<<: *build
- <<: *sentry-release
- <<: *push-production
- parallel:
- step:
<<: *push-bugsnag
- <<: *sentry-deploy
deployment-staging:
- parallel:
- step:
<<: *short-commit
- step:
<<: *composer
- <<: *security
- step:
<<: *test
- parallel:
- step:
<<: *build
- <<: *sentry-release
- <<: *push-staging
- parallel:
- step:
<<: *push-bugsnag
- <<: *sentry-deploy
branches:
staging:
- parallel:
- step:
<<: *short-commit
- step:
<<: *composer
- <<: *security
- step:
<<: *test
- parallel:
- step:
<<: *build
- <<: *sentry-release
- <<: *push-staging
- parallel:
- step:
<<: *push-bugsnag
- <<: *sentry-deploy
production:
- parallel:
- step:
<<: *short-commit
- step:
<<: *composer
- <<: *security
- step:
<<: *test
- parallel:
- step:
script:
- pipe: atlassian/slack-notify:0.2.3
variables:
WEBHOOK_URL: $SLACK_WEBHOOK_URL
MESSAGE: "New build generated in *HUBSEG*.\nCommit Hash: `$BITBUCKET_COMMIT`\nBranch: `$BITBUCKET_BRANCH`"
- step:
<<: *build
- <<: *sentry-release
- <<: *push-production
- parallel:
- step:
<<: *push-bugsnag
- <<: *sentry-deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment