Skip to content

Commit

Permalink
Add platform option to build-stack.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Romero <root@jromero.codes>
  • Loading branch information
jromero committed Mar 3, 2020
1 parent 5024764 commit 70826c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ build-stack-alpine:

build-stack-alpine-x-armv6:
@echo "> Building 'alpine' stack..."
bash stacks/build-stack.sh stacks/alpine-x-armv6
bash stacks/build-stack.sh -o linux/arm/v6 stacks/alpine-x-armv6

build-stack-bionic:
@echo "> Building 'bionic' stack..."
Expand Down
16 changes: 12 additions & 4 deletions stacks/build-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ set -e
ID_PREFIX="io.buildpacks.samples.stacks"

DEFAULT_PREFIX=cnbs/sample-stack
DEFAULT_PLATFORM=linux/amd64

REPO_PREFIX=${DEFAULT_PREFIX}
PLATFORM=${DEFAULT_PLATFORM}

export

usage() {
echo "Usage: "
echo " $0 [-p <prefix>] <dir>"
echo " $0 [-p <prefix>] [-o <platform>] <dir>"
echo " -p prefix to use for images (default: ${DEFAULT_PREFIX})"
echo " -o platform to use for images (default: ${DEFAULT_PLATFORM})"
echo " <dir> directory of stack to build"
exit 1;
}

while getopts "v:p:" o; do
case "${o}" in
while getopts "v:p:o:" opt; do
case "${opt}" in
p)
REPO_PREFIX=${OPTARG}
;;
o)
PLATFORM=${OPTARG}
;;
\?)
echo "Invalid option: -$OPTARG" 1>&2
usage
Expand Down Expand Up @@ -60,7 +68,7 @@ for TYPE in "base" "run" "build"; do
fi

echo "BUILDING ${IMAGE_NAME}..."
docker build --build-arg "base_image=${BASE_IMAGE}" --build-arg "stack_id=${STACK_ID}" -t "${IMAGE_NAME}" "${IMAGE_DIR}/${TYPE}"
docker build --platform "${PLATFORM}" --build-arg "base_image=${BASE_IMAGE}" --build-arg "stack_id=${STACK_ID}" -t "${IMAGE_NAME}" "${IMAGE_DIR}/${TYPE}"
BUILT_IMAGES="${BUILT_IMAGES} ${IMAGE_NAME}"
else
echo "Skipping ${TYPE} due to directory missing..."
Expand Down

0 comments on commit 70826c2

Please sign in to comment.