Skip to content

Commit

Permalink
Merge pull request #6 from amp-buildpacks/feat/issue-3
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo authored Jun 8, 2024
2 parents f200232 + 427621e commit 035c540
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 144 deletions.
13 changes: 13 additions & 0 deletions .github/pipeline-descriptor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
github:
username: ${{ github.actor }}
token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }}

package:
repositories: ["ghcr.io/amp-buildpacks/cairo"]
register: false
registry_token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }}

docker_credentials:
- registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }}
87 changes: 87 additions & 0 deletions .github/workflows/pb-update-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Update Pipeline
"on":
push:
branches:
- main
paths:
- .github/pipeline-descriptor.yml
schedule:
- cron: 0 5 * * 1-5
workflow_dispatch: {}
jobs:
update:
name: Update Pipeline
runs-on:
- ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Install octo
run: |
#!/usr/bin/env bash
set -euo pipefail
go install -ldflags="-s -w" github.com/paketo-buildpacks/pipeline-builder/cmd/octo@latest
- uses: actions/checkout@v3
- name: Update Pipeline
id: pipeline
run: |
#!/usr/bin/env bash
set -euo pipefail
if [[ -f .github/pipeline-version ]]; then
OLD_VERSION=$(cat .github/pipeline-version)
else
OLD_VERSION="0.0.0"
fi
rm .github/workflows/pb-*.yml || true
octo --descriptor "${DESCRIPTOR}"
PAYLOAD=$(gh api /repos/paketo-buildpacks/pipeline-builder/releases/latest)
NEW_VERSION=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.name')
echo "${NEW_VERSION}" > .github/pipeline-version
RELEASE_NOTES=$(
gh api \
-F text="$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.body')" \
-F mode="gfm" \
-F context="paketo-buildpacks/pipeline-builder" \
-X POST /markdown
)
git add .github/
git checkout -- .
echo "old-version=${OLD_VERSION}" >> "$GITHUB_OUTPUT"
echo "new-version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
DELIMITER=$(openssl rand -hex 16) # roughly the same entropy as uuid v4 used in https://github.com/actions/toolkit/blob/b36e70495fbee083eb20f600eafa9091d832577d/packages/core/src/file-command.ts#L28
printf "release-notes<<%s\n%s\n%s\n" "${DELIMITER}" "${RELEASE_NOTES}" "${DELIMITER}" >> "${GITHUB_OUTPUT}" # see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
env:
DESCRIPTOR: .github/pipeline-descriptor.yml
GITHUB_TOKEN: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }}
- uses: peter-evans/create-pull-request@v5
with:
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
body: |-
Bumps pipeline from `${{ steps.pipeline.outputs.old-version }}` to `${{ steps.pipeline.outputs.new-version }}`.
<details>
<summary>Release Notes</summary>
${{ steps.pipeline.outputs.release-notes }}
</details>
branch: update/pipeline
commit-message: |-
Bump pipeline from ${{ steps.pipeline.outputs.old-version }} to ${{ steps.pipeline.outputs.new-version }}
Bumps pipeline from ${{ steps.pipeline.outputs.old-version }} to ${{ steps.pipeline.outputs.new-version }}.
delete-branch: true
labels: semver:patch, type:task
signoff: true
title: Bump pipeline from ${{ steps.pipeline.outputs.old-version }} to ${{ steps.pipeline.outputs.new-version }}
token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) The Amphitheatre Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

bin/
dependencies/
package/
scratch/
113 changes: 5 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ enable the building of a Cairo-based application.

## Included Buildpacks

- [`amp-buildpacks/scarb`](https://github.com/amp-buildpacks/scarb)(WIP)
- [`amp-buildpacks/starknet`](https://github.com/amp-buildpacks/starknet)(WIP)

- [`amp-buildpacks/scarb`](https://github.com/amp-buildpacks/scarb)

- [`amp-buildpacks/starknet`](https://github.com/amp-buildpacks/starknet)

- [`paketo-buildpacks/procfile`](https://github.com/paketo-buildpacks/procfile)

## tl;dr
Expand Down Expand Up @@ -35,112 +38,6 @@ Packages](https://github.com/orgs/amp-buildpacks/packages).

To use: `pack build <image-name> -b ghcr.io/amp-buildpacks/cairo`

### A Builder

In this repo is a sample `example-builder.toml` that you can use to create your
own builder. We do not publish a builder, so if you'd like to use this route you
must first create the builder.

To create the builder, just run `pack builder create <published-to>/cairo-builder
--config example-builder.toml`. For example, `pack builder create
amp-buildpacks/cairo-builder --config example-builder.toml`.

You can then build an app with it using `pack build <image-name> --builder
<published-to>/cairo-builder`.

The builder is configure to use the base build and run images, which is a
reasonable mix of size and functionality. You may change the build and run
images to use the full stack, which has a lot more libraries and tools installed
but is quite a bit larger, or you can use the tiny build and run images which
presents a very small container but doesn't even contain a shell, which can make
debugging difficult.

To switch, swap the stack that you'd like to use in the builder file.

Example full stack:

```
[stack]
id = "io.buildpacks.stacks.jammy"
build-image = "docker.io/paketobuildpacks/build-jammy-base:latest"
run-image = "docker.io/paketobuildpacks/run-jammy-base:latest"
```

Example tiny stack:

```
[stack]
id = "io.buildpacks.stacks.jammy.tiny"
build-image = "docker.io/paketobuildpacks/build-jammy-tiny"
run-image = "docker.io/paketobuildpacks/run-jammy-tiny"
```

## Tips

- When building for the Paketo Tiny stack, you must build with the target set to
`x86_64-unknown-linux-musl`. This is because if you build with the glibc
target, you will end up with a dependency for the `libgcc_s.so.1` library that
does not exist on the Paketo Tiny run image. If we target musl instead, you'll
get a binary that is statically compiled against musl and does not have this
requirement, thus it will run on the Tiny stack.

When you run with the Tiny stack, the buildpacks will detect this and
automatically adjust. This includes installing the additional target to
cross-compile and modifying build commands cross-compile using the musl
target.

- By default, the Cairo buildpack will install `tini`, which is a very small
process manager that handles the PID1 responsibilities (it's also the same
running `docker run --init`), into your application image. Because your
application will run as PID1, this ensures that your application will properly
handle signals. If you are running your image with Docker, this is what makes
CTRL+C function correctly. If you're running on Kubernetes, this is what makes
graceful termination work correctly.

It is generally recommended that you keep `tini` installed. It's extremely
low-overhead. That said, if you really, really know what you're doing and your
application is properly handling signals and reaping child processes then you
may set `$BP_CAIRO_TINI_DISABLED=true` and the buildpacks will skip installing
`tini.`.

- What's the difference between using a builder and using the composite
buildpack (i.e. `ghcr.io/amp-buildpacks/cairo`)? There's not a lot of
difference, so feel free to use which one is more convenient for your use
cases. The composite buildpack is published to Amphitheatre Buildpacks
Packages so it's often easier to get started using it. We are not publishing a
builder image at the moment, so you need to build that on your own. The
builder does offer some additional customization options though. Plus, you can
set a default builder with `pack`, so if you're building many different
applications it can reduce the amount of flags you need to send to `pack
build`. You do not need to use both the builder and composite buildpack.

- Can I specify multiple processes in my `Procfile`? Yes! To make this work,
just add more lines to `Procfile`. One of the lines needs to be named `web`,
which is the expected name for the default process. Alternatively, you may use
different names but pass the `--default-process` argument to `pack build` to
indicate the default process name in your `Procfile`. It is highly recommended
that you have a default process. See [here for more details on multiple
process
containers](https://buildpacks.io/docs/app-developer-guide/run-an-app/).

- Can I pass arguments to my application? Yes, you just append them to the end
of your `docker run` command. See [here for an
example](https://buildpacks.io/docs/app-developer-guide/run-an-app/#default-process-type-with-additional-arguments).

- How do I run a non-default process from my `Procfile`? Pass `--entrypoint
<process name>` to `docker run`. See [here for an
example](https://buildpacks.io/docs/app-developer-guide/run-an-app/#non-default-process-type).

- How do I launch a shell in my container to debug? There are two ways to do
this.
[First](https://buildpacks.io/docs/app-developer-guide/run-an-app/#user-provided-shell-process),
`docker run --rm --entrypoint launcher -it <image-name> bash`. The first will
set up the shell with the standard environment, the same as what your
application will get when it launches.
[Second](https://buildpacks.io/docs/app-developer-guide/run-an-app/#no-launcher),
`docker run --rm --entrypoint bash -it <image-name>`. The second will give you
a blank environment without any buildpack specific environment variables set.

## Contributing

If anything feels off, or if you feel that some functionality is missing, please
Expand Down
26 changes: 21 additions & 5 deletions buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
api = "0.7"
# Copyright (c) The Amphitheatre Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

api = "0.8"

[buildpack]
description = "A Cloud Native Buildpack with an order definition suitable for Cairo applications"
homepage = "https://github.com/amp-buildpacks/cairo"
id = "amp-buildpacks/cairo"
keywords = ["cairo", "composite"]
name = "Cairo Build Pack"
version = "{{.version}}"
keywords = ["Cairo"]
name = "AMP Buildpack for Cairo"
version = "{{ .version }}"

[[buildpack.licenses]]
type = "Apache-2.0"
Expand All @@ -17,9 +31,11 @@ api = "0.7"

[[order]]


[[order.group]]
id = "amp-buildpacks/scarb"
version = "0.1.0"
version = "0.2.0"

[[order.group]]
id = "amp-buildpacks/starknet"
version = "0.1.0"
Expand Down
7 changes: 7 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[dependencies]]
repo = "amp-buildpacks/scarb"
version = "0.2.0"

[[dependencies]]
repo = "amp-buildpacks/starknet"
version = "0.1.0"
30 changes: 0 additions & 30 deletions example-builder.toml

This file was deleted.

13 changes: 12 additions & 1 deletion package.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@

[[dependencies]]
uri = "docker://ghcr.io/amp-buildpacks/scarb:0.1.0"
uri = "docker://ghcr.io/amp-buildpacks/scarb:0.2.0"

[[dependencies]]
uri = "docker://ghcr.io/amp-buildpacks/starknet:0.1.0"


[[dependencies]]
uri = "docker://gcr.io/paketo-buildpacks/procfile:5.6.8"

[[targets]]
arch = "amd64"
os = "linux"

[[targets]]
arch = "arm64"
os = "linux"

0 comments on commit 035c540

Please sign in to comment.