Skip to content

Commit

Permalink
Use Go tools to gather license files
Browse files Browse the repository at this point in the history
Issue: [ch11840]
See: 02f2c25
  • Loading branch information
cbandy committed Jun 28, 2021
1 parent fd6d188 commit 5dee24a
Show file tree
Hide file tree
Showing 57 changed files with 52 additions and 5,041 deletions.
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -158,7 +158,7 @@ endif

pgo-base: pgo-base-$(IMGBUILDER)

pgo-base-build: $(PGOROOT)/build/pgo-base/Dockerfile
pgo-base-build: $(PGOROOT)/build/pgo-base/Dockerfile licenses
$(IMGCMDSTEM) \
-f $(PGOROOT)/build/pgo-base/Dockerfile \
-t $(PGO_IMAGE_PREFIX)/pgo-base:$(PGO_IMAGE_TAG) \
Expand Down Expand Up @@ -258,3 +258,8 @@ generate-rbac:
hack/tools/envtest: SHELL = bash
hack/tools/envtest:
source '$(shell $(GO) list -f '{{ .Dir }}' -m 'sigs.k8s.io/controller-runtime')/hack/setup-envtest.sh' && fetch_envtest_tools $@

.PHONY: license licenses
license: licenses
licenses:
./bin/license_aggregator.sh ./cmd/...
45 changes: 45 additions & 0 deletions bin/license_aggregator.sh
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

# Copyright 2021 Crunchy Data Solutions, Inc.
# 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 -eu

# Inputs / outputs
IN_PACKAGES=("$@")
OUT_DIR=licenses

# Clean up before we start our work
rm -rf ${OUT_DIR:?}/*/

# Download dependencies of the requested packages, excluding the main module.
# - https://golang.org/ref/mod#glos-main-module
module=$(go list -m)
modules=$(go list -deps -f '{{with .Module}}{{.Path}}{{"\t"}}{{.Dir}}{{end}}' "${IN_PACKAGES[@]}")
dependencies=$(grep -v "^${module}" <<< "${modules}")

while IFS=$'\t' read -r module directory; do
licenses=$(find "${directory}" -type f -ipath '*license*' -not -name '*.go')
[ -n "${licenses}" ] || continue

while IFS= read -r license; do
# Replace the local module directory with the module path.
# - https://golang.org/ref/mod#module-path
relative="${module}${license:${#directory}}"

# Copy the license file with the same layout as the module.
destination="${OUT_DIR}/${relative%/*}"
install -d "${destination}"
install -m 0644 "${license}" "${destination}"
done <<< "${licenses}"
done <<< "${dependencies}"
1 change: 0 additions & 1 deletion build/pgo-base/Dockerfile
Expand Up @@ -18,7 +18,6 @@ LABEL vendor="Crunchy Data" \
io.openshift.tags="postgresql,postgres,sql,nosql,crunchy" \
io.k8s.description="Trusted open source PostgreSQL-as-a-Service"

COPY redhat/licenses /licenses
COPY redhat/atomic/help.1 /help.1
COPY redhat/atomic/help.md /help.md
COPY licenses /licenses
Expand Down
1 change: 1 addition & 0 deletions licenses/.gitignore
@@ -0,0 +1 @@
*
File renamed without changes.
12 changes: 0 additions & 12 deletions licenses/github.com/PuerkitoBio/purell/LICENSE

This file was deleted.

27 changes: 0 additions & 27 deletions licenses/github.com/PuerkitoBio/urlesc/LICENSE

This file was deleted.

21 changes: 0 additions & 21 deletions licenses/github.com/cpuguy83/go-md2man/LICENSE.md

This file was deleted.

15 changes: 0 additions & 15 deletions licenses/github.com/davecgh/go-spew/LICENSE

This file was deleted.

191 changes: 0 additions & 191 deletions licenses/github.com/docker/spdystream/LICENSE

This file was deleted.

22 changes: 0 additions & 22 deletions licenses/github.com/emicklei/go-restful/LICENSE

This file was deleted.

0 comments on commit 5dee24a

Please sign in to comment.