Skip to content

Commit

Permalink
Merge pull request #1060 from t-richard/revamp-websites-docs
Browse files Browse the repository at this point in the history
[DOCS] Revamp websites docs to use Lift
  • Loading branch information
mnapoli authored Oct 24, 2021
2 parents 7e0d1f1 + 94e9fd3 commit b7ad134
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 291 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ This matrix will be updated as Bref and AWS services evolve over time.

- **Website**

Websites can run on AWS Lambda. Assets can be served via AWS S3. That requires a bit of setup but this is documented in the ["Websites" documentation](/docs/websites.md). Performance is as good as any server.
Websites can run on AWS Lambda. Assets can be stored in S3 and served via Cloudfront. This is documented in the ["Websites" documentation](/docs/websites.md). Performance is as good as any server.

- **Legacy application**

Expand Down
Binary file removed docs/cloudfront.png
Binary file not shown.
30 changes: 4 additions & 26 deletions docs/environment/custom-domains.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,9 @@ After waiting for the DNS change to propagate (sometimes up to several hours) yo

## Custom domains for static files on S3

Some applications serve static files hosted on AWS S3. You can read the [Websites](/docs/websites.md#hosting-static-files-with-s3) documentation to learn more.
Some applications serve static files hosted on AWS S3. You can read the [Websites](/docs/websites.md) documentation to learn more.

The S3 bucket can be accessed at this URL: `https://<bucket>.s3.amazonaws.com/` (supports both HTTP and HTTPS).
If you want to host a fully static website with HTML files or a Single Page Application (eg. built with Vue, React or Angular)
you may be interested in [the Static Website construct of the Lift plugin](https://github.com/getlift/lift/blob/master/docs/static-website.md).

To use a custom domain for a S3 static website the process lies in 2 steps:

- name the S3 bucket like the wanted domain name

For example for the http://www.example.com website, the S3 bucket has to be named `www.example.com`
- point the domain to the S3 URL via DNS

In our example the DNS entry to create would be a CNAME for `www.example.com` pointing to `www.example.com.s3.amazonaws.com`

### Static websites

If you are hosting a full static website with HTML files ([per this documentation](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html)), the URLs to use will be different:

```bash
http://<bucket>.s3-website-<region>.amazonaws.com/
# or
http://<bucket>.s3-website.<region>.amazonaws.com/
```

In that case you need to use the domains above for the CNAME.

Note that the URL is **HTTP-only** and [depends on the region](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints).

To add HTTPS to your website for free it is possible to use a CDN like [CloudFlare](https://cloudflare.com/) (simplest) or [AWS CloudFront](/docs/websites.md#serving-php-and-static-files-via-cloudfront).
This allows to configure custom domains, root domain to `www` redirects and more. Check out [the official documentation](https://github.com/getlift/lift/blob/master/docs/static-website.md) for more details.
52 changes: 45 additions & 7 deletions docs/frameworks/laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,59 @@ For more details follow [the "Console" guide](/docs/runtimes/console.md).

## Assets

To deploy Laravel websites, we need assets to be served by AWS S3. Setting up the S3 bucket is already explained in the [websites documentation](../websites.md#hosting-static-files-with-s3). This section provides additional instructions specific to Laravel Mix.
To deploy Laravel websites, assets need to be served from AWS S3. The easiest approach is to use the
[Server-side website construct of the Lift plugin](https://github.com/getlift/lift/blob/master/docs/server-side-website.md).

First, you can compile assets for production in the `public` directory, then synchronize that directory to a S3 bucket:
This will deploy a Cloudfront distribution that will act as a proxy: it will serve
static files directly from S3 and will forward everything else to Lambda. This is very close
to how traditional web servers like Apache or Nginx work, which means your application doesn't need to change!
For more details, see [the offical documentation](https://github.com/getlift/lift/blob/master/docs/server-side-website.md#how-it-works).

First install the plugin

```bash
npm run prod
aws s3 sync public/ s3://<bucket-name>/ --delete --exclude index.php
serverless plugin install -n serverless-lift
```

Then, the assets need to be included from S3. In the production `.env` file you can now set that variable:
Then add this configuration to your `serverless.yml` file.

```dotenv
MIX_ASSET_URL=https://<bucket-name>.s3.<region>.amazonaws.com
```yaml
...
service: laravel

provider:
...

plugins:
- ./vendor/bref/bref
- serverless-lift

functions:
...

constructs:
website:
type: server-side-website
assets:
'/js/*': public/js
'/css/*': public/css
'/favicon.ico': public/favicon.ico
'/robots.txt': public/robots.txt
# add here any file or directory that needs to be served from S3
```

Before deploying, compile your assets using Laravel Mix.

```bash
npm run prod
```

Now deploy your website using `serverless deploy`. Lift will create all required resources and take care of
uploading your assets to S3 automatically.

For more details, see the [Websites section](/docs/websites.md) of this documentation
and the official [Lift documentation](https://github.com/getlift/lift/blob/master/docs/server-side-website.md).

### Assets in templates

Assets referenced in templates should be via the `asset()` helper:
Expand Down
5 changes: 4 additions & 1 deletion docs/frameworks/symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ in `trusted_proxies`.

## Assets

To deploy Symfony websites, assets need to be served from AWS S3. The easiest solution to do this is to use the
To deploy Symfony websites, assets need to be served from AWS S3. The easiest approach is to use the
[Server-side website construct of the Lift plugin](https://github.com/getlift/lift/blob/master/docs/server-side-website.md).

This will deploy a Cloudfront distribution that will act as a proxy: it will serve
Expand Down Expand Up @@ -202,6 +202,9 @@ upload all specified files and directories to the bucket.

> If you are not using Flex, update the `serverless.yml` file to exclude assets from the deployment ([see the recipe](https://github.com/symfony/recipes-contrib/blob/master/bref/symfony-bridge/0.1/serverless.yaml#L35))

For more details, see the [Websites section](/docs/websites.md) of this documentation
and the official [Lift documentation](https://github.com/getlift/lift/blob/master/docs/server-side-website.md).

### Assets in templates

For the above configuration to work, assets must be referenced in templates via the `asset()` helper as [recommended by Symfony](https://symfony.com/doc/current/templates.html#linking-to-css-javascript-and-image-assets):
Expand Down
Binary file removed docs/web-apps/edge-deployment.png
Binary file not shown.
Loading

0 comments on commit b7ad134

Please sign in to comment.