Skip to content

Commit

Permalink
skaffold: Rebuild when there are changes to go:embed files (#57)
Browse files Browse the repository at this point in the history
* skaffold: Rebuild when there are changes to `go:embed` files

Currently, the ko builder does not detect changes to `go:embed` files (see GoogleContainerTools/skaffold#7836). This makes impossible the development of some scripts that are used later by `go:embed`.
This PR inspires from gardener/gardener#6735 and gardener/gardener#6781 and does the same setup for the registry-cache extension.

* Add skaffold dependency

---------

Co-authored-by: Dimitar Kostadinov <[email protected]>
  • Loading branch information
ialidzhikov and dimitar-kostadinov authored Oct 6, 2023
1 parent c7ba18f commit 31cdc3c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ check-generate:
@$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/check-generate.sh $(REPO_ROOT)

.PHONY: check
check: $(GOIMPORTS) $(GOLANGCI_LINT) $(HELM)
check: $(GOIMPORTS) $(GOLANGCI_LINT) $(HELM) $(YQ)
@$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/check.sh --golangci-lint-config=./.golangci.yaml ./cmd/... ./pkg/... ./test/...
@$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/check-charts.sh ./charts
@hack/check-skaffold-deps.sh

.PHONY: generate
generate: $(CONTROLLER_GEN) $(GEN_CRD_API_REFERENCE_DOCS) $(HELM) $(YQ)
Expand Down
79 changes: 79 additions & 0 deletions hack/check-skaffold-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
#
# Copyright 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

echo "> Check Skaffold Dependencies"

check_successful=true

out_dir=$(mktemp -d)
function cleanup_output {
rm -rf "$out_dir"
}
trap cleanup_output EXIT

function check() {
skaffold_file="$1"
binary_name="$2"
skaffold_config_name="$3"

skaffold_yaml="$(cat "$(dirname "$0")/../$skaffold_file")"

path_current_skaffold_dependencies="${out_dir}/current-$skaffold_file-deps-$binary_name.txt"
path_actual_dependencies="${out_dir}/actual-$skaffold_file-deps-$binary_name.txt"

echo "$skaffold_yaml" |\
yq eval "select(.metadata.name == \"$skaffold_config_name\") | .build.artifacts[] | select(.ko.main == \"./cmd/$binary_name\") | .ko.dependencies.paths[]?" - |\
sort |\
uniq > "$path_current_skaffold_dependencies"

go list -f '{{ join .Deps "\n" }}' "./cmd/$binary_name" |\
grep "github.com/gardener/gardener-extension-registry-cache/" |\
sed 's/github\.com\/gardener\/gardener-extension-registry-cache\///g' |\
sort |\
uniq > "$path_actual_dependencies"

# always add vendor directory and VERSION file
echo "vendor" >> "$path_actual_dependencies"
echo "VERSION" >> "$path_actual_dependencies"

# sort dependencies
sort -o $path_current_skaffold_dependencies{,}
sort -o $path_actual_dependencies{,}

echo -n ">> Checking defined dependencies in Skaffold config '$skaffold_config_name' for '$binary_name' in '$skaffold_file'..."
if ! diff="$(diff "$path_current_skaffold_dependencies" "$path_actual_dependencies")"; then
check_successful=false

echo
echo ">>> The following actual dependencies are missing in $skaffold_file (need to be added):"
echo "$diff" | grep '>' | awk '{print $2}'
echo
echo ">>> The following dependencies defined in $skaffold_file are not needed actually (need to be removed):"
echo "$diff" | grep '<' | awk '{print $2}'
echo
else
echo " success."
fi
}

check "skaffold.yaml" "gardener-extension-registry-cache" "extension"
check "skaffold.yaml" "gardener-extension-registry-cache-admission" "admission"

if [ "$check_successful" = false ] ; then
exit 1
fi
32 changes: 32 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ build:
artifacts:
- image: eu.gcr.io/gardener-project/gardener/extensions/registry-cache
ko:
dependencies:
paths:
- charts
- cmd/gardener-extension-registry-cache/app
- pkg/apis/config
- pkg/apis/config/v1alpha1
- pkg/apis/config/validation
- pkg/apis/registry
- pkg/apis/registry/install
- pkg/apis/registry/v1alpha1
- pkg/apis/registry/v1alpha1/helper
- pkg/cmd
- pkg/component/registrycaches
- pkg/constants
- pkg/controller/extension
- pkg/imagevector
- pkg/utils/registry
- pkg/webhook/operatingsystemconfig
- vendor
- VERSION
main: ./cmd/gardener-extension-registry-cache
resourceSelector:
allow:
Expand All @@ -27,6 +47,18 @@ build:
artifacts:
- image: eu.gcr.io/gardener-project/gardener/extensions/registry-cache-admission
ko:
dependencies:
paths:
- cmd/gardener-extension-registry-cache-admission/app
- pkg/admission/cmd
- pkg/admission/validator
- pkg/apis/registry
- pkg/apis/registry/install
- pkg/apis/registry/v1alpha1
- pkg/apis/registry/validation
- pkg/constants
- vendor
- VERSION
main: ./cmd/gardener-extension-registry-cache-admission
deploy:
helm:
Expand Down

0 comments on commit 31cdc3c

Please sign in to comment.