Compare commits

..

No commits in common. "main" and "0.2.2" have entirely different histories.
main ... 0.2.2

24 changed files with 243 additions and 2072 deletions

View File

@ -1,124 +1,19 @@
version: 2.1
# Orb depedencies
orbs:
orb-tools: circleci/orb-tools@10.0.3
## used for integration tests
buildpacks: buildpacks/pack@<<pipeline.parameters.dev-orb-version>>
orb-tools: circleci/orb-tools@9.1.0
# 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:
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
- 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:
@ -132,23 +27,43 @@ workflows:
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+$/
- orb-tools/publish:
orb-ref: buildpacks/pack@$CIRCLE_TAG
attach-workspace: true
checkout: false
orb-path: orb.yml
publish-token-variable: CIRCLE_TOKEN
filters:
branches:
ignore: /.*/
tags:
only: /^\d+\.\d+\.\d+$/
requires:
- orb-tools/pack
jobs:
github-release:
machine:
image: ubuntu-2004:202010-01
steps:
- run:
name: Install generator
command: gem install github_changelog_generator
- run:
name: Install releaser
command: go get -u github.com/tcnksm/ghr
- checkout
- run:
name: Determine version
command: |
[[ $CIRCLE_BRANCH =~ ^release/(.*)$ ]] && echo -n ${BASH_REMATCH[1]} > VERSION || (echo "failed to determine version" && exit 99)
cat VERSION
- run:
name: Generate changelog
command: |
github_changelog_generator --user $CIRCLE_PROJECT_USERNAME --project $CIRCLE_PROJECT_REPONAME --token $GITHUB_BOT_PAT --future-release $(cat VERSION) -o CHANGELOG.tmp.md
# remove footer
head -n -3 CHANGELOG.tmp.md > CHANGELOG.md
cat CHANGELOG.md
- run:
name: Create GH release
command: |
VERSION=$(cat VERSION)
ghr -draft -t $GITHUB_BOT_PAT -c $CIRCLE_SHA1 -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME -b "$(cat CHANGELOG.md)" -n "pack-orb ${VERSION}" $VERSION

View File

@ -1,8 +0,0 @@
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
[Makefile]
indent_style = tab

View File

@ -1,27 +0,0 @@
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

View File

@ -1,18 +1,6 @@
## 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
bugs-label=Fixes:
bug-labels=type/bug
pr-label=### Other Changes
header-label=## Changelog
usernames-as-github-logins=true

2
.gitignore vendored
View File

@ -1,3 +1 @@
# generated during release workflow
CHANGELOG.md
VERSION

View File

@ -1,6 +0,0 @@
extends: relaxed
rules:
line-length:
max: 200
allow-non-breakable-inline-mappings: true

View File

@ -1,31 +0,0 @@
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

View File

@ -1,23 +0,0 @@
## 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
```

View File

@ -1,46 +0,0 @@
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

View File

@ -10,10 +10,9 @@ 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).
## Contributing
## Releasing
We ❤ contributions.
- [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.
1. Create a `release/<#.#.#>` branch
- `<#.#.#>` will be the version released
2. Check [CircleCI](https://circleci.com/gh/buildpacks/pack-orb) to manually approve the release workflow.
3. Check [releases](https://github.com/buildpacks/pack-orb/releases) and publish release draft.

View File

@ -1,19 +0,0 @@
## 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`.

1
VERSION Normal file
View File

@ -0,0 +1 @@
0.2.2

198
orb.yml Normal file
View File

@ -0,0 +1,198 @@
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:
image: << parameters.executor-image >>
parameters:
working-directory:
type: string
description: The directory where the app source is located.
image-name:
type: string
description: Image name (aka tag) of the app image to be produced.
image-file:
type: string
description: Filename to save the app image as locally.
default: "image.tgz"
builder:
type: string
description: Builder image name to use.
buildpack:
type: string
description: Explicit buildpack to use for building.
default: ""
env-vars:
type: string
description: Build-time environment variables. Semicolon (;) delimited.
default: ""
version:
type: string
description: Version of 'pack' to use.
default: 0.13.1
executor-image:
type: string
description: Image to execute 'pack' in.
default: ubuntu-2004:202010-01
steps:
- run: sudo chown -R circleci /var/lib/docker/volumes
- install-pack:
version: << parameters.version >>
- checkout
- pack-build:
working-directory: << parameters.working-directory >>
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:
working-directory:
type: string
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
WORKING_DIRECTORY=$(if [ -n "<< parameters.working-directory >>" ]; then echo -n "--path << parameters.working-directory >>"; else echo -n ""; fi)
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 >> "${WORKING_DIRECTORY}" "${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

View File

@ -1,93 +0,0 @@
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

View File

@ -1,41 +0,0 @@
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/

View File

@ -1,17 +0,0 @@
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:
- ./

View File

@ -1,12 +0,0 @@
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

View File

@ -1,26 +0,0 @@
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

View File

@ -1,13 +0,0 @@
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

View File

@ -1,68 +0,0 @@
#!/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

View File

@ -1,26 +0,0 @@
#!/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

View File

@ -1,86 +0,0 @@
#!/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

View File

@ -1,43 +0,0 @@
#!/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