Skip to content

Commit 1b331ba

Browse files
committed
Clean up build artifacts
- used simple README.md for release instead of the project README.md - output SPIRE binaries under bin/ during `make build` - created release specific configuration files - removed cruft developer configuration files - cleaned up .gitignore a bit for binaries built from various means - cleaned up ldflags options so it was easier to see when a git hash/tag was being passed. - tarball contents are now explicitly defined - no longer root tarball configuration to /opt/spire Signed-off-by: Andrew Harding <[email protected]>
1 parent e4ceb30 commit 1b331ba

17 files changed

+130
-340
lines changed

.gitignore

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99
/test_results
1010
/artifacts
1111
/releases
12+
/bin
1213
bundle.*.pem
1314
svid.*.key
1415
svid.*.pem
1516

16-
17-
cmd/spire-agent/spire-agent
17+
# Ignore binaries built using go build either from the root of the repo or
18+
# within the respective main packages.
19+
/spire-server
20+
/spire-agent
21+
/k8s-workload-registrar
22+
/oidc-discovery-provider
1823
cmd/spire-server/spire-server
24+
cmd/spire-agent/spire-agent
1925
support/k8s/k8s-workload-registrar/k8s-workload-registrar
2026
support/oidc-discovery-provider/oidc-discovery-provider
21-
22-
functional/tools/stresstest/stresstest
23-
functional/tools/tokengenerator/tokengenerator
24-
functional/tools/workload/workload
25-
2627
tools/spire-plugingen/spire-plugingen
2728

2829
# Travis CI encrypted files decryption paths

Dockerfile.images

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ ADD proto/spire/go.mod /spire/proto/spire/go.mod
77
RUN cd /spire && go mod download
88
ADD . /spire
99
WORKDIR /spire
10-
RUN make cmd/spire-server
11-
RUN make cmd/spire-agent
12-
RUN make support/k8s/k8s-workload-registrar
13-
RUN make support/oidc-discovery-provider
10+
RUN make build
1411

1512
# Common base
1613
FROM alpine AS spire-base
@@ -20,28 +17,28 @@ RUN mkdir -p /opt/spire/bin
2017

2118
# SPIRE Server
2219
FROM spire-base AS spire-server
23-
COPY --from=builder /spire/cmd/spire-server/spire-server /opt/spire/bin/spire-server
20+
COPY --from=builder /spire/bin/spire-server /opt/spire/bin/spire-server
2421
WORKDIR /opt/spire
2522
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/spire-server", "run"]
2623
CMD []
2724

2825
# SPIRE Agent
2926
FROM spire-base AS spire-agent
30-
COPY --from=builder /spire/cmd/spire-agent/spire-agent /opt/spire/bin/spire-agent
27+
COPY --from=builder /spire/bin/spire-agent /opt/spire/bin/spire-agent
3128
WORKDIR /opt/spire
3229
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/spire-agent", "run"]
3330
CMD []
3431

3532
# K8S Workload Registrar
3633
FROM spire-base AS k8s-workload-registrar
37-
COPY --from=builder /spire/support/k8s/k8s-workload-registrar/k8s-workload-registrar /opt/spire/bin/k8s-workload-registrar
34+
COPY --from=builder /spire/bin/k8s-workload-registrar /opt/spire/bin/k8s-workload-registrar
3835
WORKDIR /opt/spire
3936
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/k8s-workload-registrar"]
4037
CMD []
4138

4239
# OIDC Discovery Provider
4340
FROM spire-base AS oidc-discovery-provider
44-
COPY --from=builder /spire/support/oidc-discovery-provider/oidc-discovery-provider /opt/spire/bin/oidc-discovery-provider
41+
COPY --from=builder /spire/bin/oidc-discovery-provider /opt/spire/bin/oidc-discovery-provider
4542
WORKDIR /opt/spire
4643
ENTRYPOINT ["/usr/bin/dumb-init", "/opt/spire/bin/oidc-discovery-provider"]
4744
CMD []

Makefile

+27-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ endif
1313
export GO111MODULE=on
1414

