-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-1163 Create tutorial for using MongoDB with Bref #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
3646ef7
af95c04
2acc8fa
576ac73
46da485
5689613
c97aef9
16a7b31
c765d0c
2366c95
824fe18
883e951
125a427
4131fa3
6706469
99cebe4
1cace2d
f5adae8
6f8e963
9b089f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,7 @@ psalm.xml | |
| .phpbench/ | ||
| phpbench.json | ||
|
|
||
| # bref | ||
| .serverless/ | ||
|
|
||
| mongocryptd.pid | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "mongodb/bref-tutorial", | ||
| "type": "project", | ||
| "license": "MIT", | ||
| "repositories": [ | ||
| { | ||
| "type": "path", | ||
| "url": "../../..", | ||
| "options": { | ||
| "symlink": false | ||
| } | ||
| } | ||
| ], | ||
| "require": { | ||
| "bref/bref": "^2.1", | ||
| "bref/extra-php-extensions": "^1.4", | ||
| "mongodb/mongodb": "@dev" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| use MongoDB\Client; | ||
|
|
||
| require_once __DIR__ . '/vendor/autoload.php'; | ||
|
|
||
| $uri = getenv('MONGODB_URI') ?: throw new RuntimeException('The MONGODB_URI environment variable is not set'); | ||
| $client = new Client($uri); | ||
| $planets = $client->sample_guides->planets | ||
| ->find( | ||
| [], | ||
| ['sort' => ['orderFromSun' => 1]], | ||
| ); | ||
|
|
||
| ?> | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>MongoDB Planets</title> | ||
| </head> | ||
| <body> | ||
| <ul> | ||
| <?php foreach ($planets as $planet) : ?> | ||
| <li><?= $planet->name ?></li> | ||
| <?php endforeach ?> | ||
| </ul> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| service: app | ||
|
|
||
| provider: | ||
| name: aws | ||
| region: us-east-1 | ||
| environment: | ||
| MONGODB_URI: ${env:MONGODB_URI} | ||
|
|
||
| plugins: | ||
| - ./vendor/bref/bref | ||
| - ./vendor/bref/extra-php-extensions | ||
|
|
||
| functions: | ||
| api: | ||
| handler: index.php | ||
| description: '' | ||
| runtime: php-83-fpm | ||
| timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds) | ||
| events: | ||
| - httpApi: '*' | ||
| layers: | ||
| - ${bref-extra:mongodb-php-83} |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||||
| ============================== | ||||||||
| Deploy to AWS Lambda with Bref | ||||||||
| ============================== | ||||||||
|
|
||||||||
| .. default-domain:: mongodb | ||||||||
ccho-mongodb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
|
|
||||||||
| .. contents:: On this page | ||||||||
| :local: | ||||||||
| :backlinks: none | ||||||||
| :depth: 2 | ||||||||
| :class: singlecol | ||||||||
|
|
||||||||
| .. versionadded:: 1.17 | ||||||||
GromNaN marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
|
|
||||||||
| Overview | ||||||||
| -------- | ||||||||
|
|
||||||||
| `Bref <https://bref.sh>`_ allows to deploy serverless PHP applications on AWS Lambda. | ||||||||
| In this tutorial, you will deploy a simple PHP application with the MongoDB PHP extension, | ||||||||
| and connect to an Atlas cluster using AWS IAM authentication. | ||||||||
|
|
||||||||
| Prerequisites | ||||||||
| -------------- | ||||||||
|
|
||||||||
| Before you begin, you must install Bref on your machine. You can follow the | ||||||||
| `official documentation to setup Bref <https://bref.sh/docs/setup>`_. | ||||||||
|
|
||||||||
| Install the MongoDB extension | ||||||||
| ----------------------------- | ||||||||
|
|
||||||||
| By default, the bref layer is compiled with PHP and a few extensions. Additional extensions | ||||||||
ccho-mongodb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| are provided in additional layers. | ||||||||
|
|
||||||||
| Start by creating a new directory for your project and install the required MongoDB | ||||||||
| and Bref dependencies. This project will be a bare minimum PHP web application that | ||||||||
| connects to a MongoDB cluster. | ||||||||
|
||||||||
| and Bref dependencies. This project will be a bare minimum PHP web application that | |
| connects to a MongoDB cluster. | |
| and Bref dependencies by running the following commands: |
ccho-mongodb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ccho-mongodb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ccho-mongodb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
jmikola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ccho-mongodb marked this conversation as resolved.
Show resolved
Hide resolved
ccho-mongodb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ccho-mongodb: Is this the correct prefix?
The intended URL is https://www.mongodb.com/docs/atlas/sample-data/, but conf.py in mongodb/docs-php-library suggests this will be "http://docs.mongodb.org/manual%s".
Now that I'm thinking about it, that pattern looks incorrect since all docs should be pointing to a mongodb.com domain. There's also the omission of "https".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I got it wrong. The prefix should be added. Maybe added to this standing PR: mongodb/docs-php-library#57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to full url links for the time being.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the extlinks entry may override the Snooty role. The Docs Platform team can probably confirm/deny this.
For example, docs-java doesn't have a conf.py file and therefore no extlinks, but uses the :manual: role:
https://github.com/mongodb/docs-java/blob/612975d4e0a2b550a9eb486b75558afb6ee7c55b/source/usage-examples/watch.txt#L181-L183
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I asked about this in Slack and will revise mongodb/docs-php-library#57 based on the response.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue:
This seems to be missing punctuation.
If this is meant to be the title of a step, maybe this tutorial can be formatted as steps.
Here's an example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mongodb/dbx-php What's your opinion on the formatting of this tutorial? It's actually steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections if you feel it's worth the effort.
Please make sure that formatting doesn't clash with "AWS Credentials", which has a numbered list within. I'm not expecting any issue nesting a list within the RST step syntax -- just a request to confirm the rendered output looks presentable.
Edit: looking at the Kafka tutorial, I consider it less useful that the steps aren't incorporated into the "On this page" navigation. Given that, I'd lean toward no changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think skipping steps formatting is fine and more efficient with time. The issue I was focusing on was missing punctuation. Perhaps it could be something to experiment with in a future PR!
ccho-mongodb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
GromNaN marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ccho-mongodb: Intended link here is https://www.mongodb.com/docs/atlas/security/set-up-unified-aws-access/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use the :atlas: role unless it's overridden by extlinks:
https://github.com/mongodb/snooty-parser/blob/main/snooty/rstspec.toml#L1290-L1292
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use the :atlas: role unless it's overridden by extlinks:
Does the very existence of extlinks in conf.py prevent us from using any of the roles defined in main/snooty/rstspec.toml?
mongodb/docs-php-library#57 was going to introduce atlas to extlinks, but it's presently not there.
As I mentioned in Slack, we'd need a custom role for :php: to link to PHP.net pages. I'm not a bit worried that reducing conf.py to
extlinks = {
'php': ('https://php.net/%s', '')
}
...might mean we lose access to :manual: as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard my last comment. @schmalliso confirmed that conf.py is ignored by Snooty. All of the roles we need are already defined in main/snooty/rstspec.toml (including :php:).
@GromNaN: I'm not sure why :atlas: isn't working. Perhaps there's some other configuration where specific roles from rstspec.toml need to be enabled for a project? This seems like a question for #ask-docs-platform.

Uh oh!
There was an error while loading. Please reload this page.