Skip to content

Commit d578198

Browse files
committed
Add rpm build & repo publish
1 parent 456962b commit d578198

File tree

7 files changed

+215
-7
lines changed

7 files changed

+215
-7
lines changed

.dockerignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
./bin
22
./etc
3-
./build/data
4-
./build/data.tar.gz
53
./pkg/data/zz_generated_bindata.go
6-
./package/data.tar.gz
74
./.vagrant
85
./.cache
96
./.dapper
10-
./data-dir
11-
./dist
127
./.trash-cache

.drone.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ steps:
5959
event:
6060
- tag
6161

62+
- name: rpm-publish
63+
image: centos:7
64+
environment:
65+
PRIVATE_KEY:
66+
from_secret: private_key
67+
PRIVATE_KEY_PASS_PHRASE:
68+
from_secret: private_key_pass_phrase
69+
AWS_S3_BUCKET:
70+
from_secret: aws_s3_bucket
71+
AWS_ACCESS_KEY_ID:
72+
from_secret: aws_access_key_id
73+
AWS_SECRET_ACCESS_KEY:
74+
from_secret: aws_secret_access_key
75+
commands:
76+
- scripts/provision/generic/centos7/yum-install-rpm-tools
77+
- scripts/package-rpm
78+
6279
- name: test
6380
image: rancher/dapper:v0.4.2
6481
secrets: [ gcloud_auth ]
@@ -154,6 +171,23 @@ steps:
154171
event:
155172
- tag
156173

174+
- name: rpm-publish
175+
image: centos:7
176+
environment:
177+
PRIVATE_KEY:
178+
from_secret: private_key
179+
PRIVATE_KEY_PASS_PHRASE:
180+
from_secret: private_key_pass_phrase
181+
AWS_S3_BUCKET:
182+
from_secret: aws_s3_bucket
183+
AWS_ACCESS_KEY_ID:
184+
from_secret: aws_access_key_id
185+
AWS_SECRET_ACCESS_KEY:
186+
from_secret: aws_secret_access_key
187+
commands:
188+
- scripts/provision/generic/centos7/yum-install-rpm-tools
189+
- scripts/package-rpm
190+
157191
- name: test
158192
image: rancher/dapper:v0.4.2
159193
secrets: [ gcloud_auth ]
@@ -323,6 +357,6 @@ volumes:
323357
- name: docker
324358
host:
325359
path: /var/run/docker.sock
326-
360+
327361
depends_on:
328362
- manifest

package/k3s.spec

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# vim: sw=4:ts=4:et
2+
3+
%define install_path /usr/bin
4+
%define util_path %{_datadir}/k3s
5+
%define install_sh %{util_path}/.install.sh
6+
%define uninstall_sh %{util_path}/.uninstall.sh
7+
8+
Name: k3s
9+
Version: %{k3s_version}
10+
Release: %{k3s_release}%{?dist}
11+
Summary: Lightweight Kubernetes
12+
13+
Group: System Environment/Base
14+
License: ASL 2.0
15+
URL: http://k3s.io
16+
17+
BuildRequires: systemd
18+
Requires(post): k3s-selinux >= %{k3s_policyver}
19+
20+
%description
21+
The certified Kubernetes distribution built for IoT & Edge computing.
22+
23+
%install
24+
install -d %{buildroot}%{install_path}
25+
install dist/artifacts/%{k3s_binary} %{buildroot}%{install_path}/k3s
26+
install -d %{buildroot}%{util_path}
27+
install install.sh %{buildroot}%{install_sh}
28+
29+
%post
30+
# do not run install script on upgrade
31+
echo post-install args: $@
32+
if [ $1 == 1 ]; then
33+
INSTALL_K3S_BIN_DIR=%{install_path} \
34+
INSTALL_K3S_SKIP_DOWNLOAD=true \
35+
INSTALL_K3S_SKIP_ENABLE=true \
36+
UNINSTALL_K3S_SH=%{uninstall_sh} \
37+
%{install_sh}
38+
fi
39+
%systemd_post k3s.service
40+
exit 0
41+
42+
%postun
43+
echo post-uninstall args: $@
44+
# do not run uninstall script on upgrade
45+
if [ $1 == 0 ]; then
46+
%{uninstall_sh}
47+
rm -rf %{util_path}
48+
fi
49+
exit 0
50+
51+
%files
52+
%{install_path}/k3s
53+
%{install_sh}
54+
55+
%changelog
56+
* Mon Mar 2 2020 Erik Wilson <[email protected]> 0.1-1
57+
- Initial version

