Skip to content

Commit

Permalink
Fix local build of packages (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Oct 10, 2019
1 parent d7c89aa commit 5aa24fe
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 47 deletions.
5 changes: 3 additions & 2 deletions apk/templates/APKBUILD.github-binary
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pkgdesc="${PACKAGE_DESCRIPTION}"
builddir="$srcdir"
exe=$PACKAGE_EXE
repo=vendor
installdir=${INSTALL_DIR:-/usr/bin/}

# https://wiki.alpinelinux.org/wiki/APKBUILD_examples

Expand Down Expand Up @@ -133,9 +134,9 @@ check() {
# The built application and support files should be installed into $pkgdir.
package() {
echo "Installing packges to ${pkgdir}"
mkdir -p "${pkgdir}/usr/bin"
mkdir -p "${pkgdir}/${installdir}"
for cmd in ${exe}; do
install -m 755 "$(realpath "${srcdir}/${cmd}")" "${pkgdir}/usr/bin/${cmd}"
install -m 755 "$(realpath "${srcdir}/${cmd}")" "${pkgdir}/${installdir}/${cmd}"
done
echo "Binaries staged for installation in ${pkgdir}"
find "${pkgdir}"
Expand Down
1 change: 1 addition & 0 deletions codefresh/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ mtime:
touchtime=$$(date -d @$$unixtime +'%Y%m%d%H%M.%S'); \
touch -t $$touchtime $$filename; \
done

36 changes: 33 additions & 3 deletions tasks/Makefile.apk
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# APK
export PACKAGER_PRIVKEY ?= $(CURDIR)/../../key.rsa


ifeq ($(CI),)
export PACKAGER_PRIVKEY_DIR ?= /packages/apk
export PACKAGER ?= [email protected]
export PACKAGER_PRIVKEY ?= $(PACKAGER_PRIVKEY_DIR)/$(PACKAGER).rsa
export PACKAGER_PUBKEY ?= $(APK_PACKAGES_PATH)/$(PACKAGER).rsa.pub
export PACKAGER_PUBKEY_INSTALLED ?= /etc/apk/keys/$(PACKAGER).rsa.pub

$(PACKAGER_PRIVKEY) localkey:
openssl genrsa -out $(PACKAGER_PRIVKEY) 2048

$(PACKAGER_PUBKEY): $(PACKAGER_PRIVKEY)
mkdir -p $(APK_PACKAGES_PATH)
chmod 777 $(APK_PACKAGES_PATH)
openssl rsa -in $(PACKAGER_PRIVKEY) -pubout > $(PACKAGER_PUBKEY)

$(PACKAGER_PUBKEY_INSTALLED): $(PACKAGER_PUBKEY)
chmod 666 $(PACKAGER_PRIVKEY) $(PACKAGER_PUBKEY)
cp $(PACKAGER_PUBKEY) $(PACKAGER_PUBKEY_INSTALLED)

endif

export APK_TEMPLATE_PATH ?= ../../apk/templates/
export APK_BUILD_TEMPLATE ?= APKBUILD.github-binary
export APK_PACKAGES_PATH ?= /tmp/packages
Expand All @@ -26,23 +48,31 @@ apk/build:
cd $(APK_TMP_DIR) && \
sudo -E -H -u nobody abuild -c -r -P $(APK_PACKAGES_PATH)

apk/testinstall:
@echo '* Verify package can be installed:'
apk add --virtual buildtest $(APK_PACKAGE)
@echo '* Verify package can be uninstalled:'
apk del buildtest

apk/clean:
@find $(APK_PACKAGES_PATH) -type f -name APKINDEX.tar.gz -delete
apk del buildtest || true
rm -rf $(APK_TMP_DIR)
mkdir -p $(APK_TMP_DIR)

apk/reset:
apk del buildtest || true
rm -rf $(APK_PACKAGE)

.PHONY : apk
apk: $(APK_PACKAGE)
apk: $(PACKAGER_PRIVKEY) $(PACKAGER_PUBKEY_INSTALLED) $(APK_PACKAGE)
@exit 0

# Rebuild the `.apk` when it's older than the Makefile, VERSION, or RELEASE files
$(APK_PACKAGE): Makefile VERSION RELEASE
@echo "Building $@"
ls -l $@ Makefile VERSION RELEASE || true
$(MAKE) info apk/prepare apk/checksum apk/build apk/clean
$(MAKE) info apk/prepare apk/checksum apk/build apk/testinstall apk/clean

package/prepare::
@exit 0
2 changes: 0 additions & 2 deletions vendor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ APK_PACKAGE_REPOS ?= $(addprefix $(APK_PACKAGES_PATH)/,$(REPOS))
APK_PACKAGE_INDEX ?= $(addsuffix /APKINDEX.tar.gz,$(APK_PACKAGE_REPOS))
APK_PACKAGES ?= $(wildcard $(addsuffix /*.apk,$(APK_PACKAGE_REPOS)))

export PACKAGER_PRIVKEY ?= $(CURDIR)/../key.rsa

default: build

## Install alpine build deps
Expand Down
7 changes: 5 additions & 2 deletions vendor/kops-1.12/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export PACKAGE_NAME = kops-1.12
export MASTER_PACKAGE_NAME = kops
export MAJOR_VERSION = 1.12
export PACKAGE_NAME = $(MASTER_PACKAGE_NAME)-$(MAJOR_VERSION)
export DOWNLOAD_URL = https://github.com/kubernetes/kops/releases/download/$(PACKAGE_VERSION)/kops-$(OS)-$(ARCH)

include ../../tasks/Makefile.package
Expand All @@ -9,7 +11,8 @@ include ../../tasks/Makefile.apk
export VENDOR = kubernetes
export APK_BUILD_TEMPLATE = APKBUILD.github-binary
export APKBUILD_DEPENDS += dpkg
export APKBUILD_INSTALL_SCRIPTS += $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export APKBUILD_INSTALL_SCRIPTS = $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export INSTALL_DIR = /usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin

install:
$(call download_binary)
Expand Down
7 changes: 4 additions & 3 deletions vendor/kops-1.12/kops-1.12.post-deinstall
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh
# This is an Alpine `deinstall` hook that removes the alternative
PACKAGE_NAME=kops
MASTER_PACKAGE_NAME=kops
MAJOR_VERSION=1.12
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${PACKAGE_NAME}-${MAJOR_VERSION} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
PACKAGE_NAME=${MASTER_PACKAGE_NAME}-${MAJOR_VERSION}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
exit 0
10 changes: 6 additions & 4 deletions vendor/kops-1.12/kops-1.12.post-install
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/sh
# This is an Alpine Package `post-install` hook that installs an alternative into `/usr/local/${PACKAGE_NAME}/$version/bin`
PACKAGE_NAME=kops
# This is an Alpine Package `post-install` hook that links
# an alternative from `/usr/share/${PACKAGE_NAME}/$version/bin` into `/usr/bin/`
MASTER_PACKAGE_NAME=kops
MAJOR_VERSION=1.12
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
PACKAGE_NAME=${MASTER_PACKAGE_NAME}-${MAJOR_VERSION}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
mkdir -p ${INSTALL_DIR}
update-alternatives --install /usr/bin/${PACKAGE_NAME}-${MAJOR_VERSION} ${PACKAGE_NAME}-${MAJOR_VERSION} ${INSTALL_DIR}/${PACKAGE_NAME} 1
update-alternatives --install /usr/bin/${MASTER_PACKAGE_NAME} ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 12
exit 0
4 changes: 4 additions & 0 deletions vendor/kops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ include ../../tasks/Makefile.apk
export VENDOR ?= kubernetes
export DOWNLOAD_URL ?= $(PACKAGE_REPO_URL)/releases/download/$(PACKAGE_VERSION)/$(PACKAGE_NAME)-$(OS)-$(ARCH)
export APK_BUILD_TEMPLATE ?= APKBUILD.github-binary
export APKBUILD_DEPENDS += dpkg
export APKBUILD_INSTALL_SCRIPTS = $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export MAJOR_VERSION = latest
export INSTALL_DIR = /usr/share/${PACKAGE_NAME}/${MAJOR_VERSION}/bin

install:
$(call download_binary)
Expand Down
8 changes: 8 additions & 0 deletions vendor/kops/kops.post-deinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
# This is an Alpine `deinstall` hook that removes the alternative
MASTER_PACKAGE_NAME=kops
MAJOR_VERSION=latest
PACKAGE_NAME=${MASTER_PACKAGE_NAME}
INSTALL_DIR=/usr/share/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
exit 0
10 changes: 10 additions & 0 deletions vendor/kops/kops.post-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# This is an Alpine Package `post-install` hook that links
# an alternative from `/usr/share/${PACKAGE_NAME}/$version/bin` into `/usr/bin/`
MASTER_PACKAGE_NAME=kops
MAJOR_VERSION=latest
PACKAGE_NAME=${MASTER_PACKAGE_NAME}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
mkdir -p ${INSTALL_DIR}
update-alternatives --install /usr/bin/${MASTER_PACKAGE_NAME} ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 1
exit 0
7 changes: 5 additions & 2 deletions vendor/kubectl-1.13/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export PACKAGE_NAME = kubectl-1.13
export MASTER_PACKAGE_NAME = kubectl
export MAJOR_VERSION = 1.13
export PACKAGE_NAME = $(MASTER_PACKAGE_NAME)-$(MAJOR_VERSION)
export PACKAGE_REPO_NAME = kubernetes

include ../../tasks/Makefile.package
Expand All @@ -9,7 +11,8 @@ export VENDOR = kubernetes
export DOWNLOAD_URL = https://storage.googleapis.com/kubernetes-release/release/v$(PACKAGE_VERSION)/bin/$(OS)/$(ARCH)/kubectl
export APK_BUILD_TEMPLATE = APKBUILD.github-binary
export APKBUILD_DEPENDS += dpkg
export APKBUILD_INSTALL_SCRIPTS += $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export APKBUILD_INSTALL_SCRIPTS = $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export INSTALL_DIR = /usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin

install:
$(call download_binary)
Expand Down
7 changes: 4 additions & 3 deletions vendor/kubectl-1.13/kubectl-1.13.post-deinstall
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh
# This is an Alpine `deinstall` hook that removes the alternative
PACKAGE_NAME=kubectl
MASTER_PACKAGE_NAME=kubectl
MAJOR_VERSION=1.13
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${PACKAGE_NAME}-${MAJOR_VERSION} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
PACKAGE_NAME=${MASTER_PACKAGE_NAME}-${MAJOR_VERSION}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
update-alternatives --remove ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
exit 0
13 changes: 8 additions & 5 deletions vendor/kubectl-1.13/kubectl-1.13.post-install
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh
# This is an Alpine Package `post-install` hook that installs an alternative into `/usr/local/${PACKAGE_NAME}/$version/bin`
PACKAGE_NAME=kubectl
# This is an Alpine Package `post-install` hook that links
# an alternative from `/usr/share/${PACKAGE_NAME}/$version/bin` into `/usr/bin/`
MASTER_PACKAGE_NAME=kubectl
MAJOR_VERSION=1.13
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
PACKAGE_NAME=${MASTER_PACKAGE_NAME}-${MAJOR_VERSION}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin

mkdir -p ${INSTALL_DIR}
update-alternatives --install /usr/bin/${PACKAGE_NAME}-${MAJOR_VERSION} ${PACKAGE_NAME}-${MAJOR_VERSION} ${INSTALL_DIR}/${PACKAGE_NAME} 1
update-alternatives --install /usr/bin/${PACKAGE_NAME} ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 13
update-alternatives --install /usr/bin/${PACKAGE_NAME} ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 1
update-alternatives --install /usr/bin/${MASTER_PACKAGE_NAME} ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 13
exit 0
7 changes: 5 additions & 2 deletions vendor/kubectl-1.14/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export PACKAGE_NAME = kubectl-1.14
export MASTER_PACKAGE_NAME = kubectl
export MAJOR_VERSION = 1.14
export PACKAGE_NAME = $(MASTER_PACKAGE_NAME)-$(MAJOR_VERSION)
export PACKAGE_REPO_NAME = kubernetes

include ../../tasks/Makefile.package
Expand All @@ -9,7 +11,8 @@ export VENDOR = kubernetes
export DOWNLOAD_URL = https://storage.googleapis.com/kubernetes-release/release/v$(PACKAGE_VERSION)/bin/$(OS)/$(ARCH)/kubectl
export APK_BUILD_TEMPLATE = APKBUILD.github-binary
export APKBUILD_DEPENDS += dpkg
export APKBUILD_INSTALL_SCRIPTS += $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export APKBUILD_INSTALL_SCRIPTS = $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export INSTALL_DIR = /usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin

install:
$(call download_binary)
Expand Down
9 changes: 5 additions & 4 deletions vendor/kubectl-1.14/kubectl-1.14.post-deinstall
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh
# This is an Alpine `deinstall` hook that removes the alternative
PACKAGE_NAME=kubectl
MAJOR_VERSION=1.14
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${PACKAGE_NAME}-${MAJOR_VERSION} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
MASTER_PACKAGE_NAME=kubectl
MAJOR_VERSION=1.13
PACKAGE_NAME=${MASTER_PACKAGE_NAME}-${MAJOR_VERSION}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
update-alternatives --remove ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
exit 0
13 changes: 8 additions & 5 deletions vendor/kubectl-1.14/kubectl-1.14.post-install
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh
# This is an Alpine Package `post-install` hook that installs an alternative into `/usr/local/${PACKAGE_NAME}/$version/bin`
PACKAGE_NAME=kubectl
# This is an Alpine Package `post-install` hook that links
# an alternative from `/usr/share/${PACKAGE_NAME}/$version/bin` into `/usr/bin/`
MASTER_PACKAGE_NAME=kubectl
MAJOR_VERSION=1.14
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
PACKAGE_NAME=${MASTER_PACKAGE_NAME}-${MAJOR_VERSION}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin

mkdir -p ${INSTALL_DIR}
update-alternatives --install /usr/bin/${PACKAGE_NAME}-${MAJOR_VERSION} ${PACKAGE_NAME}-${MAJOR_VERSION} ${INSTALL_DIR}/${PACKAGE_NAME} 1
update-alternatives --install /usr/bin/${PACKAGE_NAME} ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 14
update-alternatives --install /usr/bin/${PACKAGE_NAME} ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 1
update-alternatives --install /usr/bin/${MASTER_PACKAGE_NAME} ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 14
exit 0
4 changes: 3 additions & 1 deletion vendor/kubectl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export VENDOR = kubernetes
export DOWNLOAD_URL = https://storage.googleapis.com/kubernetes-release/release/v$(PACKAGE_VERSION)/bin/$(OS)/$(ARCH)/$(PACKAGE_NAME)
export APK_BUILD_TEMPLATE = APKBUILD.github-binary
export APKBUILD_DEPENDS += dpkg
export APKBUILD_INSTALL_SCRIPTS += $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export APKBUILD_INSTALL_SCRIPTS = $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export MAJOR_VERSION = latest
export INSTALL_DIR = /usr/share/${PACKAGE_NAME}/${MAJOR_VERSION}/bin

install:
$(call download_binary)
Expand Down
9 changes: 5 additions & 4 deletions vendor/kubectl/kubectl.post-deinstall
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh
# This is an Alpine `deinstall` hook that removes the alternative
PACKAGE_NAME=kubectl
MAJOR_VERSION=default
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
MASTER_PACKAGE_NAME=kubectl
MAJOR_VERSION=latest
PACKAGE_NAME=${MASTER_PACKAGE_NAME}
INSTALL_DIR=/usr/share/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
update-alternatives --remove ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} --quiet
exit 0
12 changes: 7 additions & 5 deletions vendor/kubectl/kubectl.post-install
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/sh
# This is an Alpine Package `post-install` hook that installs an alternative into `/usr/local/${PACKAGE_NAME}/$version/bin`
PACKAGE_NAME=kubectl
MAJOR_VERSION=default
INSTALL_DIR=/usr/local/${PACKAGE_NAME}/${MAJOR_VERSION}/bin
# This is an Alpine Package `post-install` hook that links
# an alternative from `/usr/share/${PACKAGE_NAME}/$version/bin` into `/usr/bin/`
MASTER_PACKAGE_NAME=kubectl
MAJOR_VERSION=latest
PACKAGE_NAME=${MASTER_PACKAGE_NAME}
INSTALL_DIR=/usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
mkdir -p ${INSTALL_DIR}
update-alternatives --install /usr/bin/${PACKAGE_NAME} ${PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 1
update-alternatives --install /usr/bin/${MASTER_PACKAGE_NAME} ${MASTER_PACKAGE_NAME} ${INSTALL_DIR}/${PACKAGE_NAME} 1
exit 0

0 comments on commit 5aa24fe

Please sign in to comment.