github.com/Tyktechnologies/tyk@v2.9.5+incompatible/bin/dist_build.sh (about) 1 #!/bin/bash 2 3 set -ex 4 5 : ${ORGDIR:="/go/src/github.com/TykTechnologies"} 6 : ${SOURCEBINPATH:="${ORGDIR}/tyk"} 7 : ${SIGNKEY:="12B5D62C28F57592D1575BD51ED14C59E37DAC20"} 8 : ${BUILDPKGS:="1"} 9 : ${SIGNPKGS:="1"} 10 : ${PKGNAME:="tyk-gateway"} 11 BUILDTOOLSDIR=$SOURCEBINPATH/build_tools 12 BUILDDIR=$SOURCEBINPATH/build 13 14 echo "Set version number" 15 : ${VERSION:=$(perl -n -e'/v(\d+).(\d+).(\d+)/'' && print "$1\.$2\.$3"' version.go)} 16 17 if [ $BUILDPKGS == "1" ]; then 18 echo Configuring gpg-agent-config to accept a passphrase 19 mkdir ~/.gnupg && chmod 700 ~/.gnupg 20 cat >> ~/.gnupg/gpg-agent.conf <<EOF 21 allow-preset-passphrase 22 debug-level expert 23 log-file /tmp/gpg-agent.log 24 EOF 25 gpg-connect-agent reloadagent /bye 26 27 echo "Importing signing key" 28 gpg --list-keys | grep -w $SIGNKEY && echo "Key exists" || gpg --batch --import $BUILDTOOLSDIR/tyk.io.signing.key 29 bash $BUILDTOOLSDIR/unlock-agent.sh $SIGNKEY 30 fi 31 32 echo "Prepare the release directories" 33 34 export SOURCEBIN=tyk 35 36 declare -A ARCHTGZDIRS 37 ARCHTGZDIRS=( 38 [i386]=$BUILDDIR/i386/tgz/tyk.linux.i386-$VERSION 39 [amd64]=$BUILDDIR/amd64/tgz/tyk.linux.amd64-$VERSION 40 [arm64]=$BUILDDIR/arm/tgz/tyk.linux.arm64-$VERSION 41 ) 42 43 DESCRIPTION="Tyk Open Source API Gateway written in Go" 44 echo "Starting Tyk build" 45 cd $SOURCEBINPATH 46 47 echo "Moving vendor dir to GOPATH" 48 yes | cp -r vendor ${GOPATH}/src/ && rm -rf vendor 49 50 echo "Blitzing TGZ dirs" 51 for arch in ${!ARCHTGZDIRS[@]} 52 do 53 rm -rf ${ARCHTGZDIRS[$arch]} 54 mkdir -p ${ARCHTGZDIRS[$arch]} 55 done 56 57 echo "Building Tyk binaries" 58 gox -tags 'goplugin' -osarch="linux/amd64 linux/386" -cgo 59 # Build arm64 without CGO (no Python plugins), an improved cross-compilation toolkit is needed for that 60 gox -tags 'goplugin' -osarch="linux/arm64" 61 62 TEMPLATEDIR=${ARCHTGZDIRS[i386]} 63 echo "Prepping TGZ Dirs" 64 mkdir -p $TEMPLATEDIR/apps 65 mkdir -p $TEMPLATEDIR/js 66 mkdir -p $TEMPLATEDIR/middleware 67 mkdir -p $TEMPLATEDIR/middleware/python 68 mkdir -p $TEMPLATEDIR/middleware/lua 69 mkdir -p $TEMPLATEDIR/event_handlers 70 mkdir -p $TEMPLATEDIR/event_handlers/sample 71 mkdir -p $TEMPLATEDIR/templates 72 mkdir -p $TEMPLATEDIR/policies 73 mkdir -p $TEMPLATEDIR/utils 74 mkdir -p $TEMPLATEDIR/install 75 76 cp $SOURCEBINPATH/apps/app_sample.json $TEMPLATEDIR/apps 77 cp $SOURCEBINPATH/templates/*.json $TEMPLATEDIR/templates 78 cp -R $SOURCEBINPATH/install/* $TEMPLATEDIR/install 79 cp $SOURCEBINPATH/middleware/*.js $TEMPLATEDIR/middleware 80 cp $SOURCEBINPATH/event_handlers/sample/*.js $TEMPLATEDIR/event_handlers/sample 81 cp $SOURCEBINPATH/policies/*.json $TEMPLATEDIR/policies 82 cp $SOURCEBINPATH/tyk.conf.example $TEMPLATEDIR/ 83 cp $SOURCEBINPATH/tyk.conf.example $TEMPLATEDIR/tyk.conf 84 cp -R $SOURCEBINPATH/coprocess $TEMPLATEDIR/ 85 86 # Clone template dir to all architectures and copy corresponding binaries 87 for arch in ${!ARCHTGZDIRS[@]} 88 do 89 archDir=${ARCHTGZDIRS[$arch]} 90 [ $archDir != $TEMPLATEDIR ] && cp -R $TEMPLATEDIR/* $archDir 91 mv tyk_linux_${arch/i386/386} $archDir/$SOURCEBIN 92 done 93 94 echo "Compressing" 95 for arch in ${!ARCHTGZDIRS[@]} 96 do 97 cd ${ARCHTGZDIRS[$arch]}/../ 98 tar -pczf ${ARCHTGZDIRS[$arch]}/../tyk-linux-$arch-$VERSION.tar.gz tyk.linux.$arch-$VERSION/ 99 done 100 101 # Nothing more to do if we're not going to build packages 102 [ $BUILDPKGS != "1" ] && exit 0 103 104 CONFIGFILES=( 105 --config-files /opt/tyk-gateway/apps 106 --config-files /opt/tyk-gateway/templates 107 --config-files /opt/tyk-gateway/middleware 108 --config-files /opt/tyk-gateway/event_handlers 109 --config-files /opt/tyk-gateway/js 110 --config-files /opt/tyk-gateway/policies 111 --config-files /opt/tyk-gateway/tyk.conf 112 ) 113 FPMCOMMON=( 114 --name "$PKGNAME" 115 --description "$DESCRIPTION" 116 -v $VERSION 117 --vendor "Tyk Technologies Ltd" 118 -m "<info@tyk.io>" 119 --url "https://tyk.io" 120 -s dir 121 --before-install $TEMPLATEDIR/install/before_install.sh 122 --after-install $TEMPLATEDIR/install/post_install.sh 123 --after-remove $TEMPLATEDIR/install/post_remove.sh 124 ) 125 [ -z $PKGCONFLICTS ] || FPMCOMMON+=( --conflicts $PKGCONFLICTS ) 126 FPMRPM=( 127 --before-upgrade $TEMPLATEDIR/install/post_remove.sh 128 --after-upgrade $TEMPLATEDIR/install/post_install.sh 129 ) 130 131 cd $BUILDDIR 132 echo "Removing old packages" 133 rm -f *.deb 134 rm -f *.rpm 135 136 for arch in ${!ARCHTGZDIRS[@]} 137 do 138 archDir=${ARCHTGZDIRS[$arch]} 139 echo "Creating DEB Package for $arch" 140 fpm "${FPMCOMMON[@]}" -C $archDir -a $arch -t deb "${CONFIGFILES[@]}" ./=/opt/tyk-gateway 141 echo "Creating RPM Package for $arch" 142 fpm "${FPMCOMMON[@]}" "${FPMRPM[@]}" -C $archDir -a $arch -t rpm "${CONFIGFILES[@]}" ./=/opt/tyk-gateway 143 144 if [ $SIGNPKGS == "1" ]; then 145 echo "Signing $arch RPM" 146 rpm --define "%_gpg_name Team Tyk (package signing) <team@tyk.io>" \ 147 --define "%__gpg /usr/bin/gpg" \ 148 --addsign *.rpm || (cat /tmp/gpg-agent.log; exit 1) 149 echo "Signing $arch DEB" 150 for i in *.deb 151 do 152 dpkg-sig --sign builder -k $SIGNKEY $i || (cat /tmp/gpg-agent.log; exit 1) 153 done 154 fi 155 done