Skip to content

Commit

Permalink
Create local script to replace existing local dev scripts
Browse files Browse the repository at this point in the history
- Support building with pack or ko locally

Signed-off-by: Tom Kennedy <[email protected]>
  • Loading branch information
tomkennedy513 committed Sep 27, 2023
1 parent 2a98bed commit e39eab1
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 107 deletions.
5 changes: 2 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ You'll also need:

```bash
kubectl cluster-info # ensure you have access to a cluster
docker login <registry namespace> # must be writable and publicly accessible; e.g., your Docker Hub username or gcr.io/<some-project>
./hack/apply.sh <registry namespace>
./hack/local.sh --help #this will provide all options for building/deploying kpack
```

#### When using private registries
Expand Down Expand Up @@ -85,7 +84,7 @@ make unit
* 🍿 These tests can take anywhere from 20-30 minutes depending on your setup

```bash
IMAGE_REGISTRY=gcr.io/<some-project> \
IMAGE_REGISTRY=gcr.io/<some-project> \
IMAGE_REGISTRY_USERNAME=_json_key \
IMAGE_REGISTRY_PASSWORD=$(cat gcp.json) \
make e2e
Expand Down
18 changes: 0 additions & 18 deletions hack/apply.sh

This file was deleted.

203 changes: 203 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#!/bin/bash

function lifecycle_image_build() {
image=$1
go run hack/lifecycle/main.go --tag=${image}
}

function generate_kbld_config_pack() {
path=$1
registry=$2

controller_args=("--env" "BP_GO_TARGETS=./cmd/controller")
controller_args+=($buildArgs)
controller_args="${controller_args[@]}";

webhook_args=("--env" "BP_GO_TARGETS=./cmd/webhook")
webhook_args+=($buildArgs)
webhook_args="${webhook_args[@]}";

build_init_args=("--env" "BP_GO_TARGETS=./cmd/build-init")
build_init_args+=($buildArgs)
build_init_args="${build_init_args[@]}";

build_waiter_args=("--env" "BP_GO_TARGETS=./cmd/build-waiter")
build_waiter_args+=($buildArgs)
build_waiter_args="${build_waiter_args[@]}";

rebase_args=("--env" "BP_GO_TARGETS=./cmd/rebase")
rebase_args+=($buildArgs)
rebase_args="${rebase_args[@]}";

completion_args=("--env" "BP_GO_TARGETS=./cmd/completion")
completion_args+=($buildArgs)
completion_args="${completion_args[@]}";

cat <<EOT > $path
apiVersion: kbld.k14s.io/v1alpha1
kind: Config
sources:
- image: controller
path: .
pack:
build:
builder: paketobuildpacks/builder-jammy-tiny
rawOptions: [${controller_args// /,}]
- image: webhook
path: .
pack:
build:
builder: paketobuildpacks/builder-jammy-tiny
rawOptions: [${webhook_args// /,}]
- image: build-init
path: .
pack:
build:
builder: paketobuildpacks/builder-jammy-tiny
rawOptions: [${build_init_args// /,}]
- image: build-waiter
path: .
pack:
build:
builder: paketobuildpacks/builder-jammy-tiny
rawOptions: [${build_waiter_args// /,}]
- image: rebase
path: .
pack:
build:
builder: paketobuildpacks/builder-jammy-tiny
rawOptions: [${rebase_args// /,}]
- image: completion
path: .
pack:
build:
builder: paketobuildpacks/builder-jammy-tiny
rawOptions: [${completion_args// /,}]
overrides:
- image: build-init-windows
newImage: build-init-windows
preresolved: true
- image: completion-windows
newImage: completion-windows
preresolved: true
- image: lifecycle
newImage: $lifecycle_image
destinations:
- image: controller
newImage: $controller_image
- image: webhook
newImage: $webhook_image
- image: build-init
newImage: $build_init_image
- image: build-waiter
newImage: $build_waiter_image
- image: rebase
newImage: $rebase_image
- image: completion
newImage: $completion_image
EOT
}

function generate_kbld_config_ko() {
path=$1
registry=$2

args=("--disable-optimizations")
args+=($buildArgs)
args="${args[@]}";

cat <<EOT > $path
apiVersion: kbld.k14s.io/v1alpha1
kind: Config
sources:
- image: controller
path: cmd/controller
ko:
build:
rawOptions: [${args// /,}]
- image: webhook
path: cmd/webhook
ko:
build:
rawOptions: [${args// /,}]
- image: build-init
path: cmd/build-init
ko:
build:
rawOptions: [${args// /,}]
- image: build-waiter
path: cmd/build-waiter
ko:
build:
rawOptions: [${args// /,}]
- image: rebase
path: cmd/rebase
ko:
build:
rawOptions: [${args// /,}]
- image: completion
path: cmd/completion
ko:
build:
rawOptions: [${args// /,}]
overrides:
- image: build-init-windows
newImage: build-init-windows
preresolved: true
- image: completion-windows
newImage: completion-windows
preresolved: true
- image: lifecycle
newImage: $lifecycle_image
destinations:
- image: controller
newImage: $controller_image
- image: webhook
newImage: $webhook_image
- image: build-init
newImage: $build_init_image
- image: build-waiter
newImage: $build_waiter_image
- image: rebase
newImage: $rebase_image
- image: completion
newImage: $completion_image
EOT
}

function compile() {
type=$1
registry=$2
output=$3

# Overrides registry=$1 for Docker Hub images
# e.g. IMAGE_PREFIX=username/kpack-
IMAGE_PREFIX=${IMAGE_PREFIX:-"${registry}/"}
controller_image=${IMAGE_PREFIX}controller
webhook_image=${IMAGE_PREFIX}webhook
build_init_image=${IMAGE_PREFIX}build-init
build_waiter_image=${IMAGE_PREFIX}build-waiter
rebase_image=${IMAGE_PREFIX}rebase
completion_image=${IMAGE_PREFIX}completion
lifecycle_image=${IMAGE_PREFIX}lifecycle

echo "Building Lifecycle"
lifecycle_image_build ${lifecycle_image}

echo "Generating kbld config"
temp_dir=$(mktemp -d)
kbld_config_path="${temp_dir}/kbld-config"
if [ $type = "ko" ]; then
generate_kbld_config_ko $kbld_config_path $registry
elif [ $type = "pack" ]; then
generate_kbld_config_pack $kbld_config_path $registry
else
echo "invalid build type, either 'pack' or 'ko' is allowed"
exit 1
fi

echo "Building Images"
ytt -f config | kbld -f $kbld_config_path -f- > $output
}
67 changes: 0 additions & 67 deletions hack/common.sh

This file was deleted.

Loading

0 comments on commit e39eab1

Please sign in to comment.