Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create local script to replace existing local dev scripts #1295

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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

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

function generate_kbld_config_pack() {
chenbh marked this conversation as resolved.
Show resolved Hide resolved
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() {
kbld_config_path=$1
ko_config_path=$2
registry=$3

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

cat <<EOT > $kbld_config_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

prefix="github.com/pivotal/kpack/pkg/apis/build/v1alpha2"
cat <<EOT > $ko_config_path
defaultBaseImage: paketobuildpacks/run-jammy-tiny

builds:
- id: controller
ldflags:
- -X ${prefix}.CompletionCommand=/ko-app/completion
- -X ${prefix}.PrepareCommand=/ko-app/build-init
- -X ${prefix}.RebaseCommand=/ko-app/rebase
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"
ko_config_path="${temp_dir}/.ko.yaml"
if [ $type = "ko" ]; then
Copy link
Contributor

@sambhav sambhav Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to support both types? Should we just use the one that is better suited here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason I added both was a bit of a proof of concept. Inside VMware we have some teams that use ko, but are experimenting with using buildpacks, so I was trying to show a way that you could build the same image with either ko or pack.

Which one has the best developer experience is a bit tough to answer since it depends a bit on what you're doing. Iterating locally, ko will be a bit quicker since there is no docker involved, but it is very dependent on your local environment. Building with pack will replicate our ci so as a developer you can have confidence that the changes you are working on locally will behave the same in ci.

I personally think there is room for both, but if I had to chose one I would pick pack because consistency would be more important to me than speed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trade off is pack is what we use to generate our actual releases (and something-something dog fooding), so you would use it to get as close as possible to the release process/candidate. On the other hand, ko is fast, like 1 min vs 7-10 min. The difference is even greater when both are started from empty caches.

generate_kbld_config_ko $kbld_config_path $ko_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 | KO_CONFIG_PATH="$ko_config_path" kbld -f $kbld_config_path -f- > $output
}
67 changes: 0 additions & 67 deletions hack/common.sh

This file was deleted.

Loading