Skip to content

Commit c6126b2

Browse files
Merge pull request opencontainers#1554 from cyphar/use-umoci-release-script
release: import umoci's release.sh script
2 parents b31bdfc + c24f602 commit c6126b2

File tree

3 files changed

+133
-27
lines changed

3 files changed

+133
-27
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ before_install:
3030
script:
3131
- git-validation -run DCO,short-subject -v
3232
- make BUILDTAGS="${BUILDTAGS}"
33-
- make BUILDTAGS="${BUILDTAGS}" clean validate test
33+
- make BUILDTAGS="${BUILDTAGS}" clean ci

Makefile

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,7 @@ static: $(SOURCES)
4343
CGO_ENABLED=1 $(GO) build $(EXTRA_FLAGS) -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT} -X main.version=${VERSION} $(EXTRA_LDFLAGS)" -o contrib/cmd/recvtty/recvtty ./contrib/cmd/recvtty
4444

4545
release:
46-
@flag_list=(seccomp selinux apparmor static); \
47-
unset expression; \
48-
for flag in "$${flag_list[@]}"; do \
49-
expression+="' '{'',$${flag}}"; \
50-
done; \
51-
eval profile_list=("$$expression"); \
52-
for profile in "$${profile_list[@]}"; do \
53-
output=${RELEASE_DIR}/runc; \
54-
for flag in $$profile; do \
55-
output+=."$$flag"; \
56-
done; \
57-
tags="$$profile"; \
58-
ldflags="-X main.gitCommit=${COMMIT} -X main.version=${VERSION}"; \
59-
buildflags="-buildmode=pie"; \
60-
CGO_ENABLED=; \
61-
[[ "$$profile" =~ static ]] && { \
62-
tags="$${tags/static/static_build}"; \
63-
tags+=" cgo"; \
64-
buildflags=; \
65-
ldflags+=" -w -extldflags -static"; \
66-
CGO_ENABLED=1; \
67-
}; \
68-
echo "Building target: $$output"; \
69-
$(GO) build $$buildflags $(EXTRA_FLAGS) -ldflags "$$ldflags $(EXTRA_LDFLAGS)" -tags "$$tags" -o "$$output" .; \
70-
done
46+
script/release.sh -r release/$(VERSION) -v $(VERSION)
7147

7248
dbuild: runcimage
7349
docker run --rm -v $(CURDIR):/go/src/$(PROJECT) --privileged $(RUNC_IMAGE) make clean all
@@ -139,7 +115,7 @@ validate:
139115
script/validate-gofmt
140116
$(GO) vet $(allpackages)
141117

142-
ci: validate localtest
118+
ci: validate test release
143119

144120
# memoize allpackages, so that it's executed only once and only if used
145121
_allpackages = $(shell $(GO) list ./... | grep -v vendor)

script/release.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/bin/bash
2+
# Copyright (C) 2017 SUSE LLC.
3+
#
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 -e
17+
18+
## --->
19+
# Project-specific options and functions. In *theory* you shouldn't need to
20+
# touch anything else in this script in order to use this elsewhere.
21+
project="runc"
22+
root="$(readlink -f "$(dirname "${BASH_SOURCE}")/..")"
23+
24+
# This function takes an output path as an argument, where the built
25+
# (preferably static) binary should be placed.
26+
function build_project() {
27+
builddir="$(dirname "$1")"
28+
29+
# Build with all tags enabled.
30+
make -C "$root" COMMIT_NO= BUILDTAGS="seccomp selinux apparmor" static
31+
mv "$root/$project" "$1"
32+
}
33+
34+
# End of the easy-to-configure portion.
35+
## <---
36+
37+
# Print usage information.
38+
function usage() {
39+
echo "usage: release.sh [-S <gpg-key-id>] [-c <commit-ish>] [-r <release-dir>] [-v <version>]" >&2
40+
exit 1
41+
}
42+
43+
# Log something to stderr.
44+
function log() {
45+
echo "[*] $*" >&2
46+
}
47+
48+
# Log something to stderr and then exit with 0.
49+
function bail() {
50+
log "$@"
51+
exit 0
52+
}
53+
54+
# Conduct a sanity-check to make sure that GPG provided with the given
55+
# arguments can sign something. Inability to sign things is not a fatal error.
56+
function gpg_cansign() {
57+
gpg "$@" --clear-sign </dev/null >/dev/null
58+
}
59+
60+
# When creating releases we need to build static binaries, an archive of the
61+
# current commit, and generate detached signatures for both.
62+
keyid=""
63+
commit="HEAD"
64+
version=""
65+
releasedir=""
66+
hashcmd=""
67+
while getopts "S:c:r:v:h:" opt; do
68+
case "$opt" in
69+
S)
70+
keyid="$OPTARG"
71+
;;
72+
c)
73+
commit="$OPTARG"
74+
;;
75+
r)
76+
releasedir="$OPTARG"
77+
;;
78+
v)
79+
version="$OPTARG"
80+
;;
81+
h)
82+
hashcmd="$OPTARG"
83+
;;
84+
\:)
85+
echo "Missing argument: -$OPTARG" >&2
86+
usage
87+
;;
88+
\?)
89+
echo "Invalid option: -$OPTARG" >&2
90+
usage
91+
;;
92+
esac
93+
done
94+
95+
version="${version:-$(<"$root/VERSION")}"
96+
releasedir="${releasedir:-release/$version}"
97+
hashcmd="${hashcmd:-sha256sum}"
98+
goarch="$(go env GOARCH || echo "amd64")"
99+
100+
log "creating $project release in '$releasedir'"
101+
log " version: $version"
102+
log " commit: $commit"
103+
log " key: ${keyid:-DEFAULT}"
104+
log " hash: $hashcmd"
105+
106+
# Make explicit what we're doing.
107+
set -x
108+
109+
# Make the release directory.
110+
rm -rf "$releasedir" && mkdir -p "$releasedir"
111+
112+
# Build project.
113+
build_project "$releasedir/$project.$goarch"
114+
115+
# Generate new archive.
116+
git archive --format=tar --prefix="$project-$version/" "$commit" | xz > "$releasedir/$project.tar.xz"
117+
118+
# Generate sha256 checksums for both.
119+
( cd "$releasedir" ; "$hashcmd" "$project".{"$goarch",tar.xz} > "$project.$hashcmd" ; )
120+
121+
# Set up the gpgflags.
122+
[[ "$keyid" ]] && export gpgflags="--default-key $keyid"
123+
gpg_cansign $gpgflags || bail "Could not find suitable GPG key, skipping signing step."
124+
125+
# Sign everything.
126+
gpg $gpgflags --detach-sign --armor "$releasedir/$project.$goarch"
127+
gpg $gpgflags --detach-sign --armor "$releasedir/$project.tar.xz"
128+
gpg $gpgflags --clear-sign --armor \
129+
--output "$releasedir/$project.$hashcmd"{.tmp,} && \
130+
mv "$releasedir/$project.$hashcmd"{.tmp,}

0 commit comments

Comments
 (0)