1515
# Makefile variables
16-
binary_dirs := $(shell find cmd/* support/k8s/* support/oidc-discovery-provider -maxdepth 0 -type d)
1716
docker_volume_gopath := $(shell echo $${GOPATH}/pkg/mod):/root/go/pkg/mod
1817
docker_volume_spire := $(shell echo $${PWD}):/root/spire
1918
docker_image = spire-dev:latest
@@ -23,12 +22,19 @@ goversion-required := $(shell cat .go-version)
2322
gittag := $(shell git tag --points-at HEAD)
2423
githash := $(shell git rev-parse --short=7 HEAD)
2524
gitdirty := $(shell git status -s)
26-
# don't provide the git tag if the git status is dirty.
27-
ifneq ($(gitdirty),)
28-
gittag :=
29-
githash :=
25+
26+
# Determine the ldflags passed to the go linker. The git tag and hash will be
27+
# provided to the linker unless the git status is dirty.
28+
go_ldflags := -s -w
29+
ifeq ($(gitdirty),)
30+
ifneq ($(gittag),)
31+
go_ldflags += -X github.com/spiffe/spire/pkg/common/version.gittag=$(gittag)
32+
endif
33+
ifneq ($(githash),)
34+
go_ldflags += -X github.com/spiffe/spire/pkg/common/version.githash=$(githash)
35+
endif
3036
endif
31-
ldflags := '-s -w -X github.com/spiffe/spire/pkg/common/version.gittag=$(gittag) -X github.com/spiffe/spire/pkg/common/version.githash=$(githash)'
37+
go_ldflags := '${go_ldflags}'
3238

3339
utils = github.com/spiffe/spire/tools/spire-plugingen
3440

@@ -54,10 +60,22 @@ go-check:
5460

5561
# Make targets
5662
##@ Building
57-
build: $(binary_dirs) ## Build SPIRE binaries
5863

59-
$(binary_dirs): go-check
60-
$(docker) /bin/sh -c "cd $@; go build -ldflags $(ldflags)"
64+
build: bin/spire-server bin/spire-agent bin/k8s-workload-registrar bin/oidc-discovery-provider ## Build SPIRE binaries
65+
66+
define binary_rule
67+
.PHONY: $1
68+
$1:
69+
$$(docker) /bin/sh -c "go build -ldflags $$(go_ldflags) -o $1 $2"
70+
endef
71+
72+
$(eval $(call binary_rule,bin/spire-server,./cmd/spire-server))
73+
$(eval $(call binary_rule,bin/spire-agent,./cmd/spire-agent))
74+
$(eval $(call binary_rule,bin/k8s-workload-registrar,./support/k8s/k8s-workload-registrar))
75+
$(eval $(call binary_rule,bin/oidc-discovery-provider,./support/oidc-discovery-provider))
76+
77+
bin:
78+
mkdir -p bin
6179

6280
all: $(container) build test ## Build and run tests
6381

build.sh

+10-36
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ declare -r PROTOBUF_TGZ="protoc-${PROTOBUF_VERSION}-${OS2}-${ARCH1}.zip"
4242
_exit_error() { echo "ERROR: $*" 1>&2; exit 1; }
4343
_log_info() { echo "INFO: $*"; }
4444

45-
_artifact_dirs() {
46-
find cmd/* -maxdepth 0 -type d 2>/dev/null
47-
}
48-
49-
_release_dirs() {
50-
find cmd/* -maxdepth 0 -type d 2>/dev/null
51-
}
52-
5345
_fetch_url() {
5446
mkdir -p "${BUILD_CACHE}"
5547
if [[ ! -r ${BUILD_CACHE}/${2} ]]; then
@@ -198,23 +190,15 @@ build_release() {
198190
_tag="$(git describe --abbrev=0 2>/dev/null || true)"
199191
_always="$(git describe --always || true)"
200192
if [[ "$_tag" == "$_always" ]]; then
201-
build_artifact "$_tag" "$(_release_dirs)"
193+
build_artifact "$_tag"
202194
fi
203195
}
204196

205197
## Create a distributable tar.gz of all the binaries
206198
build_artifact() {
207-
local _version="$1" _dirs="$2"
199+
local _version="$1"
208200
local _libc _tgz _sum _binaries _n _tmp _tar_opts=()
209201

210-
[[ -z "$_dirs" ]] && _dirs="$(_artifact_dirs)"
211-
_dirs_array=()
212-
for _dir in $_dirs; do
213-
_dirs_array+=( "$_dir" )
214-
done
215-
_binaries="$(find "${_dirs_array[@]}" -perm -u=x -a -type f)"
216-
217-
218202
# handle the case that we're building for alpine
219203
if [[ $OS1 == linux ]]; then
220204
case $(ldd --version 2>&1) in
@@ -242,26 +226,16 @@ build_artifact() {
242226
rm -rf "$(dirname "$_tmp")"
243227
mkdir -p "$_tmp"
244228

245-
# ensure empty .data dir is available
246-
mkdir "$_tmp/.data"
229+
# Copy in the contents under release/
230+
cp -r release/* "$_tmp"
247231

248-
# we munge the file structure a bit here
249-
for _n in $_binaries; do
250-
if [[ $_n == *cmd/* ]]; then
251-
cp "$_n" $_tmp
252-
else
253-
mkdir -p "${_tmp}/$(dirname "$(dirname "$_n")")"
254-
cp -r "$_n" "${_tmp}/$(dirname "$_n")"
255-
fi
256-
done
257-
for _n in $RELEASE_FILES; do
258-
cp -r "$_n" "$_tmp"
259-
done
232+
# Copy in the LICENSE
233+
cp LICENSE "$_tmp"
260234

261-
# anchor relative paths in configuration files to /opt/spire. the backup
262-
# extension supplied to sed is only for easy cross-platform in-place
263-
# replacement because of differences between macOS and linux sed.
264-
find "$_tmp/conf" -type f -name "*.conf" -print0 | xargs -0 -I % -n1 sh -c "sed -i.bak -e 's#= \"./#= \"/opt/spire/#g' %; rm %.bak"
235+
# Copy in the SPIRE binaries
236+
mkdir -p "$_tmp"/bin
237+
cp bin/spire-server "$_tmp"/bin
238+
cp bin/spire-agent "$_tmp"/bin
265239

266240
tar -cvzf "$_tgz" --directory .tmp "${_tar_opts[@]}" "$(basename "$_tmp")"
267241
echo "$(shasum -a 256 "$_tgz" | cut -d' ' -f1) $(basename "$_tgz")" > "$_sum"

conf/agent/dummy_agent_ssh_key

-7
This file was deleted.

conf/agent/dummy_agent_ssh_key-cert.pub

-1
This file was deleted.

conf/agent/ha-postgres.conf

-30
This file was deleted.

conf/compose/ha-postgres.yml

-39
This file was deleted.

conf/server/dummy_ssh_cert_authority.pub

-1
This file was deleted.

conf/server/ha-postgres.conf

-45
This file was deleted.

conf/server/server-mysql.conf

-54
This file was deleted.

0 commit comments

Comments
 (0)