Compare commits
67 Commits
Author | SHA1 | Date |
---|---|---|
|
2f19abaa19 | |
|
530701a74e | |
|
a5f67de09e | |
|
3155c35c0d | |
|
a1b0f2d6a5 | |
|
5eb4f17c7c | |
|
619e3e2dd4 | |
|
f0578ebd4b | |
|
0cddf0d5d6 | |
|
913be197c6 | |
|
cc391d52f9 | |
|
de7c5df218 | |
|
8c2d84ba38 | |
|
17d3f29875 | |
|
fff3f220a2 | |
|
46ec76538d | |
|
87dad6af6a | |
|
2246e4a453 | |
|
02c8c71447 | |
|
3727a921a7 | |
|
7dd27675eb | |
|
7710ecaa6a | |
|
50b35365e1 | |
|
0c86df4f76 | |
|
a65fef7c5d | |
|
47b249190b | |
|
42e38e4e5d | |
|
d7368a57c9 | |
|
94eb5b3ab1 | |
|
7cfdb28c63 | |
|
1bcabd71dd | |
|
1b51d3b608 | |
|
4bae602fd7 | |
|
1952baeaa9 | |
|
bf300f4744 | |
|
ddeaa001d0 | |
|
24def30fbd | |
|
1abdea7406 | |
|
cf44fd8451 | |
|
f4b67a4f4f | |
|
00c283d2da | |
|
dbc9e301eb | |
|
11e6612ec6 | |
|
8f8745e69d | |
|
9a13a52644 | |
|
0634d3a885 | |
|
38e4a3e4e2 | |
|
0a164a9430 | |
|
2bff69bb56 | |
|
8e5a650de1 | |
|
c08b235e60 | |
|
eb052ac5e6 | |
|
a492cae142 | |
|
a89a6750d5 | |
|
b56dd82931 | |
|
8a521d8f94 | |
|
a74ab17f87 | |
|
4c183ae43a | |
|
e380792cfd | |
|
7f27da12e0 | |
|
3e5385680e | |
|
53b4b70423 | |
|
1f2a08e726 | |
|
a5813dcb55 | |
|
36af9ad3a6 | |
|
604345bf68 | |
|
1dcd173f45 |
|
@ -1,36 +1,154 @@
|
|||
version: 2.1
|
||||
orbs:
|
||||
orb-tools: circleci/orb-tools@9.1.0
|
||||
|
||||
# Orb depedencies
|
||||
orbs:
|
||||
orb-tools: circleci/orb-tools@10.0.3
|
||||
## used for integration tests
|
||||
buildpacks: buildpacks/pack@<<pipeline.parameters.dev-orb-version>>
|
||||
|
||||
# Pipeline Parameters
|
||||
parameters:
|
||||
## internal to orb-tools
|
||||
run-integration-tests:
|
||||
description: An internal flag to prevent integration test from running before a development version has been created.
|
||||
type: boolean
|
||||
default: false
|
||||
## internal to orb-tools
|
||||
dev-orb-version:
|
||||
description: >
|
||||
The development version of the orb to test.
|
||||
This value is automatically adjusted by the "trigger-integration-tests-workflow" job to correspond with the specific version created by the commit and should not be edited.
|
||||
A "dev:alpha" version must exist for the initial pipeline run.
|
||||
type: string
|
||||
default: "dev:alpha"
|
||||
|
||||
# Jobs to use in workflows
|
||||
jobs:
|
||||
test:
|
||||
machine:
|
||||
image: ubuntu-2204:2023.04.2
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Run unit tests
|
||||
command: make test
|
||||
github-release:
|
||||
machine:
|
||||
image: ubuntu-2204:2023.04.2
|
||||
steps:
|
||||
- run:
|
||||
name: Install releaser
|
||||
command: go get -u github.com/tcnksm/ghr
|
||||
- checkout
|
||||
- run:
|
||||
name: Determine version
|
||||
command: |
|
||||
BRANCH=$CIRCLE_BRANCH make future-version | tail -1 > VERSION
|
||||
cat VERSION
|
||||
- run:
|
||||
name: Generate changelog
|
||||
command: |
|
||||
VERSION=$(cat VERSION) make generate-changelog
|
||||
- run:
|
||||
name: Create GH release
|
||||
command: |
|
||||
VERSION=$(cat VERSION)
|
||||
ghr -draft -t $GITHUB_TOKEN -c $CIRCLE_SHA1 -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME -b "$(cat CHANGELOG.md)" -n "pack-orb ${VERSION}" $VERSION
|
||||
|
||||
# Workflows
|
||||
#
|
||||
# The following is a visual representation of the existing workflows for development and releasing:
|
||||
#
|
||||
# on main branch and per PR on release/* branch
|
||||
# ┌────────────────────────────┐ ┌─────────────────┐
|
||||
# │ │ │ │
|
||||
# │ ┌────────────┐ │ │ draft release │
|
||||
# │ │ │ │ │ │
|
||||
# │ │ validate │ │ └─────────────────┘
|
||||
# │ │ │ │
|
||||
# │ └──────┬─────┘ │
|
||||
# │ │ *trigger* │
|
||||
# │ │ │ on tags
|
||||
# │ ┌───────▼───────┐ │ ┌────────────┐
|
||||
# │ │ │ │ │ │
|
||||
# │ │ integration │ │ │ publish │
|
||||
# │ │ tests │ │ │ │
|
||||
# │ │ │ │ └────────────┘
|
||||
# │ └───────────────┘ │
|
||||
# │ │
|
||||
# └────────────────────────────┘
|
||||
#
|
||||
workflows:
|
||||
validate-publish-dev:
|
||||
integration-test:
|
||||
when: << pipeline.parameters.run-integration-tests >>
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
name: "Minimal"
|
||||
builder: cnbs/sample-builder:bionic
|
||||
image-name: test-image
|
||||
working-directory: samples/apps/ruby-bundler
|
||||
after-checkout:
|
||||
- run: git clone --depth=1 https://github.com/buildpacks/samples.git samples
|
||||
- buildpacks/build:
|
||||
name: "All Options"
|
||||
builder: cnbs/sample-builder:bionic
|
||||
image-name: test-image
|
||||
working-directory: samples/apps/ruby-bundler
|
||||
buildpacks: samples/ruby-bundler
|
||||
env-vars: "ENV_1=VAL 1;ENV_2=VAL 2"
|
||||
tags: "another-image:2"
|
||||
image-file: "exported-image.tgz"
|
||||
version: "0.18.1"
|
||||
after-checkout:
|
||||
- run: git clone --depth=1 https://github.com/buildpacks/samples.git samples
|
||||
validate-dev:
|
||||
unless: << pipeline.parameters.run-integration-tests >>
|
||||
jobs:
|
||||
- orb-tools/lint
|
||||
- test
|
||||
- orb-tools/pack:
|
||||
use-orb-pack: true
|
||||
- orb-tools/publish-dev:
|
||||
orb-name: buildpacks/pack
|
||||
orb-path: orb.yml
|
||||
publish-token-variable: CIRCLE_TOKEN
|
||||
checkout: true
|
||||
requires:
|
||||
- orb-tools/lint
|
||||
tag-triggered-publish:
|
||||
- orb-tools/pack
|
||||
- orb-tools/trigger-integration-tests-workflow:
|
||||
name: trigger-integration-dev
|
||||
requires:
|
||||
- orb-tools/publish-dev
|
||||
draft-release:
|
||||
unless: << pipeline.parameters.run-integration-tests >>
|
||||
jobs:
|
||||
- hold-for-approval:
|
||||
filters:
|
||||
branches:
|
||||
only: /release\/.*/
|
||||
type: approval
|
||||
- github-release:
|
||||
filters:
|
||||
branches:
|
||||
only: /release\/.*/
|
||||
requires:
|
||||
- hold-for-approval
|
||||
publish:
|
||||
unless: << pipeline.parameters.run-integration-tests >>
|
||||
jobs:
|
||||
- orb-tools/pack:
|
||||
use-orb-pack: true
|
||||
filters:
|
||||
branches:
|
||||
ignore: /.*/
|
||||
tags:
|
||||
only: /^\d+\.\d+\.\d+$/
|
||||
type: approval
|
||||
- orb-tools/publish:
|
||||
orb-ref: buildpacks/pack@$CIRCLE_TAG
|
||||
orb-path: orb.yml
|
||||
publish-token-variable: CIRCLE_TOKEN
|
||||
attach-workspace: true
|
||||
checkout: false
|
||||
filters:
|
||||
branches:
|
||||
ignore: /.*/
|
||||
tags:
|
||||
only: /^\d+\.\d+\.\d+$/
|
||||
requires:
|
||||
- hold-for-approval
|
||||
|
||||
- orb-tools/pack
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
|
@ -0,0 +1,27 @@
|
|||
name: update-pack-version
|
||||
|
||||
on:
|
||||
repository_dispatch:
|
||||
types:
|
||||
- pack-release
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
update-version:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Update pack version of buildpacks/pack-orb/src/@orb.yml on new pack release
|
||||
run: |
|
||||
NEW_VERSION=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/buildpacks/pack/releases/latest | jq .tag_name -r | cut -c 2-)
|
||||
sed -i 's/default: [0-9]\{1,\}.[0-9]\{1,\}.[0-9]\{1,\}/default: '"${NEW_VERSION}"'/g' src/@orb.yml
|
||||
- name: Create pull request
|
||||
uses: peter-evans/create-pull-request@v3.10.0
|
||||
with:
|
||||
token: ${{ secrets.DISTRIBUTION_GITHUB_TOKEN }}
|
||||
commit-message: Update version to latest release of buildpacks/pack
|
||||
title: Update default version of @orb.yml
|
||||
body: Updates default version of @orb.yml to reflect release changes in buildpacks/pack
|
||||
branch: update-version
|
||||
base: main
|
||||
signoff: true
|
|
@ -0,0 +1,18 @@
|
|||
## Filtering
|
||||
unreleased-only=true
|
||||
issues=false
|
||||
|
||||
## Other Visuals
|
||||
compare-link=false
|
||||
usernames-as-github-logins=true
|
||||
|
||||
## Sections
|
||||
header-label=## Changelog
|
||||
|
||||
enhancement-label=### Improvements
|
||||
enhancement-labels=type/enhancement
|
||||
|
||||
bugs-label=### Fixes
|
||||
bug-labels=type/bug
|
||||
|
||||
pr-label=### Other Changes
|
|
@ -0,0 +1,3 @@
|
|||
# generated during release workflow
|
||||
CHANGELOG.md
|
||||
VERSION
|
|
@ -0,0 +1,6 @@
|
|||
extends: relaxed
|
||||
|
||||
rules:
|
||||
line-length:
|
||||
max: 200
|
||||
allow-non-breakable-inline-mappings: true
|
|
@ -1 +1 @@
|
|||
* @buildpacks/platform-maintainers
|
||||
* @buildpacks/platform-maintainers
|
|
@ -0,0 +1,31 @@
|
|||
We're glad you are interested in contributing to this project. We hope that this
|
||||
document helps you get started.
|
||||
|
||||
## Policies
|
||||
|
||||
This repository adheres to the following project policies:
|
||||
|
||||
- [Code of Conduct][code-of-conduct] - How we should act with each other.
|
||||
- [Contributing][contributing] - General contributing standards.
|
||||
- [Security][security] - Reporting security concerns.
|
||||
- [Support][support] - Getting support.
|
||||
|
||||
[code-of-conduct]: https://github.com/buildpacks/.github/blob/main/CODE_OF_CONDUCT.md
|
||||
[contributing]: https://github.com/buildpacks/.github/blob/main/CONTRIBUTING.md
|
||||
[security]: https://github.com/buildpacks/.github/blob/main/SECURITY.md
|
||||
[support]: https://github.com/buildpacks/.github/blob/main/SUPPORT.md
|
||||
|
||||
|
||||
## Contributing to this repository
|
||||
|
||||
### Development
|
||||
|
||||
Aside from the policies above, you may find [DEVELOPMENT.md](DEVELOPMENT.md) to provide specific helpful detail
|
||||
to assist you while developing in this repository.
|
||||
|
||||
|
||||
#### Creating a Pull Request
|
||||
|
||||
After making all the changes read the following [Pull Request process][pull-request-process].
|
||||
|
||||
[pull-request-process]: https://github.com/buildpacks/.github/blob/main/CONTRIBUTING.md#pull-request-process
|
|
@ -0,0 +1,23 @@
|
|||
## Prerequisites
|
||||
|
||||
* [Docker](https://www.docker.com/products/docker-desktop)
|
||||
* [`circleci` CLI](https://circleci.com/docs/2.0/local-cli/#installation)
|
||||
* Make (and build tools)
|
||||
* macOS: `xcode-select --install`
|
||||
* Windows:
|
||||
* `choco install cygwin make -y`
|
||||
* `[Environment]::SetEnvironmentVariable("PATH", "C:\tools\cygwin\bin;$ENV:PATH", "MACHINE")`
|
||||
|
||||
### Linting
|
||||
|
||||
```
|
||||
make lint
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
Tests are structured as recommended by the [Orb Project Template](https://github.com/CircleCI-Public/Orb-Project-Template/tree/master/src/tests). They use [shunit2](https://github.com/kward/shunit2) instead of [BATS-Core](https://github.com/bats-core/bats-core).
|
||||
|
||||
```
|
||||
make test
|
||||
```
|
|
@ -0,0 +1,46 @@
|
|||
BRANCH?=$(shell git branch --show-current)
|
||||
VERSION?=$(shell echo $(BRANCH) | grep "^release" | sed 's;release\/\(.*\);\1;')
|
||||
|
||||
.PHONY: publish-dev
|
||||
publish-dev:
|
||||
@echo "> Publishing new dev:alpha version..."
|
||||
circleci orb pack src/ | circleci orb publish - buildpacks/pack@dev:alpha
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@echo "NOTE: If changes have been make to .circleci/config.yml "\
|
||||
"that depend on changes to the orb. It may require for the 'dev:alpha' "\
|
||||
"version to be updated.\n\nYou may run 'publish-dev' to do so (if permissions allow).\n"
|
||||
|
||||
@echo "> Validating orb..."
|
||||
circleci orb pack src/ | circleci orb validate -
|
||||
|
||||
@echo "> Validating CI config..."
|
||||
circleci config validate .circleci/config.yml
|
||||
|
||||
.PHONE: test
|
||||
test:
|
||||
@echo "> Running tests..."
|
||||
cd ./src/tests/; find . -type f -name "*_test.sh" -exec {} \;
|
||||
|
||||
.PHONY: future-version
|
||||
future-version:
|
||||
@echo "> Determining future version..."
|
||||
@$(if $(strip $(VERSION)),echo $(VERSION), echo "Failed to determine future version. May need to provide VERSION env var."; exit 1)
|
||||
|
||||
.PHONY: generate-changelog
|
||||
generate-changelog: export TMP_DIR:=$(shell mktemp -d "/tmp/changelog.XXXXXXXXX")
|
||||
generate-changelog: future-version
|
||||
generate-changelog:
|
||||
@echo "> Configuring changelog generator..."
|
||||
@cp .github_changelog_generator $(TMP_DIR)
|
||||
|
||||
@echo "> Generating changelog..."
|
||||
@docker run -it --rm -v "$(TMP_DIR)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator --user buildpacks --project pack-orb --token $(GITHUB_TOKEN) --future-release $(VERSION) -o CHANGELOG.md
|
||||
|
||||
@echo "> Cleaning it up..."
|
||||
@# removes footer
|
||||
@awk 'n>=3 { print a[n%3] } { a[n++%3]=$$0 }' "$(TMP_DIR)/CHANGELOG.md" > CHANGELOG.md
|
||||
|
||||
@echo "> CHANGELOG:"
|
||||
@cat CHANGELOG.md
|
13
README.md
13
README.md
|
@ -10,13 +10,10 @@ For more information and usage examples, see the [CircleCI documentation](https:
|
|||
|
||||
See the [documentation on the CircleCI Orb Registry](https://circleci.com/orbs/registry/orb/buildpacks/pack).
|
||||
|
||||
## Releasing
|
||||
## Contributing
|
||||
|
||||
Create a tag a push it:
|
||||
We ❤ contributions.
|
||||
|
||||
```
|
||||
$ git tag x.y.z
|
||||
$ git push --tags
|
||||
```
|
||||
|
||||
Check [CircleCI](https://circleci.com/gh/buildpacks/pack-orb) to manually approve the release workflow.
|
||||
- [CONTRIBUTING](CONTRIBUTING.md) - Information on how to contribute, including the pull request process.
|
||||
- [DEVELOPMENT](DEVELOPMENT.md) - Further detail to help you during the development process.
|
||||
- [RELEASE](RELEASE.md) - Further details about our release process.
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
## Release Process
|
||||
|
||||
1. Create and push `release/<VERSION>` branch off of `main`.
|
||||
1. After all [CI checks](https://app.circleci.com/pipelines/github/buildpacks/pack-orb) pass, find the job "hold-for-approval" and `Approve`.
|
||||
1. On the [GitHub releases page](https://github.com/buildpacks/pack-orb/releases):
|
||||
1. Click `Edit` on the latest _draft_ release.
|
||||
1. Review (and edit) generated changelog.
|
||||
1. Verify the _tag version_ value:
|
||||
- It should be `<VERSION>`.
|
||||
- It should "target" the `release/<VERSION>` branch.
|
||||
1. Click `Publish` release.
|
||||
|
||||
_The release "Publish" action will create a tag that then triggers a workflow that additionally publishes the orb to the circleci catalog._
|
||||
1. Confirm that the orb is updated by viewing the [orb page](https://circleci.com/developer/orbs/orb/buildpacks/pack).
|
||||
|
||||
## Makefile targets
|
||||
|
||||
`make future-version` - logic to determine the next version by looking at the current git branch.
|
||||
`make generate-changelog` - process of generating the changelog for the `future-version`.
|
180
orb.yml
180
orb.yml
|
@ -1,180 +0,0 @@
|
|||
version: 2.1
|
||||
description: Cloud Native Buildpacks Orb
|
||||
|
||||
display:
|
||||
source_url: "https://github.com/buildpacks/pack-orb"
|
||||
home_url: "https://buildpacks.io/"
|
||||
|
||||
orbs:
|
||||
docker: circleci/docker@1.2.1
|
||||
orb-tools: circleci/orb-tools@9.1.0
|
||||
jobs:
|
||||
build:
|
||||
description: "Build OCI Image"
|
||||
machine: true
|
||||
parameters:
|
||||
image-name:
|
||||
type: string
|
||||
image-file:
|
||||
type: string
|
||||
default: "image.tgz"
|
||||
builder:
|
||||
type: string
|
||||
buildpack:
|
||||
type: string
|
||||
default: ""
|
||||
env-vars:
|
||||
type: string
|
||||
default: ""
|
||||
version:
|
||||
type: string
|
||||
default: 0.13.1
|
||||
steps:
|
||||
- run: sudo chown -R circleci /var/lib/docker/volumes
|
||||
- install-pack:
|
||||
version: << parameters.version >>
|
||||
- checkout
|
||||
- pack-build:
|
||||
image-name: << parameters.image-name >>
|
||||
builder: << parameters.builder >>
|
||||
buildpack: << parameters.buildpack >>
|
||||
env-vars: << parameters.env-vars >>
|
||||
- save-image-to-workspace:
|
||||
image-name: << parameters.image-name >>
|
||||
image-file: << parameters.image-file >>
|
||||
commands:
|
||||
save-image-to-workspace:
|
||||
description: "Save image"
|
||||
parameters:
|
||||
image-name:
|
||||
type: string
|
||||
image-file:
|
||||
type: string
|
||||
default: image.tgz
|
||||
steps:
|
||||
- run:
|
||||
name: Save image to workspace
|
||||
command: |
|
||||
mkdir -p images
|
||||
docker save -o images/<< parameters.image-file >> << parameters.image-name >>
|
||||
- persist_to_workspace:
|
||||
root: .
|
||||
paths:
|
||||
- ./
|
||||
pack-build:
|
||||
description: "Run pack build"
|
||||
parameters:
|
||||
image-name:
|
||||
type: string
|
||||
builder:
|
||||
type: string
|
||||
buildpack:
|
||||
type: string
|
||||
env-vars:
|
||||
type: string
|
||||
steps:
|
||||
- restore_cache:
|
||||
key: pack-cache-<< parameters.image-name >>-<< parameters.builder >>-{{ arch }}
|
||||
- run:
|
||||
name: Run pack build
|
||||
command: |
|
||||
ENV_VARS=""
|
||||
|
||||
in="<< parameters.env-vars >>"
|
||||
IFS=';' list=($in)
|
||||
for item in "${list[@]}"; do
|
||||
case "$item" in
|
||||
*\ * )
|
||||
IFS='='
|
||||
read -a strarr \<<<"$item"
|
||||
ENV_VARS="--env ${strarr[0]}=\"${strarr[1]}\" ${ENV_VARS}"
|
||||
unset IFS
|
||||
;;
|
||||
*)
|
||||
ENV_VARS="--env ${item} ${ENV_VARS}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
BUILD_PACK_ARG=$(if [ -n "<< parameters.buildpack >>" ]; then echo -n "--buildpack << parameters.buildpack >>"; else echo -n ""; fi)
|
||||
|
||||
eval pack build << parameters.image-name >> --builder << parameters.builder >> "${BUILD_PACK_ARG}" "${ENV_VARS}"
|
||||
- save_cache:
|
||||
key: pack-cache-<< parameters.image-name >>-<< parameters.builder >>-{{ arch }}-{{ epoch }}
|
||||
paths:
|
||||
- /var/lib/docker/volumes/
|
||||
install-pack:
|
||||
description: "Setup and install pack"
|
||||
parameters:
|
||||
install-dir:
|
||||
default: ~/bin
|
||||
description: |
|
||||
Directory in which to install Pack binary
|
||||
type: string
|
||||
version:
|
||||
type: string
|
||||
default: 0.13.1
|
||||
steps:
|
||||
- run:
|
||||
name: "Setup and install pack"
|
||||
command: |
|
||||
mkdir -p << parameters.install-dir >>
|
||||
curl -L "https://github.com/buildpack/pack/releases/download/v<< parameters.version >>/pack-v<< parameters.version >>-linux.tgz" | tar xzm -C << parameters.install-dir >>
|
||||
export PATH="$PATH:<< parameters.install-dir >>"
|
||||
mkdir -p ~/.docker/
|
||||
if [ ! -f ~/.docker/config.json ]; then
|
||||
echo "{}" > ~/.docker/config.json
|
||||
fi
|
||||
examples:
|
||||
heroku:
|
||||
description: Run the Heroku Buildpacks
|
||||
usage:
|
||||
version: 2.1
|
||||
orbs:
|
||||
buildpacks: buildpacks/pack@x.y.z
|
||||
workflows:
|
||||
main:
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
builder: heroku/buildpacks:18
|
||||
use-buildpack:
|
||||
description: Run the Heroku Buildpacks
|
||||
usage:
|
||||
version: 2.1
|
||||
orbs:
|
||||
buildpacks: buildpacks/pack@x.y.z
|
||||
workflows:
|
||||
main:
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
builder: heroku/buildpacks:18
|
||||
buildpack: heroku/ruby
|
||||
build-and-publish:
|
||||
description: Run the Heroku Buildpacks
|
||||
usage:
|
||||
version: 2.1
|
||||
orbs:
|
||||
buildpacks: buildpacks/pack@x.y.z
|
||||
jobs:
|
||||
publish:
|
||||
machine: true
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: /tmp/workspace
|
||||
- run:
|
||||
command: |
|
||||
docker load -i /tmp/workspace/images/myimage.tgz
|
||||
docker push myimage
|
||||
workflows:
|
||||
main:
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
image-file: myimage.tgz
|
||||
builder: heroku/buildpacks:18
|
||||
- publish:
|
||||
requires:
|
||||
- buildpacks/build
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
version: 2.1
|
||||
description: Cloud Native Buildpacks Orb
|
||||
|
||||
display:
|
||||
source_url: "https://github.com/buildpacks/pack-orb"
|
||||
home_url: "https://buildpacks.io/"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
description: "Build OCI Image"
|
||||
machine:
|
||||
image: << parameters.executor-image >>
|
||||
parameters:
|
||||
builder:
|
||||
type: string
|
||||
description: Builder image name to use.
|
||||
image-name:
|
||||
type: string
|
||||
description: Image name (aka tag) of the app image to be produced.
|
||||
working-directory:
|
||||
type: string
|
||||
description: The directory where the app source is located.
|
||||
default: ""
|
||||
buildpacks:
|
||||
type: string
|
||||
description: The specific buildpacks to execute. Semicolon (;) delimited.
|
||||
default: ""
|
||||
env-vars:
|
||||
type: string
|
||||
description: Build-time environment variables. Semicolon (;) delimited.
|
||||
default: ""
|
||||
tags:
|
||||
type: string
|
||||
description: Additional image names to create. Semicolon (;) delimited.
|
||||
default: ""
|
||||
image-file:
|
||||
type: string
|
||||
description: Filename to save the app image as locally.
|
||||
default: "image.tgz"
|
||||
version:
|
||||
type: string
|
||||
description: Version of 'pack' to use.
|
||||
default: 0.29.0
|
||||
after-checkout:
|
||||
description: Optional steps to run after checking out the code.
|
||||
type: steps
|
||||
default: []
|
||||
executor-image:
|
||||
type: string
|
||||
description: Image to execute 'pack' in.
|
||||
default: ubuntu-2204:2023.04.2
|
||||
steps:
|
||||
- run: sudo chown -R circleci /var/lib/docker/volumes
|
||||
- install-pack:
|
||||
version: << parameters.version >>
|
||||
- checkout
|
||||
- when:
|
||||
name: Run after-checkout lifecycle hook steps.
|
||||
condition: << parameters.after-checkout >>
|
||||
steps: << parameters.after-checkout >>
|
||||
- pack-build:
|
||||
builder: << parameters.builder >>
|
||||
image-name: << parameters.image-name >>
|
||||
path: << parameters.working-directory >>
|
||||
buildpacks: << parameters.buildpacks >>
|
||||
env-vars: << parameters.env-vars >>
|
||||
tags: << parameters.tags >>
|
||||
- save-image-to-workspace:
|
||||
image-name: << parameters.image-name >>
|
||||
image-file: << parameters.image-file >>
|
||||
commands:
|
||||
install-pack:
|
||||
description: "Setup and install pack"
|
||||
parameters:
|
||||
install-dir:
|
||||
default: ~/bin
|
||||
description: |
|
||||
Directory in which to install Pack binary
|
||||
type: string
|
||||
version:
|
||||
type: string
|
||||
default: 0.29.0
|
||||
steps:
|
||||
- run:
|
||||
name: "Setup and install pack"
|
||||
command: |
|
||||
mkdir -p << parameters.install-dir >>
|
||||
curl -L --fail --retry 3 --connect-timeout 5 --max-time 60 "https://github.com/buildpack/pack/releases/download/v<< parameters.version >>/pack-v<< parameters.version >>-linux.tgz" | tar xzm -C << parameters.install-dir >>
|
||||
export PATH="$PATH:<< parameters.install-dir >>"
|
||||
mkdir -p ~/.docker/
|
||||
if [ ! -f ~/.docker/config.json ]; then
|
||||
echo "{}" > ~/.docker/config.json
|
||||
fi
|
|
@ -0,0 +1,41 @@
|
|||
description: "Run pack build"
|
||||
parameters:
|
||||
builder:
|
||||
type: string
|
||||
description: The builder image name to use for building.
|
||||
image-name:
|
||||
type: string
|
||||
description: The primary image name to save the image as.
|
||||
path:
|
||||
type: string
|
||||
description: The path to the working directory to run `pack build` in.
|
||||
default: ""
|
||||
buildpacks:
|
||||
type: string
|
||||
description: The specific buildpacks to execute. Semicolon (;) delimited.
|
||||
default: ""
|
||||
env-vars:
|
||||
type: string
|
||||
description: Environment variables to set during the build. Semicolon (;) delimited.
|
||||
default: ""
|
||||
tags:
|
||||
type: string
|
||||
description: Additional image names to create. Semicolon (;) delimited.
|
||||
default: ""
|
||||
steps:
|
||||
- restore_cache:
|
||||
key: pack-cache-<< parameters.image-name >>-<< parameters.builder >>-{{ arch }}
|
||||
- run:
|
||||
name: Run pack build
|
||||
environment:
|
||||
PARAM_BUILDER: << parameters.builder >>
|
||||
PARAM_IMAGE_NAME: << parameters.image-name >>
|
||||
PARAM_PATH: << parameters.path >>
|
||||
PARAM_BUILDPACKS: << parameters.buildpacks >>
|
||||
PARAM_ENV_VARS: << parameters.env-vars >>
|
||||
PARAM_TAGS: << parameters.tags >>
|
||||
command: <<include(scripts/pack-build.sh)>>
|
||||
- save_cache:
|
||||
key: pack-cache-<< parameters.image-name >>-<< parameters.builder >>-{{ arch }}-{{ epoch }}
|
||||
paths:
|
||||
- /var/lib/docker/volumes/
|
|
@ -0,0 +1,17 @@
|
|||
description: "Save image to file"
|
||||
parameters:
|
||||
image-name:
|
||||
type: string
|
||||
image-file:
|
||||
type: string
|
||||
steps:
|
||||
- run:
|
||||
name: Save image to workspace
|
||||
environment:
|
||||
PARAM_IMAGE_NAME: << parameters.image-name >>
|
||||
PARAM_IMAGE_FILE: << parameters.image-file >>
|
||||
command: <<include(scripts/save-image-to-workspace.sh)>>
|
||||
- persist_to_workspace:
|
||||
root: .
|
||||
paths:
|
||||
- ./
|
|
@ -0,0 +1,12 @@
|
|||
description: Basic usage
|
||||
|
||||
usage:
|
||||
version: 2.1
|
||||
orbs:
|
||||
buildpacks: buildpacks/pack@x.y.z
|
||||
workflows:
|
||||
main:
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
builder: heroku/builder:22
|
|
@ -0,0 +1,26 @@
|
|||
description: Build and publish
|
||||
|
||||
usage:
|
||||
version: 2.1
|
||||
orbs:
|
||||
buildpacks: buildpacks/pack@x.y.z
|
||||
workflows:
|
||||
main:
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
image-file: myimage.tgz
|
||||
builder: heroku/builder:22
|
||||
- publish:
|
||||
requires:
|
||||
- buildpacks/build
|
||||
jobs:
|
||||
publish:
|
||||
machine: true
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: /tmp/workspace
|
||||
- run:
|
||||
command: |
|
||||
docker load -i /tmp/workspace/images/myimage.tgz
|
||||
docker push myimage
|
|
@ -0,0 +1,13 @@
|
|||
description: Run specific buildpacks
|
||||
|
||||
usage:
|
||||
version: 2.1
|
||||
orbs:
|
||||
buildpacks: buildpacks/pack@x.y.z
|
||||
workflows:
|
||||
main:
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
builder: heroku/builder:22
|
||||
buildpack: heroku/ruby
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
create_buildpack_flags() {
|
||||
local flags=()
|
||||
IFS=';' read -ra entries <<<"$1"
|
||||
for entry in "${entries[@]}"; do
|
||||
flags+=("--buildpack \"${entry}\"")
|
||||
done
|
||||
|
||||
echo "${flags[@]}"
|
||||
}
|
||||
|
||||
create_env_var_flags() {
|
||||
local flags=()
|
||||
IFS=';' read -ra entries <<<"$1"
|
||||
for entry in "${entries[@]}"; do
|
||||
IFS='=' read -ra parts <<<"$entry"
|
||||
flags+=("--env ${parts[0]}=\"${parts[1]}\"")
|
||||
done
|
||||
|
||||
echo "${flags[@]}"
|
||||
}
|
||||
|
||||
create_path_flag() {
|
||||
if [ -n "$1" ]; then
|
||||
echo "--path \"$1\""
|
||||
fi
|
||||
}
|
||||
|
||||
create_tag_flags() {
|
||||
local flags=()
|
||||
IFS=';' read -ra entries <<<"$1"
|
||||
for entry in "${entries[@]}"; do
|
||||
flags+=("--tag \"${entry}\"")
|
||||
done
|
||||
|
||||
echo "${flags[@]}"
|
||||
}
|
||||
|
||||
create_command() {
|
||||
for i in PARAM_BUILDER,builder PARAM_IMAGE_NAME,image-name; do
|
||||
KEY=${i%,*}
|
||||
VAL=${i#*,}
|
||||
|
||||
if [[ -z "${!KEY}" ]]; then
|
||||
echo "param '${VAL}' is required!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo pack build \
|
||||
--no-color \
|
||||
--builder \"${PARAM_BUILDER}\" \
|
||||
--trust-builder \
|
||||
$(create_path_flag "${PARAM_PATH}") \
|
||||
$(create_buildpack_flags "${PARAM_BUILDPACKS}") \
|
||||
$(create_env_var_flags "${PARAM_ENV_VARS}") \
|
||||
$(create_tag_flags "${PARAM_TAGS}") \
|
||||
\"${PARAM_IMAGE_NAME}\"
|
||||
}
|
||||
|
||||
main() {
|
||||
eval $(create_command)
|
||||
}
|
||||
|
||||
if [[ -n $(echo "$0" | sed 's/.*_test$//;s/.*_test\.sh$//') ]]; then
|
||||
main "$@"
|
||||
fi
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
main() {
|
||||
for i in PARAM_IMAGE_FILE,image-file PARAM_IMAGE_NAME,image-name; do
|
||||
KEY=${i%,*}
|
||||
VAL=${i#*,}
|
||||
|
||||
if [[ -z "${!KEY}" ]]; then
|
||||
echo "param ${VAL} is required!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
local image_dir="${IMAGE_DIR:-images}"
|
||||
echo "> Ensuring image dir '${image_dir}' exists..."
|
||||
mkdir -p "$image_dir"
|
||||
|
||||
local full_image_path="${image_dir}/${PARAM_IMAGE_FILE}"
|
||||
echo "> Exporting image '${PARAM_IMAGE_NAME}' as '${full_image_path}'..."
|
||||
docker save -o "${full_image_path}" ${PARAM_IMAGE_NAME}
|
||||
echo "> Saved as '${full_image_path}'..."
|
||||
}
|
||||
|
||||
if [[ -n $(echo "$0" | sed 's/.*_test$//;s/.*_test\.sh$//') ]]; then
|
||||
main "$@"
|
||||
fi
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
testBuildpackFlagsWithNoValues() {
|
||||
local values=""
|
||||
local results=$(create_buildpack_flags "${values}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertEquals "$results" ""
|
||||
}
|
||||
|
||||
testBuildpackFlagsWithValues() {
|
||||
local values="my-buildpack@1.2.3;docker.io/org/other-buildpack:latest"
|
||||
local results=$(create_buildpack_flags "${values}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertContains "$results" "--buildpack \"my-buildpack@1.2.3\""
|
||||
assertContains "$results" "--buildpack \"docker.io/org/other-buildpack:latest\""
|
||||
}
|
||||
|
||||
testEnvVarsFlagsWithNoValues() {
|
||||
local values=""
|
||||
local results=$(create_env_var_flags "${values}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertEquals "$results" ""
|
||||
}
|
||||
|
||||
testEnvVarsFlagsWithValues() {
|
||||
local values="ENV_1=VAL_1;ENV_2=VAL 2;"
|
||||
local results=$(create_env_var_flags "${values}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertContains "$results" "--env ENV_1=\"VAL_1\""
|
||||
assertContains "$results" "--env ENV_2=\"VAL 2\""
|
||||
}
|
||||
|
||||
testPathFlagWithNoValue() {
|
||||
local value=""
|
||||
local results=$(create_path_flag "${value}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertEquals "$results" ""
|
||||
}
|
||||
|
||||
testPathFlagWithValue() {
|
||||
local value="some/nested/dir"
|
||||
local results=$(create_path_flag "${value}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertContains "$results" "--path \"some/nested/dir\""
|
||||
}
|
||||
|
||||
testTagFlagsWithNoValues() {
|
||||
local values=""
|
||||
local results=$(create_tag_flags "${values}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertEquals "$results" ""
|
||||
}
|
||||
|
||||
testTagFlagsWithValues() {
|
||||
local values="my-image;docker.io/org/image:2"
|
||||
local results=$(create_tag_flags "${values}") code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertContains "$results" "--tag \"my-image\""
|
||||
assertContains "$results" "--tag \"docker.io/org/image:2\""
|
||||
}
|
||||
|
||||
testCreateCommandMissingBuilder() {
|
||||
local results=$(create_command) code="$?"
|
||||
assertEquals 1 "$code"
|
||||
assertContains "$results" "param 'builder' is required!"
|
||||
}
|
||||
|
||||
testCreateCommandMissingImageName() {
|
||||
local results=$(PARAM_BUILDER=some-builder create_command) code="$?"
|
||||
assertEquals 1 "$code"
|
||||
assertContains "$results" "param 'image-name' is required!"
|
||||
}
|
||||
|
||||
testCreateCommandFull() {
|
||||
local results=$(PARAM_BUILDER=some-builder PARAM_IMAGE_NAME=some/image:latest PARAM_PATH=some/dir PARAM_BUILDPACKS=my-buildpack@1.2.3 PARAM_ENV_VARS="ENV_1=VAL_1" PARAM_TAGS="another/tag:2" create_command) code="$?"
|
||||
assertEquals 0 "$code"
|
||||
assertEquals 'pack build --no-color --builder "some-builder" --path "some/dir" --buildpack "my-buildpack@1.2.3" --env ENV_1="VAL_1" --tag "another/tag:2" "some/image:latest"' "$results"
|
||||
}
|
||||
|
||||
oneTimeSetUp() {
|
||||
echo "> Loading script under test..."
|
||||
source './../scripts/pack-build.sh'
|
||||
}
|
||||
|
||||
# Load shUnit2
|
||||
. ./shunit2
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
testParamImageFileRequired() {
|
||||
local results="$(PARAM_IMAGE_NAME='name' main)" code="$?"
|
||||
assertEquals 1 $code
|
||||
assertContains "$results" "param image-file is required!"
|
||||
}
|
||||
|
||||
testParamImageNameRequired() {
|
||||
local results="$(PARAM_IMAGE_FILE='file' main)" code="$?"
|
||||
assertEquals 1 $code
|
||||
assertContains "$results" "param image-name is required!"
|
||||
}
|
||||
|
||||
testImageFileIsCreated() {
|
||||
cat <<EOF >${SHUNIT_TMPDIR}/Dockerfile
|
||||
FROM busybox AS build-env
|
||||
RUN touch /empty
|
||||
|
||||
FROM scratch
|
||||
COPY --from=build-env /empty /.emptyfile
|
||||
EOF
|
||||
|
||||
local image_name="test$RANDOM"
|
||||
echo "> Creating docker image..."
|
||||
docker build -t ${image_name} ${SHUNIT_TMPDIR}
|
||||
|
||||
local image_dir="${SHUNIT_TMPDIR}/images"
|
||||
local results="$(IMAGE_DIR=$image_dir PARAM_IMAGE_NAME=$image_name PARAM_IMAGE_FILE='image.img' main)" code="$?"
|
||||
assertEquals 0 $code
|
||||
assertContains "$results" "$image_dir"
|
||||
assertContains "$results" "$image_name"
|
||||
|
||||
ls -al $image_dir/image.img
|
||||
}
|
||||
|
||||
oneTimeSetUp() {
|
||||
echo "> Loading script under test..."
|
||||
source './../scripts/save-image-to-workspace.sh'
|
||||
}
|
||||
|
||||
# Load shUnit2
|
||||
. ./shunit2
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue