-
Notifications
You must be signed in to change notification settings - Fork 166
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
Document project.toml #190
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
be0f0a4
Add Project Descriptor schema
dfreilich 0d38a89
Add project descriptor to env var tutorials
dfreilich 71ec273
Add Project Descriptor app-dev guide
dfreilich 0d2b3e3
Update content/docs/app-developer-guide/environment-variables.md
jromero 1ec3039
Merge branch 'main' into 165-project-toml
jromero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
content/docs/app-developer-guide/using-project-descriptor.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
+++ | ||
title="Using project.toml" | ||
weight=3 | ||
summary="Learn how to use a project.toml file to simplify configuring pack." | ||
+++ | ||
|
||
A `project descriptor` (alternatively referred to as a `project.toml` file) allows users to detail configuration for a | ||
repository. Users can, for instance, specify which buildpacks should be used when building the repository, what files | ||
should be included/excluded in the build, and [set environment variables at build time][descriptor-envs]. | ||
|
||
### Example | ||
We will use our [samples][samples] repo to demonstrate how to use a `project.toml` file. | ||
|
||
In the below example (`samples/apps/bash-script/project.toml`), we define project information (in this case, the `id` | ||
and human-readable `name` of the application we are building, and a `version`), and specify build information to pack. | ||
|
||
```toml | ||
[project] | ||
id = "io.buildpacks.bash-script" | ||
name = "Bash Script" | ||
version = "1.0.0" | ||
|
||
[build] | ||
exclude = [ | ||
"README.md", | ||
"bash-script-buildpack" | ||
] | ||
|
||
[[build.buildpacks]] | ||
uri = "bash-script-buildpack/" | ||
``` | ||
|
||
To use a `project.toml` file, simply: | ||
```shell script | ||
# build the app | ||
pack build sample-app \ | ||
--builder cnbs/sample-builder:bionic \ | ||
--path samples/apps/bash-script/ | ||
|
||
# run the app | ||
docker run sample-app | ||
``` | ||
|
||
If the descriptor is named `project.toml`, it will be read by `pack` automatically. Otherwise, you can run: | ||
```shell script | ||
pack build sample-app \ | ||
--builder cnbs/sample-builder:bionic \ | ||
--path samples/apps/bash-script/ \ | ||
--descriptor samples/apps/bash-script/<project-descriptor-file.toml> | ||
``` | ||
to specify an alternatively named `project descriptor`. | ||
|
||
### Specify Buildpacks and Envs | ||
As with other methods of [specifying buildpacks][specify-buildpacks], the only ones used are those that are specifically | ||
requested. Therefore, if we'd want to include another buildpack in our build (like a `hello-world` buildpack, to help us | ||
understand the environment), we would want to add it to our `project.toml`. | ||
|
||
> **Note:** Flags passed directly into `pack` have precedence over anything in the `project.toml`. Therefore, if we wanted | ||
> to use different buildpacks in the above case, we could also call `pack build ... --buildpack ...` | ||
|
||
Below is an expanded `project.toml`, with an additional buildpack and environment variable included. | ||
|
||
```toml | ||
[project] | ||
id = "io.buildpacks.bash-script" | ||
name = "Bash Script" | ||
version = "1.0.0" | ||
|
||
[build] | ||
exclude = [ | ||
"README.md", | ||
"bash-script-buildpack" | ||
] | ||
[[build.buildpacks]] | ||
uri = "../../buildpacks/hello-world/" | ||
|
||
|
||
[[build.buildpacks]] | ||
uri = "bash-script-buildpack/" | ||
|
||
[[build.env]] | ||
name='HELLO' | ||
value='WORLD' | ||
``` | ||
|
||
Paste the above `toml` as `new-project.toml` in the `samples/apps/bash-script/` directory, and simply: | ||
```shell script | ||
# build the app | ||
pack build sample-app \ | ||
--builder cnbs/sample-builder:bionic \ | ||
--path samples/apps/bash-script/ \ | ||
--descriptor samples/apps/bash-script/new-project.toml | ||
|
||
# run the app | ||
docker run sample-app | ||
``` | ||
|
||
### Further Reading | ||
For more about project descriptors, look at the [schema][descriptor-schema], as well as the [specification][spec]. | ||
|
||
[specify-buildpacks]: /docs/app-developer-guide/specific-buildpacks/ | ||
[descriptor-envs]: /docs/app-developer-guide/environment-variables/#using-project-descriptor | ||
[descriptor-schema]: /docs/reference/project-descriptor/ | ||
[samples]: https://github.com/buildpacks/samples | ||
[spec]: https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
+++ | ||
title="project.toml" | ||
summary="Schema of the project descriptor file." | ||
aliases=["/docs/reference/project-descriptor/"] | ||
+++ | ||
|
||
A project descriptor allows users to detail configuration for apps, services, functions and buildpacks. It should, by | ||
default, be named `project.toml`, though users can name it differently, and pass the filename to `pack` by calling | ||
```shell script | ||
$ pack build --descriptor <project-descriptor path> | ||
``` | ||
|
||
The schema for the `project descriptor` is: | ||
|
||
- #### `project` _(table, optional)_ | ||
A configuration table for a project. | ||
|
||
- **`id`** _(string, optional)_\ | ||
A machine readable identifier for the `project`. For example, `com.example.myservice`. | ||
|
||
- **`name`** _(string, optional)_\ | ||
A human readable identifier for the `project`. For example, `My Example Service`. | ||
|
||
- **`version`** _(string, optional)_\ | ||
The version of the `project`. | ||
|
||
- **`authors`** _(string list, optional)_\ | ||
The names and/or email addresses of the `project` authors. | ||
|
||
- **`documentation-url`** _(string, optional)_\ | ||
A link to the documentation for the `project`. | ||
|
||
- **`source-url`** _(string, optional)_\ | ||
A link to the source code of the `project`. | ||
|
||
- **`licenses`** _(list, optional)_\ | ||
A list of project licenses. Each must contain **at least one** of the following fields: | ||
|
||
- **`type`** _(string, optional)_\ | ||
The type of license. | ||
|
||
- **`uri`** _(string, optional)_\ | ||
If the project uses a nonstandard license, you may use `uri` to point to the license. | ||
|
||
- #### `build` _(table, optional)_ | ||
A list of specifications for build-time configuration of the project. | ||
|
||
- **`env`** _(list, optional)_ | ||
You can set environment variables at build time, by defining each with the following fields: | ||
|
||
- **`name`** _(string, optional)_\ | ||
The name of the environment variable | ||
|
||
- **`value`** _(string, optional, default: latest)_\ | ||
The assigned version of the environment variable | ||
|
||
- **`include`** _(string list, optional)_\ | ||
A list of files to include in the build, while excluding everything else. | ||
|
||
OR | ||
|
||
- **`exclude`** _(string list, optional)_\ | ||
A list of files to exclude from the build, while including everything else. | ||
|
||
> If `include` and `exclude` are both present, the lifecycle will error out. | ||
|
||
- **`buildpacks`** _(list, optional)_ | ||
A list of buildpacks, each with the following fields: | ||
|
||
- **`id`** _(string, optional)_\ | ||
An identifier for the buildpack. Must match ID specified in buildpack's `buildpack.toml` file. | ||
|
||
- **`version`** _(string, optional, default: latest)_\ | ||
The version of the buildpack. Must match version specified in buildpack's `buildpack.toml` file. | ||
|
||
- **`uri`** _(string, default=`urn:buildpack:<id>`)_\ | ||
A URL or path to an [archive][supported-archives], a packaged buildpack (saved as a `.cnb` file), or a directory. If path is relative, it must be relative to the `project.toml`. | ||
|
||
- #### `metadata` _(table, optional)_ | ||
Buildpacks and specific platforms are free to define additional arbitrary key-value pairs in the `metadata` table. | ||
|
||
## Example | ||
An example `project.toml` is: | ||
```toml | ||
[project] | ||
id = "io.buildpacks.my-app" | ||
version = "0.1" | ||
|
||
[build] | ||
include = [ | ||
"cmd/", | ||
"go.mod", | ||
"go.sum", | ||
"*.go" | ||
] | ||
|
||
[[build.env]] | ||
name = "JAVA_OPTS" | ||
value = "-Xmx1g" | ||
|
||
[[build.buildpacks]] | ||
id = "io.buildpacks/java" | ||
version = "1.0" | ||
|
||
[[build.buildpacks]] | ||
id = "io.buildpacks/nodejs" | ||
version = "1.0" | ||
|
||
[metadata] | ||
foo = "bar" | ||
|
||
[metadata.fizz] | ||
buzz = ["a", "b", "c"] | ||
``` | ||
|
||
## Specification | ||
For more detail, you can check out the `project.toml` [specification][spec] | ||
|
||
[spec]: https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md | ||
[supported-archives]: /docs/reference/builder-config#supported-archives |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not sure if this is a feature of a bug. Should
project.toml
detect env vars set? Should I open a bug in pack?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.
This would be a feature request. I don't believe this is an expectation and given that this is a spec'd it would require an RFC.