scripts/package-rpm

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
set -e -x
3+
4+
cd $(dirname $0)/..
5+
6+
ARCH=${DRONE_STAGE_ARCH:-$(arch)}
7+
. ./scripts/version.sh
8+
9+
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(\-[^\+]*)?\+k3s.+$ ]]; then
10+
echo "k3s version $VERSION does not match regex for rpm upload"
11+
exit 0
12+
fi
13+
14+
TMPDIR=$(mktemp -d)
15+
cleanup() {
16+
exit_code=$?
17+
trap - EXIT INT
18+
rm -rf ${TMPDIR}
19+
exit ${exit_code}
20+
}
21+
trap cleanup EXIT INT
22+
23+
export HOME=${TMPDIR}
24+
25+
BIN_SUFFIX=""
26+
if [ ${ARCH} = aarch64 ] || [ ${ARCH} = arm64 ]; then
27+
BIN_SUFFIX="-arm64"
28+
elif [ ${ARCH} = armv7l ] || [ ${ARCH} = arm ]; then
29+
BIN_SUFFIX="-armhf"
30+
fi
31+
32+
# capture version of k3s
33+
k3s_version=$(sed -E -e 's/^v([^-+]*).*$/\1/' <<< $VERSION)
34+
# capture pre-release and metadata information of k3s
35+
k3s_release=$(sed -E -e 's/\+k3s/+/; s/\+/-/g; s/^[^-]*//; s/^--/dev-/; s/-+/./g; s/^\.+//; s/\.+$//;' <<< $VERSION)
36+
# k3s-selinux policy version needed for functionality
37+
k3s_policyver=0.1-1
38+
39+
rpmbuild \
40+
--define "k3s_version ${k3s_version}" \
41+
--define "k3s_release ${k3s_release}" \
42+
--define "k3s_policyver ${k3s_policyver}" \
43+
--define "k3s_binary k3s${BIN_SUFFIX}" \
44+
--define "_sourcedir ${PWD}" \
45+
--define "_specdir ${PWD}" \
46+
--define "_builddir ${PWD}" \
47+
--define "_srcrpmdir ${PWD}" \
48+
--define "_rpmdir ${PWD}/dist/rpm" \
49+
--define "_buildrootdir ${PWD}/.rpm-build" \
50+
-bb package/k3s.spec
51+
52+
if ! grep "BEGIN PGP PRIVATE KEY BLOCK" <<<"$PRIVATE_KEY"; then
53+
echo "PRIVATE_KEY not defined, skipping rpm sign and upload"
54+
exit 0
55+
fi
56+
57+
cat <<\EOF >~/.rpmmacros
58+
%_signature gpg
59+
60+
EOF
61+
gpg --import - <<<"$PRIVATE_KEY"
62+
63+
expect <<EOF
64+
set timeout 60
65+
spawn sh -c "rpmsign --addsign dist/rpm/**/k3s-*.rpm"
66+
expect "Enter pass phrase:"
67+
send -- "$PRIVATE_KEY_PASS_PHRASE\r"
68+
expect eof
69+
lassign [wait] _ _ _ code
70+
exit \$code
71+
EOF
72+
73+
if [ -z "$AWS_S3_BUCKET" ]; then
74+
echo "AWS_S3_BUCKET skipping rpm upload"
75+
exit 0
76+
fi
77+
78+
rpm-s3 --bucket $AWS_S3_BUCKET dist/rpm/**/k3s-*.rpm
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -e -x
4+
5+
TMPDIR=$(mktemp -d)
6+
cleanup() {
7+
exit_code=$?
8+
trap - EXIT INT
9+
rm -rf ${TMPDIR}
10+
exit ${exit_code}
11+
}
12+
trap cleanup EXIT INT
13+
14+
export HOME=${TMPDIR}
15+
16+
gpg --batch --gen-key - <<EOF
17+
%echo Generating a default key
18+
Key-Type: default
19+
Subkey-Type: default
20+
Name-Real: Rancher
21+
Name-Comment: CI
22+
Name-Email: [email protected]
23+
Expire-Date: 0
24+
25+
# Key-Length: 4096
26+
# Subkey-Length: 4096
27+
Passphrase: $PRIVATE_KEY_PASS_PHRASE
28+
# %no-protection
29+
# %no-ask-passphrase
30+
31+
# Do a commit here, so that we can later print "done" :-)
32+
%commit
33+
%echo done
34+
EOF
35+
36+
gpg --armor --export [email protected] >public.key
37+
gpg --armor --export-secret-key [email protected] >private.key
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e -x
4+
5+
yum install -y git expect yum-utils rpm-build rpm-sign python-deltarpm epel-release
6+
yum install -y python2-pip
7+
pip install git+git://github.com/Voronenko/rpm-s3.git@5695c6ad9a08548141d3713328e1bd3f533d137e

scripts/version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARCH=${ARCH:-$(go env GOARCH)}
44
SUFFIX="-${ARCH}"
55
GIT_TAG=$DRONE_TAG
66
TREE_STATE=clean
7-
COMMIT=unknown
7+
COMMIT=$DRONE_COMMIT
88

99
if [ -d .git ]; then
1010
if [ -z "$GIT_TAG" ]; then

0 commit comments

Comments
 (0)