Examples
Web and Database Application
In this example, we’ll walk through an example of enabling preview environments for a Python (Django) application that connects to a Postgres database. The sample repository can be found here.
preview.yaml
File Walkthrough
The preview.yaml
file to define both a Postgres database and a web application is as follows:
version: v1
resources:
- name: postgres
source:
name: postgresql
config:
postgresqlPassword: testing
- name: web
depends_on:
- postgres
source:
name: web
config:
build:
method: pack
builder: heroku/buildpacks:20
values:
container:
command: web
port: 8000
env:
normal:
POSTGRES_USERNAME: "{ .postgres.postgresqlUsername }"
POSTGRES_PASSWORD: "{ .postgres.postgresqlPassword }"
postgres.source
: by setting thesource.name
field topostgresql
, Porter will look for a supported addon calledpostgresql
.postgres.config
: thepostgresql
addon accepts thepostgresqlPassword
field to set the default Postgres password.web.source
: by setting thesource.name
field toweb
, Porter will deploy this resource as aweb
application.web.depends_on
: by setting thedepends_on
field to includepostgres
, Porter will wait for thepostgres
resource to be created before deploying the web application.web.config.build
: specifying theconfig.build.method
field aspack
instructs Porter to build this application using cloud-native buildpacks, and setting thebuilder
toheroku/buildpacks:20
means that this buildpack will be used.web.config.values
: here, we set common configuration settings, such as the start command, the port that the application runs on, and environment variables for the application. Also, note that configuration references an output variable from thepostgres
resource.