Compare commits
46 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 |
|
@ -2,7 +2,7 @@ version: 2.1
|
|||
|
||||
# Orb depedencies
|
||||
orbs:
|
||||
orb-tools: circleci/orb-tools@9.1.0
|
||||
orb-tools: circleci/orb-tools@10.0.3
|
||||
## used for integration tests
|
||||
buildpacks: buildpacks/pack@<<pipeline.parameters.dev-orb-version>>
|
||||
|
||||
|
@ -24,9 +24,17 @@ parameters:
|
|||
|
||||
# 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-2004:202010-01
|
||||
image: ubuntu-2204:2023.04.2
|
||||
steps:
|
||||
- run:
|
||||
name: Install releaser
|
||||
|
@ -75,16 +83,31 @@ workflows:
|
|||
when: << pipeline.parameters.run-integration-tests >>
|
||||
jobs:
|
||||
- buildpacks/build:
|
||||
working-directory: samples/apps/ruby-bundler
|
||||
name: "Minimal"
|
||||
builder: cnbs/sample-builder:bionic
|
||||
image-name: test-image
|
||||
builder: heroku/buildpacks:18
|
||||
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
|
||||
- orb-tools/pack
|
||||
- test
|
||||
- orb-tools/pack:
|
||||
use-orb-pack: true
|
||||
- orb-tools/publish-dev:
|
||||
orb-name: buildpacks/pack
|
||||
requires:
|
||||
|
@ -112,6 +135,7 @@ workflows:
|
|||
unless: << pipeline.parameters.run-integration-tests >>
|
||||
jobs:
|
||||
- orb-tools/pack:
|
||||
use-orb-pack: true
|
||||
filters:
|
||||
branches:
|
||||
ignore: /.*/
|
||||
|
|
|
@ -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,6 @@
|
|||
extends: relaxed
|
||||
|
||||
rules:
|
||||
line-length:
|
||||
max: 200
|
||||
allow-non-breakable-inline-mappings: true
|
|
@ -12,4 +12,12 @@
|
|||
|
||||
```
|
||||
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
|
||||
```
|
||||
|
|
21
Makefile
21
Makefile
|
@ -1,11 +1,28 @@
|
|||
BRANCH?=$(shell git branch --show-current)
|
||||
VERSION?=$(shell echo $(BRANCH) | grep "^release" | sed 's;release\/\(.*\);\1;')
|
||||
|
||||
.PHONY: validate
|
||||
.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..."
|
||||
|
@ -26,4 +43,4 @@ generate-changelog:
|
|||
@awk 'n>=3 { print a[n%3] } { a[n++%3]=$$0 }' "$(TMP_DIR)/CHANGELOG.md" > CHANGELOG.md
|
||||
|
||||
@echo "> CHANGELOG:"
|
||||
@cat CHANGELOG.md
|
||||
@cat CHANGELOG.md
|
||||
|
|
106
src/@orb.yml
106
src/@orb.yml
|
@ -11,32 +11,36 @@ jobs:
|
|||
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: ""
|
||||
image-name:
|
||||
buildpacks:
|
||||
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.
|
||||
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.18.1
|
||||
default: 0.29.0
|
||||
after-checkout:
|
||||
description: Optional steps to run after checking out the code.
|
||||
type: steps
|
||||
|
@ -44,7 +48,7 @@ jobs:
|
|||
executor-image:
|
||||
type: string
|
||||
description: Image to execute 'pack' in.
|
||||
default: ubuntu-2004:202010-01
|
||||
default: ubuntu-2204:2023.04.2
|
||||
steps:
|
||||
- run: sudo chown -R circleci /var/lib/docker/volumes
|
||||
- install-pack:
|
||||
|
@ -55,78 +59,16 @@ jobs:
|
|||
condition: << parameters.after-checkout >>
|
||||
steps: << parameters.after-checkout >>
|
||||
- pack-build:
|
||||
working-directory: << parameters.working-directory >>
|
||||
image-name: << parameters.image-name >>
|
||||
builder: << parameters.builder >>
|
||||
buildpack: << parameters.buildpack >>
|
||||
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:
|
||||
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 --no-color << 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:
|
||||
|
@ -137,13 +79,13 @@ commands:
|
|||
type: string
|
||||
version:
|
||||
type: string
|
||||
default: 0.18.1
|
||||
default: 0.29.0
|
||||
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 >>
|
||||
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
|
||||
|
|
|
@ -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:
|
||||
- ./
|
|
@ -9,4 +9,4 @@ usage:
|
|||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
builder: heroku/buildpacks:18
|
||||
builder: heroku/builder:22
|
||||
|
|
|
@ -10,7 +10,7 @@ usage:
|
|||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
image-file: myimage.tgz
|
||||
builder: heroku/buildpacks:18
|
||||
builder: heroku/builder:22
|
||||
- publish:
|
||||
requires:
|
||||
- buildpacks/build
|
||||
|
|
|
@ -9,5 +9,5 @@ usage:
|
|||
jobs:
|
||||
- buildpacks/build:
|
||||
image-name: myimage
|
||||
builder: heroku/buildpacks:18
|
||||
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