github.com/dbernstein1/tyk@v2.9.0-beta9-dl-apic+incompatible/bin/dist_build.sh (about) 1 #!/bin/bash 2 : ${ORGDIR:="/src/github.com/TykTechnologies"} 3 : ${SOURCEBINPATH:="${ORGDIR}/tyk"} 4 : ${SIGNKEY:="729EA673"} 5 : ${BUILDPKGS:="1"} 6 : ${PKGNAME:="tyk-gateway"} 7 BUILDTOOLSDIR=$SOURCEBINPATH/build_tools 8 BUILDDIR=$SOURCEBINPATH/build 9 10 echo "Set version number" 11 : ${VERSION:=$(perl -n -e'/v(\d+).(\d+).(\d+)/'' && print "$1\.$2\.$3"' version.go)} 12 13 if [ $BUILDPKGS == "1" ]; then 14 echo "Importing signing key" 15 gpg --list-keys | grep -w $SIGNKEY && echo "Key exists" || gpg --batch --import $BUILDTOOLSDIR/build_key.key 16 fi 17 18 echo "Prepare the release directories" 19 20 export SOURCEBIN=tyk 21 export CLIBIN=tyk-cli 22 23 declare -A ARCHTGZDIRS 24 ARCHTGZDIRS=( 25 [i386]=$BUILDDIR/i386/tgz/tyk.linux.i386-$VERSION 26 [amd64]=$BUILDDIR/amd64/tgz/tyk.linux.amd64-$VERSION 27 [arm64]=$BUILDDIR/arm/tgz/tyk.linux.arm64-$VERSION 28 ) 29 30 cliDIR=$ORGDIR/tyk-cli 31 cliTmpDir=$SOURCEBINPATH/temp/cli 32 DESCRIPTION="Tyk Open Source API Gateway written in Go" 33 34 echo "Clearing CLI temp folder" 35 rm -rf $cliTmpDir 36 mkdir -p $cliTmpDir 37 38 echo "Preparing CLI Build" 39 cd $ORGDIR 40 [ -d $cliDIR ] || git clone https://github.com/TykTechnologies/tyk-cli.git 41 cd $cliDIR 42 git checkout master 43 git pull 44 go get -v ./... 45 gox -osarch="linux/arm64 linux/amd64 linux/386" 46 47 echo "Copying CLI Build files" 48 mv tyk-cli_linux_* $cliTmpDir/ 49 50 echo "Starting Tyk build" 51 cd $SOURCEBINPATH 52 53 echo "Blitzing TGZ dirs" 54 for arch in ${!ARCHTGZDIRS[@]} 55 do 56 rm -rf ${ARCHTGZDIRS[$arch]} 57 mkdir -p ${ARCHTGZDIRS[$arch]} 58 done 59 60 echo "Building Tyk binaries" 61 gox -osarch="linux/arm64 linux/amd64 linux/386" -tags 'coprocess grpc' 62 63 echo "Building Tyk CP binaries" 64 export CPBINNAME_LUA=tyk_linux_amd64_lua 65 export CPBINNAME_PYTHON=tyk_linux_amd64_python 66 67 gox -osarch="linux/amd64" -tags 'coprocess python' -output '{{.Dir}}_{{.OS}}_{{.Arch}}_python' 68 gox -osarch="linux/amd64" -tags 'coprocess lua' -output '{{.Dir}}_{{.OS}}_{{.Arch}}_lua' 69 70 TEMPLATEDIR=${ARCHTGZDIRS[i386]} 71 echo "Prepping TGZ Dirs" 72 mkdir -p $TEMPLATEDIR/apps 73 mkdir -p $TEMPLATEDIR/js 74 mkdir -p $TEMPLATEDIR/middleware 75 mkdir -p $TEMPLATEDIR/middleware/python 76 mkdir -p $TEMPLATEDIR/middleware/lua 77 mkdir -p $TEMPLATEDIR/event_handlers 78 mkdir -p $TEMPLATEDIR/event_handlers/sample 79 mkdir -p $TEMPLATEDIR/templates 80 mkdir -p $TEMPLATEDIR/policies 81 mkdir -p $TEMPLATEDIR/utils 82 mkdir -p $TEMPLATEDIR/install 83 84 cp $SOURCEBINPATH/apps/app_sample.json $TEMPLATEDIR/apps 85 cp $SOURCEBINPATH/templates/*.json $TEMPLATEDIR/templates 86 cp -R $SOURCEBINPATH/install/* $TEMPLATEDIR/install 87 cp $SOURCEBINPATH/middleware/*.js $TEMPLATEDIR/middleware 88 cp $SOURCEBINPATH/event_handlers/sample/*.js $TEMPLATEDIR/event_handlers/sample 89 cp $SOURCEBINPATH/policies/*.json $TEMPLATEDIR/policies 90 cp $SOURCEBINPATH/tyk.conf.example $TEMPLATEDIR/ 91 cp $SOURCEBINPATH/tyk.conf.example $TEMPLATEDIR/tyk.conf 92 cp -R $SOURCEBINPATH/coprocess $TEMPLATEDIR/ 93 94 # Clone template dir to all architectures and copy corresponding binaries 95 for arch in ${!ARCHTGZDIRS[@]} 96 do 97 archDir=${ARCHTGZDIRS[$arch]} 98 [ $archDir != $TEMPLATEDIR ] && cp -R $TEMPLATEDIR/* $archDir 99 mv tyk_linux_${arch/i386/386} $archDir/$SOURCEBIN 100 cp $cliTmpDir/tyk-cli_linux_${arch/i386/386} $archDir/utils/$CLIBIN 101 done 102 mv $CPBINNAME_LUA ${ARCHTGZDIRS[amd64]}/$SOURCEBIN-lua 103 mv $CPBINNAME_PYTHON ${ARCHTGZDIRS[amd64]}/$SOURCEBIN-python 104 105 echo "Compressing" 106 for arch in ${!ARCHTGZDIRS[@]} 107 do 108 cd ${ARCHTGZDIRS[$arch]}/../ 109 tar -pczf ${ARCHTGZDIRS[$arch]}/../tyk-linux-$arch-$VERSION.tar.gz tyk.linux.$arch-$VERSION/ 110 done 111 112 # Nothing more to do if we're not going to build packages 113 [ $BUILDPKGS != "1" ] && exit 0 114 115 CONFIGFILES=( 116 --config-files /opt/tyk-gateway/apps 117 --config-files /opt/tyk-gateway/templates 118 --config-files /opt/tyk-gateway/middleware 119 --config-files /opt/tyk-gateway/event_handlers 120 --config-files /opt/tyk-gateway/js 121 --config-files /opt/tyk-gateway/policies 122 --config-files /opt/tyk-gateway/tyk.conf 123 ) 124 FPMCOMMON=( 125 --name "$PKGNAME" 126 --description "$DESCRIPTION" 127 -v $VERSION 128 --vendor "Tyk Technologies Ltd" 129 -m "<info@tyk.io>" 130 --url "https://tyk.io" 131 -s dir 132 --before-install $TEMPLATEDIR/install/before_install.sh 133 --after-install $TEMPLATEDIR/install/post_install.sh 134 --after-remove $TEMPLATEDIR/install/post_remove.sh 135 ) 136 [ -z $PKGCONFLICTS ] || FPMCOMMON+=( --conflicts $PKGCONFLICTS ) 137 FPMRPM=( 138 --before-upgrade $TEMPLATEDIR/install/post_remove.sh 139 --after-upgrade $TEMPLATEDIR/install/post_install.sh 140 ) 141 142 cd $BUILDDIR 143 echo "Removing old packages" 144 rm -f *.deb 145 rm -f *.rpm 146 147 for arch in ${!ARCHTGZDIRS[@]} 148 do 149 archDir=${ARCHTGZDIRS[$arch]} 150 echo "Creating DEB Package for $arch" 151 fpm "${FPMCOMMON[@]}" -C $archDir -a $arch -t deb "${CONFIGFILES[@]}" ./=/opt/tyk-gateway 152 echo "Creating RPM Package for $arch" 153 fpm "${FPMCOMMON[@]}" "${FPMRPM[@]}" -C $archDir -a $arch -t rpm "${CONFIGFILES[@]}" ./=/opt/tyk-gateway 154 155 rpmName="$PKGNAME-$VERSION-1.${arch/amd64/x86_64}.rpm" 156 echo "Signing $arch RPM" 157 $BUILDTOOLSDIR/rpm-sign.sh $rpmName 158 done