Skip to content

Commit

Permalink
Separating binaries into strict and optional
Browse files Browse the repository at this point in the history
  • Loading branch information
arykalin committed Mar 18, 2019
1 parent c0c62e5 commit 6abf72d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
20 changes: 2 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,17 @@ clean:

build: build_strict build_optional

#LDFLAGS_OPT := -s -w -extldflags "-static" -X pki.VenafiPolciyCheck=true -X pki.VenafiPolicyDenyAll=false
#LDFLAGS_STRICT := -s -w -extldflags "-static" -X pki.VenafiPolciyCheck=true -X pki.VenafiPolicyDenyAll=true
LDFLAGS_OPT := -s -w -extldflags "-static"
build_strict:
scripts/build.sh $(PLUGIN_NAME) $(PLUGIN_DIR) strict
scripts/build.sh $(PLUGIN_NAME) $(PLUGIN_DIR) $(DIST_DIR) strict $(VERSION)

build_optional:
scripts/build.sh $(PLUGIN_NAME) $(PLUGIN_DIR) optional
scripts/build.sh $(PLUGIN_NAME) $(PLUGIN_DIR) $(DIST_DIR) optional $(VERSION)


dev_build:
sed -i 's/const venafiPolicyDenyAll =.*/const venafiPolicyDenyAll = true/' plugin/pki/vcert.go
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '$(LDFLAGS_STRICT)' -a -o $(PLUGIN_DIR)/$(PLUGIN_NAME) || exit 1

compress:
mkdir -p $(DIST_DIR)
rm -f $(DIST_DIR)/*
for os in linux linux86 darwin darwin86; do \
for mode in strict optional; do \
sha256sum pkg/bin/$${os}/$(PLUGIN_NAME)_$${mode} > ${CURRENT_DIR}/$(DIST_DIR)/${PLUGIN_NAME}_${VERSION}_$${os}_$${mode}.SHA256SUM && \
sed -i "s#pkg/bin/$${os}/##" ${CURRENT_DIR}/$(DIST_DIR)/${PLUGIN_NAME}_${VERSION}_$${os}_$${mode}.SHA256SUM && \
zip -j "${CURRENT_DIR}/$(DIST_DIR)/${PLUGIN_NAME}_${VERSION}_$${os}_$${mode}.zip" "$(PLUGIN_DIR)/$${os}/$(PLUGIN_NAME)_$${mode}" ; done ; done
for os in windows windows86; do \
for mode in strict optional; do \
sha256sum pkg/bin/$${os}/$(PLUGIN_NAME)_$${mode}.exe > ${CURRENT_DIR}/$(DIST_DIR)/${PLUGIN_NAME}_${VERSION}_$${os}_$${mode}.SHA256SUM && \
sed -i "s#pkg/bin/$${os}/##" ${CURRENT_DIR}/$(DIST_DIR)/${PLUGIN_NAME}_${VERSION}_$${os}_$${mode}.SHA256SUM && \
zip -j "${CURRENT_DIR}/$(DIST_DIR)/${PLUGIN_NAME}_${VERSION}_$${os}_$${mode}.zip" "$(PLUGIN_DIR)/$${os}/$(PLUGIN_NAME)_$${mode}.exe" ; done

mount_dev: unset
vault write sys/plugins/catalog/$(PLUGIN_NAME) sha_256="$(SHA256)" command="$(PLUGIN_NAME)"
Expand Down
15 changes: 14 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ set -e

PLUGIN_NAME=$1
PLUGIN_DIR=$2
BUILD_MODE=$3
DIST_DIR=$3
BUILD_MODE=$4
VERSION=$5
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

if [ ${BUILD_MODE}=="strict" ]; then
echo "Changing venafiPolicyDenyAll to true"
Expand All @@ -16,19 +19,29 @@ else
exit 1
fi

mkdir -p ${CURRENT_DIR}/../${DIST_DIR}

for os in linux darwin windows; do
for arch in 386 amd64; do
if echo ${arch}|grep --quiet 386; then
binary_name="${PLUGIN_DIR}/${os}86/${PLUGIN_NAME}_${BUILD_MODE}"
archive_name="${CURRENT_DIR}/../${DIST_DIR}/${PLUGIN_NAME}_${VERSION}_${os}86_${BUILD_MODE}"
else
binary_name="${PLUGIN_DIR}/${os}/${PLUGIN_NAME}_${BUILD_MODE}"
archive_name="${CURRENT_DIR}/../${DIST_DIR}/${PLUGIN_NAME}_${VERSION}_${os}_${BUILD_MODE}"
fi
if echo ${os}|grep --quiet windows; then
binary_name="${binary_name}.exe"
fi
echo "Building plugin binary ${binary_name} for ${os}-${arch}"
env CGO_ENABLED=0 GOOS=${os} GOARCH=${arch} go build -ldflags '-s -w -extldflags "-static"' -a -o ${binary_name} || exit 1
chmod +x ${binary_name}
echo "Archiving binary into ${archive_name}.zip"
SHA256=$(sha256sum ${binary_name}| head -c 64)
echo "${SHA256} ${PLUGIN_NAME}_${BUILD_MODE}" > ${archive_name}.SHA256SUM
zip -j "${archive_name}.zip" "${binary_name}"
done
done

echo "Checksums for binaries:"
cat ${CURRENT_DIR}/../${DIST_DIR}/*.SHA256SUM

0 comments on commit 6abf72d

Please sign in to comment.