Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/buildpacks/github-…
Browse files Browse the repository at this point in the history
…actions-5.7.0
  • Loading branch information
AidanDelaney committed Jun 17, 2024
2 parents 879c0ef + ec87a39 commit 51a3301
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ weight=1
<!--more-->

Building for the ARM architecture is now easier than ever! The `heroku/builder:24` builder supports both AMD64 and ARM64 architectures, and includes
multi-arch Java, Node.js, Python, Ruby, Scala and Go buildpacks. You can read more about Heroku's [Cloud Native Buildpacks here][heroku-buildpacks].
multi-arch Go, Java, Node.js, PHP, Python, Ruby and Scala buildpacks. You can read more about Heroku's [Cloud Native Buildpacks here][heroku-buildpacks].

### 1. Clone the [samples][samples] repository

Expand All @@ -22,17 +22,17 @@ git clone https://github.com/buildpacks/samples

### 2. Build the app

If you're using an ARM64 computer (such as an Apple Silicon Mac, or an AWS Graviton instance), you can produce an ARM64 OCI image with [pack][pack] simply by setting your builder to `heroku/builder:24`:
If you're using an ARM64 computer (such as an Apple Silicon Mac, or an AWS Graviton instance), you can build an ARM64 OCI image with [pack][pack] simply by setting your builder to `heroku/builder:24`:
```
pack build java-maven-sample --path samples/apps/java-maven/ --builder heroku/builder:24
```
<!--+- "{{execute}}"+-->

As `heroku/builder:24` is a multi-arch builder, it'll default to the current architecture, and an AMD64 image will be built when running `pack` on that architecture.
By default, `pack` uses the current architecture for multi-arch builders like `heroku/builder:24`, so an AMD64 image will be built on AMD64 systems.

If you want to build an ARM64 image from a different host architecture, you can use the arch-specific builder tag: `heroku/builder:24_linux-arm64`:
If you want to build an ARM64 image from a different host architecture, use the `--platform` parameter:
```
pack build java-maven-sample --path samples/apps/java-maven/ --builder heroku/builder:24_linux-arm64
pack build java-maven-sample --path samples/apps/java-maven/ --builder heroku/builder:24 --platform linux/arm64
```
<!--+- "{{execute}}"+-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,81 @@ weight=99

<!--more-->

This page is a stub! The CNB project is applying to [Google Season of Docs](https://developers.google.com/season-of-docs/docs/timeline) to receive support for improving our documentation. Please check back soon.
The [buildpacks `exec.d` interface](https://github.com/buildpacks/spec/blob/main/buildpack.md#execd) allows buildpack authors to execute custom scripts or binaries when the application image is started. This interface can be particularly useful for injecting dynamic behavior or environment variables into the runtime environment of an application.

If you are familiar with this content and would like to make a contribution, please feel free to open a PR :)
## Key Points:

1. Location and Naming: Scripts are placed in the `<layer>/exec.d/` directory within a launch layer and must be executable. They can have any name.

2. Script Behavior:
* **Inputs**
* A third open file descriptor (in addition to stdout and stderr). The third open file descriptor is inherited from the calling process.
* **Outputs**
* Valid TOML describing environment variables in the form of key=value pairs. These variables are added to the application's runtime environment. The content should be written to file descriptor 3 (see examples for how to do this).
* Exit Code: The scripts should exit with a status code of `0` to indicate success. A non-zero exit code will indicate an error and prevent the application from launching.

## Use Cases:
* Dynamic Configuration: Inject configuration values that are determined at runtime.
* Service Bindings: Configure environment variables based on bound services.

## Implementation Steps:
* Write Scripts: Create executable scripts within the `<layer>/exec.d/` directory.
* Set Permissions: Ensure scripts have the appropriate execute permissions (chmod +x).
* Environment Variables: Use scripts to print `key="value"` pairs to the third open file descriptor.

### Examples

`exec.d` executables can be written in any language. We provide examples in bash, Go and Python that inject the `EXAMPLE="test"` into the runtime environment. It is important that environment variables are written to the third file descriptor which is inherited by the `exec.d` binary.

A `bash` example looks as follows:
```bash
#!/bin/bash

# Use the third file descriptor
FD=&3

# Output the environment variable EXAMPLE="test" to the specified file descriptor
echo "EXAMPLE=\"test\"" >&$FD
```

And a `Go` example is:
```Go
package main

import (
"fmt"
"os"
)

func main() {
// Open file descriptor 3 for writing
fd3 := os.NewFile(3, "fd3")
if fd3 == nil {
fmt.Println("Failed to open file descriptor 3")
return
}

// Write the environment variable to file descriptor 3
_, err := fd3.WriteString(`EXAMPLE="test"\n`)
if err != nil {
fmt.Println("Error writing to file descriptor 3:", err)
}
}
```
Finally, we provide a short Python example:
```Python
import os
import sys

def main():
# Use file descriptor 3
fd = 3

# Write the environment variable to the given file descriptor
os.write(fd, b'EXAMPLE="test"\n')

if __name__ == "__main__":
main()
```

The `exec.d` interface provides a powerful mechanism for dynamically configuring runtime environments in a flexible and programmable manner, enhancing the customization capabilities available to application programmers using buildpacks.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FROM ubuntu:jammy
# Install packages that we want to make available at build time
RUN apt-get update && \
apt-get install -y xz-utils ca-certificates && \
rm -rf /var/lib/apt/lists/* \
rm -rf /var/lib/apt/lists/*

# Set required CNB user information
ARG cnb_uid=1000
Expand All @@ -32,7 +32,7 @@ ENV CNB_GROUP_ID=${cnb_gid}

# Create user and group
RUN groupadd cnb --gid ${CNB_GROUP_ID} && \
useradd --uid ${CNB_USER_ID} --gid ${CNB_GROUP_ID} -m -s /bin/bash cnb \
useradd --uid ${CNB_USER_ID} --gid ${CNB_GROUP_ID} -m -s /bin/bash cnb

# Set user and group
USER ${CNB_USER_ID}:${CNB_GROUP_ID}
Expand Down
Loading

0 comments on commit 51a3301

Please sign in to comment.