The Bedrock Command Line Interface can be used to manage Bedrock projects and deployments.
curl -s https://install.bedrock.io | bash
bedrock create
Quick create:
bedrock create \
--domain seltzerbox.com \
--repository github.com/dominiek/seltzer-box \
seltzer-box
To use the bedrock cloud
commands, check the bedrock-core
Deployment README.md, which includes: gcloud setup, deployment and provisioning.
Provisioning will allow new infrastructure to be created on Google Cloud using Terraform. CLI commands will also let you deploy and control a Kubernetes cluster.
Bedrock uses GCP as it's standard cloud solution for hosting and deploying Bedrock projects. Projects are built using docker and deployed with kubernetes.
The bedrock cloud deploy
command supports posting message on a Slack channel when starting and finishing the deploy. This requires the following steps:
- Create a new Slack App at api.slack.com for your workspace
- Optional: Update your Slack with a nice Icon and description
- Create
incoming webhook
. Select this feature in the menu, and hitAdd New Webhook to Workspace
. It will ask you to select the Slack channel in your workspace to post messages to. - Copy the generated Webhook URL, which includes the api token
- Paste the Webhook URL in your project's deployment environment
config.json
(See Deployment README.md). Exampledeployment/environments/staging/config.json
(replace webhook value with your own Webhook URL):
{
"gcloud": {
"envName": "staging",
"bucketPrefix": "bedrock-foundation-staging",
"project": "bedrock-foundation-staging",
"computeZone": "us-east1-c",
"kubernetes": {
"clusterName": "cluster-2",
"nodePoolCount": 1,
"minNodeCount": 1,
"maxNodeCount": 3,
"machineType": "n2-standard-2"
},
"label": "app"
},
"slack": {
"webhook": "https://hooks.slack.com/services/xxxxxxxx/xxxxxxxx"
}
}
Each environment can use the same webhook for the same channel, or you can set up a different channel and webhook for each environment.
- Use
gcloud auth login
andgcloud auth application-default login
to login to the right Google account, orbedrock cloud login
- Use
bedrock cloud authorize staging
to get cluster credentials - If you've used
gcloud auth
with another account, rungcloud config set account <EMAIL>
orbedrock cloud account <EMAIL>
, then re-runbedrock cloud authorize
.
If you get this error when trying to deploy:
unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials
Then do the following
gcloud auth configure-docker
or
gcloud docker --authorize-only
The following commands will build a docker image locally:
bedrock cloud build
bedrock cloud deploy
There is also the option to build the image remotely using GCP Container Registry:
bedrock cloud build --remote
bedrock cloud deploy --remote
This may be advantageous as it requires less data to transfer (pushing a tarball of the source vs pushing up an entire docker image), also notably docker images take much longer to build on Apple Silicon as they must compile to x86
targets.
The CLI generate
command can be used to generate the following:
model
- model definitionsroutes
- API routesdocs
- documentationmodal
- modal dialogs for editing objects from anywherescreens
- basic CRUD screens (search/filter, detail page, etc)subscreens
- screens for associated models (for example a page forproducts
that belong to ashop
)
Running bedrock generate
can generate one or many of these resources. As the foundation for your generated code, models must be first created to allow generation of other resources so generating other resources will ask you to create a new model or load an existing one.
Generating a model requires creating a schema. Understanding Mongoose schema types will be helpful here. The schema definition can be edited or changed within the CLI, then choosing Build Schema
will continue on to generate other resources that are derived from it.
The generator makes a best effort to integrate generated code into your app, and on a fresh Bedrock codebase can even generate new resources without restarting the server. However as your code diverges it may require some manual tweaking to correctly integrate with your app.
As structured JSON data, models can safely be re-generated after manual changes but as a general rule, generated code is expected to diverge as it is modified. However if the code has not been manually changed then it is safe to re-run generators. Another strategy is to allow the generator to overwrite existing files and use git diff
to manually merge custom and generated code.
Client side code specifically is expected to diverge, however modal
dialogs benefit greatly from avoiding manual changes as editiable fields inside them can be re-generated after changes your model definition changes.
Use the help
command for more information on CLI commands:
bedrock help