diff --git a/Makefile b/Makefile index c1848d992b..1863c04cf3 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ ROOT_DIR := $(CURDIR) BUILD_DIR := $(ROOT_DIR)/_output BIN_DIR := $(BUILD_DIR)/bin BUILD_SCRIPT := $(ROOT_DIR)/build/build.sh +DEB_BUILD_SCRIPT := $(ROOT_DIR)/build/build_deb.sh ifeq ($(ONECLOUD_CI_BUILD),) GIT_COMMIT := $(shell git rev-parse --short HEAD) @@ -64,6 +65,7 @@ endif cmdTargets:=$(filter-out cmd/host-image,$(wildcard cmd/*)) rpmTargets:=$(foreach b,$(patsubst cmd/%,%,$(cmdTargets)),$(if $(shell [ -f "$(CURDIR)/build/$(b)/vars" ] && echo 1),rpm/$(b))) +debTargets:=$(foreach b,$(patsubst cmd/%,%,$(cmdTargets)),$(if $(shell [ -f "$(CURDIR)/build/$(b)/vars" ] && echo 1),deb/$(b))) all: build @@ -93,6 +95,9 @@ cmd/%: prepare_dir rpm/%: cmd/% $(BUILD_SCRIPT) $* +deb/%: cmd/% + $(DEB_BUILD_SCRIPT) $* + pkg/%: prepare_dir $(GO_INSTALL) $(REPO_PREFIX)/$@ @@ -102,6 +107,9 @@ build: rpm: $(MAKE) $(rpmTargets) +deb: + $(MAKE) $(debTargets) + rpmclean: rm -fr $(BUILD_DIR)/rpms diff --git a/build/build_deb.sh b/build/build_deb.sh new file mode 100755 index 0000000000..c86ca987f4 --- /dev/null +++ b/build/build_deb.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +set -e + +if [ -z "$ROOT_DIR" ]; then + pushd $(dirname $(readlink -f "$BASH_SOURCE")) > /dev/null + ROOT_DIR=$(cd .. && pwd) + popd > /dev/null +fi + +SRC_BIN=$ROOT_DIR/_output/bin +SRC_BUILD=$ROOT_DIR/build +OUTPUT_DIR=$ROOT_DIR/_output/debs + +PKG=$1 +BIN_PATH=${2:-/opt/yunion/bin} + +if [ -z "$PKG" ]; then + echo "Usage: $0 " + exit 1 +fi + +BIN="$SRC_BIN/$PKG" +ROOT="$SRC_BUILD/$PKG" + +if [ ! -x "$BIN" ]; then + echo "$BIN not exists" + exit 1 +fi + +if [ ! -x "$ROOT" ]; then + echo "$ROOT not exists" + exit 1 +fi + +. $ROOT/vars + +if [ -z "$VERSION" ]; then + TAG=$(git describe --abbrev=0 --tags || echo 000000) + VERSION=${TAG/\//-} + VERSION=${VERSION/v/} +fi +RELEASE=`date +"%y%m%d%H"` +FULL_VERSION=$VERSION-$RELEASE +BUILDROOT=$OUTPUT_DIR/yunion-$1-$FULL_VERSION +rm -rf $BUILDROOT +mkdir -p $BUILDROOT/DEBIAN +mkdir -p $BUILDROOT/$BIN_PATH + +cp -rf $BIN $BUILDROOT/$BIN_PATH +cp -rf $ROOT/root/* $BUILDROOT/ + + +echo "Build root ${BUILDROOT}" + +case $(uname -m) in + x86_64) + CURRENT_ARCH=amd64 + ;; + aarch64) + CURRENT_ARCH=arm64 + ;; +esac + +echo "Package: yunion-$1 +Version: $FULL_VERSION +Section: base +Priority: optional +Architecture: $CURRENT_ARCH +Maintainer: wanyaoqi@yunionyun.com +Description: Yunion $1 +" > $BUILDROOT/DEBIAN/control +chmod 0755 $BUILDROOT/DEBIAN/control + + +dpkg-deb --build $BUILDROOT \ No newline at end of file