Skip to content

Commit 5dee24a

Browse files
committed
Use Go tools to gather license files
Issue: [ch11840] See: 02f2c25
1 parent fd6d188 commit 5dee24a

File tree

57 files changed

+52
-5041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+52
-5041
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ endif
158158

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

161-
pgo-base-build: $(PGOROOT)/build/pgo-base/Dockerfile
161+
pgo-base-build: $(PGOROOT)/build/pgo-base/Dockerfile licenses
162162
$(IMGCMDSTEM) \
163163
-f $(PGOROOT)/build/pgo-base/Dockerfile \
164164
-t $(PGO_IMAGE_PREFIX)/pgo-base:$(PGO_IMAGE_TAG) \
@@ -258,3 +258,8 @@ generate-rbac:
258258
hack/tools/envtest: SHELL = bash
259259
hack/tools/envtest:
260260
source '$(shell $(GO) list -f '{{ .Dir }}' -m 'sigs.k8s.io/controller-runtime')/hack/setup-envtest.sh' && fetch_envtest_tools $@
261+
262+
.PHONY: license licenses
263+
license: licenses
264+
licenses:
265+
./bin/license_aggregator.sh ./cmd/...

bin/license_aggregator.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2021 Crunchy Data Solutions, Inc.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eu
17+
18+
# Inputs / outputs
19+
IN_PACKAGES=("$@")
20+
OUT_DIR=licenses
21+
22+
# Clean up before we start our work
23+
rm -rf ${OUT_DIR:?}/*/
24+
25+
# Download dependencies of the requested packages, excluding the main module.
26+
# - https://golang.org/ref/mod#glos-main-module
27+
module=$(go list -m)
28+
modules=$(go list -deps -f '{{with .Module}}{{.Path}}{{"\t"}}{{.Dir}}{{end}}' "${IN_PACKAGES[@]}")
29+
dependencies=$(grep -v "^${module}" <<< "${modules}")
30+
31+
while IFS=$'\t' read -r module directory; do
32+
licenses=$(find "${directory}" -type f -ipath '*license*' -not -name '*.go')
33+
[ -n "${licenses}" ] || continue
34+
35+
while IFS= read -r license; do
36+
# Replace the local module directory with the module path.
37+
# - https://golang.org/ref/mod#module-path
38+
relative="${module}${license:${#directory}}"
39+
40+
# Copy the license file with the same layout as the module.
41+
destination="${OUT_DIR}/${relative%/*}"
42+
install -d "${destination}"
43+
install -m 0644 "${license}" "${destination}"
44+
done <<< "${licenses}"
45+
done <<< "${dependencies}"

build/pgo-base/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ LABEL vendor="Crunchy Data" \
1818
io.openshift.tags="postgresql,postgres,sql,nosql,crunchy" \
1919
io.k8s.description="Trusted open source PostgreSQL-as-a-Service"
2020

21-
COPY redhat/licenses /licenses
2221
COPY redhat/atomic/help.1 /help.1
2322
COPY redhat/atomic/help.md /help.md
2423
COPY licenses /licenses

licenses/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*
File renamed without changes.

licenses/github.com/PuerkitoBio/purell/LICENSE

-12
This file was deleted.

licenses/github.com/PuerkitoBio/urlesc/LICENSE

-27
This file was deleted.

licenses/github.com/cpuguy83/go-md2man/LICENSE.md

-21
This file was deleted.

licenses/github.com/davecgh/go-spew/LICENSE

-15
This file was deleted.

licenses/github.com/docker/spdystream/LICENSE

-191
This file was deleted.

licenses/github.com/emicklei/go-restful/LICENSE

-22
This file was deleted.

0 commit comments

Comments
 (0)