|
| 1 | +import { Callout, Steps, Cards, Card } from 'nextra/components'; |
| 2 | +// Path relative to the copy in the `website/` folder |
| 3 | +import { LaravelIcon } from '../../components/icons/LaravelIcon'; |
| 4 | +import { SymfonyIcon } from '../../components/icons/SymfonyIcon'; |
| 5 | +import { NextSeo } from 'next-seo'; |
| 6 | + |
| 7 | +<NextSeo description="How to deploy Bref application using Bref Cloud." /> |
| 8 | + |
| 9 | +# Deployment |
| 10 | + |
| 11 | +Bref Cloud deploys application using Bref's `serverless.yml` file. |
| 12 | + |
| 13 | +If you haven't gotten started with Bref, follow the guide corresponding to your framework: |
| 14 | + |
| 15 | +<Cards num={2}> |
| 16 | + <Card icon={<LaravelIcon />} title="Get started with Laravel" arrow="true" href="/docs/laravel/getting-started" /> |
| 17 | + <Card icon={<SymfonyIcon />} title="Get started with Symfony" arrow="true" href="/docs/symfony/getting-started" /> |
| 18 | + <Card title="Get started with any PHP framework" arrow="true" href="/docs/default/getting-started" /> |
| 19 | +</Cards> |
| 20 | + |
| 21 | +The main difference with Bref Cloud is that you don't deploy by running `serverless deploy`. Instead, you deploy by running: |
| 22 | + |
| 23 | +```shell |
| 24 | +bref deploy |
| 25 | +``` |
| 26 | + |
| 27 | +(see [the Getting Started guide](./cloud-getting-started.mdx) to install the `bref` CLI) |
| 28 | + |
| 29 | +The benefits of deploying using Bref Cloud: |
| 30 | + |
| 31 | +- **Credentials**: You don't need to create AWS credentials or configure the `serverless` CLI, Bref Cloud handles this for you ([learn more](./cloud-security.mdx)). |
| 32 | +- **Deployment monitoring**: Bref Cloud provides a dashboard to view deployments of all your applications across all AWS accounts, regions, and environments. |
| 33 | +- **No need to install `serverless`**: Bref Cloud transparently installs and runs the `serverless` CLI. |
| 34 | +- **Better UX**: the `bref` CLI has minimal output with verbose mode that can be enabled in real time. |
| 35 | + |
| 36 | +When you run `bref deploy`, Bref Cloud runs the `serverless deploy` command for you in the background. |
| 37 | + |
| 38 | +## Differences between `bref` and `serverless` |
| 39 | + |
| 40 | +The `bref` CLI uses AWS credentials from AWS accounts connected in [Bref Cloud](https://bref.cloud/aws-accounts). That means that it will ignore AWS credentials configured on your machine. |
| 41 | + |
| 42 | +The `bref` CLI also uses the [open-source fork of Serverless Framework](https://github.com/oss-serverless/serverless), which is a fork of Serverless Framework v3, the last free and open-source version. This fork is maintained by Bref and ensures that the CLI is maintained and stable in the long run. |
| 43 | + |
| 44 | +Finally, the `bref` CLI uses "**environments**" instead of "**stages**". This is just a vocabulary change. That means that you should use the `--env` option instead of the `--stage` option: |
| 45 | + |
| 46 | +```shell |
| 47 | +bref deploy --env production |
| 48 | + |
| 49 | +# is equivalent to |
| 50 | +serverless deploy --stage production |
| 51 | +``` |
| 52 | + |
| 53 | +## Deploying with Bref Cloud |
| 54 | + |
| 55 | +To deploy an application using Bref Cloud, you need to add your Bref Cloud team to the `serverless.yml` file: |
| 56 | + |
| 57 | +```yaml |
| 58 | +service: my-app |
| 59 | +provider: |
| 60 | + name: aws |
| 61 | + # ... |
| 62 | + |
| 63 | +# Add these lines: |
| 64 | +bref: |
| 65 | + team: my-bref-cloud-team |
| 66 | +``` |
| 67 | +
|
| 68 | +(you can find your team name [in Bref Cloud](https://bref.cloud/app/create)) |
| 69 | +
|
| 70 | +Then, you can deploy using the `bref` CLI: |
| 71 | + |
| 72 | +```shell |
| 73 | +bref deploy |
| 74 | +
|
| 75 | +# or for a specific environment |
| 76 | +bref deploy --env production |
| 77 | +``` |
| 78 | + |
| 79 | +## Deploying from GitHub Actions |
| 80 | + |
| 81 | +You can also deploy your application using GitHub Actions. Here is an example workflow: |
| 82 | + |
| 83 | +```yaml |
| 84 | +name: Deploy |
| 85 | +
|
| 86 | +on: |
| 87 | + push: |
| 88 | + branches: [ main ] |
| 89 | +
|
| 90 | +jobs: |
| 91 | + deploy: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + timeout-minutes: 15 |
| 94 | + concurrency: deploy-prod # Avoid deploying concurrently |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v4 |
| 97 | +
|
| 98 | + - uses: actions/setup-node@v2 |
| 99 | + with: |
| 100 | + node-version: '18' |
| 101 | +
|
| 102 | + - name: Cache NPM dependencies |
| 103 | + uses: actions/cache@v4 |
| 104 | + with: |
| 105 | + path: ~/.npm # npm cache files are stored in `~/.npm` |
| 106 | + key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }} |
| 107 | + restore-keys: | |
| 108 | + ${{ runner.OS }}-node- |
| 109 | +
|
| 110 | + # You can remove this step if you don't have a `package.json` file |
| 111 | + - run: npm ci |
| 112 | + |
| 113 | + - name: Setup PHP |
| 114 | + uses: shivammathur/setup-php@v2 |
| 115 | + with: |
| 116 | + php-version: '8.2' |
| 117 | + coverage: none |
| 118 | + # Install the Bref CLI as a global tool |
| 119 | + tools: bref/cli |
| 120 | + |
| 121 | + - uses: ramsey/composer-install@v3 |
| 122 | + with: |
| 123 | + composer-options: '--optimize-autoloader --no-dev' |
| 124 | + |
| 125 | + - run: bref deploy --env=prod |
| 126 | + env: |
| 127 | + BREF_TOKEN: ${{ secrets.BREF_TOKEN }} |
| 128 | +``` |
| 129 | +
|
| 130 | +<Callout> |
| 131 | + Depending on your framework, you may need to add extra steps to build your application. For example with Laravel or Symfony you may want to build assets before deploying. |
| 132 | +</Callout> |
| 133 | +
|
| 134 | +Finally, you need to add the `BREF_TOKEN` secret to your repository: |
| 135 | + |
| 136 | +- [Create a "bot token" in your Bref Cloud team](https://bref.cloud/) |
| 137 | +- Go to your repository on GitHub |
| 138 | +- Click on "Settings" > "Secrets and variables" > "Actions" > "New repository secret" |
| 139 | +- Set the name to `BREF_TOKEN` and the value to the token you received after creating the bot token |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | +That's it! Your application will be deployed automatically when you push to the main branch. On the first deployment, the application will appear in the Bref Cloud dashboard. |
0 commit comments