Skip to content

Commit

Permalink
feat: autosupport Build Changes (#541)
Browse files Browse the repository at this point in the history
* feat: autosupport Build Changes

* feat: pass platform as argument for asup

* feat: pass platform as argument for asup

* feat: pass platform as argument for asup

* feat: address review comments
  • Loading branch information
rahulguptajss authored Oct 6, 2021
1 parent 276fc08 commit 5eefa40
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 27 deletions.
23 changes: 23 additions & 0 deletions .github/fetch-asup
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

if [ $# -ne 3 ]; then
echo "You need to provide ASUP_BIN, ASUP_BINARY_VERSION and BIN_PLATFORM as arguments"
exit 1
fi

ASUP_BIN_DIR=$(pwd)/"$1"
ASUP_BIN_VERSION="$2"
BIN_PLATFORM="$3"
mkdir -p "$ASUP_BIN_DIR"

COUNT_REPO_FOLDERS=($(find $ASUP_BIN_DIR/github.com/!net!app -mindepth 1 -maxdepth 1 -type d | wc -l))
if [ $COUNT_REPO_FOLDERS -gt 5 ]; then
rm -rf $ASUP_BIN_DIR/*
fi
GOMODCACHE=$ASUP_BIN_DIR go mod download github.com/NetApp/harvest-metrics@"$ASUP_BIN_VERSION"
mod_bin=$(find "$ASUP_BIN_DIR" -name "*asup*" -name "*$BIN_PLATFORM*" -exec ls -t {} + | head -n 1)
if [ -n "${mod_bin}" ]; then
cp -f "$mod_bin" ./autosupport/asup
chmod +x ./autosupport/asup
chmod -R +rw "$ASUP_BIN_DIR/github.com/"
fi
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copyright 2021 NetApp, Inc. All Rights Reserved
.DEFAULT_GOAL:=help

.PHONY: help deps clean build test fmt vet package asup dev
.PHONY: help deps clean build test fmt vet package asup dev fetch-asup

###############################################################################
# Anything that needs to be done before we build everything
# Check for GCC, GO version, etc and anything else we are dependent on.
###############################################################################
SHELL := /bin/bash
GCC_EXISTS := $(shell which gcc)
REQUIRED_GO_VERSION := 1.17
ifneq (, $(shell which go))
Expand All @@ -28,6 +29,10 @@ ASUP_TMP := /tmp/asup
ASUP_MAKE_TARGET ?= build #one of build/production
GIT_TOKEN ?=
CURRENT_DIR = $(shell pwd)
ASUP_BIN = asup
ASUP_BIN_VERSION ?= main #change it to match tag of release branch
BIN_PLATFORM ?= linux
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)


help: ## Display this help
Expand Down Expand Up @@ -79,7 +84,7 @@ vet: ## run go vet on the source files
@echo "Running go vet"
go vet ./...

build: clean deps fmt harvest ## Build the project
build: clean deps fmt harvest fetch-asup ## Build the project

package: clean deps build test dist-tar ## Package Harvest binary

Expand Down Expand Up @@ -130,11 +135,22 @@ asup:
@rm -rf autosupport/asup
@rm -rf ${ASUP_TMP}
@mkdir ${ASUP_TMP}
@git clone https://${GIT_TOKEN}@github.com/NetApp/harvest-private.git ${ASUP_TMP}
# check if there is an equivalent branch name to harvest. If branch name is not found then take autosupport code from main branch.
@if [[ $(shell git ls-remote --heads https://${GIT_TOKEN}@github.com/NetApp/harvest-private.git ${BRANCH} | wc -l | xargs) == 0 ]]; then\
git clone -b main https://${GIT_TOKEN}@github.com/NetApp/harvest-private.git ${ASUP_TMP};\
else\
git clone -b ${BRANCH} https://${GIT_TOKEN}@github.com/NetApp/harvest-private.git ${ASUP_TMP};\
fi
@cd ${ASUP_TMP}/harvest-asup && make ${ASUP_MAKE_TARGET} VERSION=${VERSION} RELEASE=${RELEASE}
@mkdir -p ${CURRENT_DIR}/autosupport
@cp ${ASUP_TMP}/harvest-asup/bin/asup ${CURRENT_DIR}/autosupport

dev: build
@echo "Deleting AutoSupport binary"
@rm -rf autosupport/asup
@rm -rf autosupport/asup

fetch-asup:
@./.github/fetch-asup ${ASUP_BIN} ${ASUP_BIN_VERSION} ${BIN_PLATFORM} 2>/dev/null #Suppress Error in case of internet connectivity



Binary file removed autosupport/asup
Binary file not shown.
Binary file removed autosupport/asup_alpine_amd64
Binary file not shown.
11 changes: 5 additions & 6 deletions deb/build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mkdir -p "$BUILD"
mkdir -p "$BUILD/opt/harvest/bin/"
cp -r "$SRC/grafana" "$SRC/conf" "$BUILD/opt/harvest/"
cp "$SRC/harvest.yml" "$SRC/prom-stack.yml" "$SRC/harvest.cue" "$BUILD/opt/harvest/"
cp -r "$SRC/.github/" "$BUILD/opt/harvest/"
cp -r "$SRC/pkg/" "$SRC/cmd/" "$SRC/docs/" "$SRC/docker/" "$BUILD/opt/harvest/"
cp -r "$SRC/rpm/" "$SRC/deb/" "$SRC/service/" "$SRC/autosupport/" "$SRC/.git" "$BUILD/opt/harvest/"
cp "$SRC/Makefile" "$SRC/README.md" "$SRC/LICENSE" "$SRC/go.mod" "$SRC/go.sum" "$BUILD/opt/harvest/"
Expand Down Expand Up @@ -51,18 +52,16 @@ if [ "$HARVEST_ARCH" = "armhf" ]; then
export GOARM="7"
fi
echo " --> build harvest with envs [GOOS=$GOOS, GOARCH=$GOARCH, GOARM=$GOARM]"
if [ -n "$ASUP_MAKE_TARGET" ] && [ -z "$GIT_TOKEN" ]
then
echo "GIT_TOKEN is required when ASUP_MAKE_TARGET is passed!"
exit 1
fi

if [ -n "$ASUP_MAKE_TARGET" ] && [ -n "$GIT_TOKEN" ]
then
make asup build VERSION=$VERSION RELEASE=$RELEASE ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET GIT_TOKEN=$GIT_TOKEN
make build asup VERSION=$VERSION RELEASE=$RELEASE ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET GIT_TOKEN=$GIT_TOKEN
else
make build VERSION=$HARVEST_VERSION RELEASE=$HARVEST_RELEASE
fi

rm -rf $BUILD/opt/harvest/asup/*

if [ ! $? -eq 0 ]; then
error " build failed"
exit 1
Expand Down
18 changes: 9 additions & 9 deletions docker/onePollerPerContainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
FROM golang:1.17-alpine as golangAlpine

RUN apk add curl && apk add --virtual build-dependencies build-base gcc
RUN apk add curl && apk add --virtual build-dependencies build-base gcc git bash

ARG INSTALL_DIR=/opt/harvest
ARG BUILD_DIR=/opt/home
ARG VERSION=2.0
ARG RELEASE=nightly

RUN echo $VERSION
RUN echo $RELEASE
ARG GIT_TOKEN
ARG ASUP_MAKE_TARGET=build

# Set the Current Working Directory inside the container
WORKDIR $BUILD_DIR
Expand All @@ -17,14 +16,15 @@ RUN mkdir -p $INSTALL_DIR

COPY . .

RUN make build VERSION=$VERSION RELEASE=$RELEASE
RUN if [[ -n "$ASUP_MAKE_TARGET" && -n "$GIT_TOKEN" ]]; then \
make build asup VERSION=$VERSION RELEASE=$RELEASE ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET GIT_TOKEN=$GIT_TOKEN ; \
else \
make build VERSION=$VERSION RELEASE=$RELEASE BIN_PLATFORM=alpine ;\
fi

RUN cp -a $BUILD_DIR/harvest.yml $INSTALL_DIR/harvest.yml

RUN cp -aR bin $BUILD_DIR/conf $BUILD_DIR/docs $BUILD_DIR/grafana $BUILD_DIR/autosupport $INSTALL_DIR &&\
rm $INSTALL_DIR/autosupport/asup &&\
mv $INSTALL_DIR/autosupport/asup_alpine_amd64 $INSTALL_DIR/autosupport/asup &&\
chmod u=rwx,g=rx,o=rx $INSTALL_DIR/autosupport/asup
RUN cp -aR bin $BUILD_DIR/conf $BUILD_DIR/docs $BUILD_DIR/grafana $BUILD_DIR/autosupport $INSTALL_DIR

FROM alpine:latest

Expand Down
4 changes: 2 additions & 2 deletions jenkins/artifacts/jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pipeline {
export PATH=$PATH:/usr/local/go/bin
targetLocation=$targetParentLocation$VERSION-$RELEASE-$BRANCH
rm -rf dist
make asup package VERSION=$VERSION RELEASE=$RELEASE ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET GIT_TOKEN=$GIT_TOKEN
make build asup test dist-tar VERSION=$VERSION RELEASE=$RELEASE ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET GIT_TOKEN=$GIT_TOKEN
cp -RT ./dist/ $targetLocation
cp ./autosupport/asup $targetLocation/asup_linux_amd64
'''
Expand All @@ -134,7 +134,7 @@ pipeline {
cd $harvestPath
targetLocation=$targetParentLocation$VERSION-$RELEASE-$BRANCH
docker login
docker build -f docker/onePollerPerContainer/Dockerfile --build-arg VERSION=$VERSION --build-arg RELEASE=$RELEASE -t ${imageName}:latest -t ${imageName}:$VERSION-$RELEASE . --no-cache
docker build -f docker/onePollerPerContainer/Dockerfile --build-arg VERSION=$VERSION --build-arg RELEASE=$RELEASE --build-arg ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET --build-arg GIT_TOKEN=$GIT_TOKEN -t ${imageName}:latest -t ${imageName}:$VERSION-$RELEASE . --no-cache
docker save -o ${targetLocation}/docker_harvest.tar ${imageName}:latest
'''
}
Expand Down
11 changes: 5 additions & 6 deletions rpm/build-rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cp "$SRC/prom-stack.yml" "$BUILD/harvest/"
cp "$SRC/harvest.cue" "$BUILD/harvest/"
cp "$SRC/go.mod" "$BUILD/harvest/"
cp "$SRC/go.sum" "$BUILD/harvest/"
cp -r "$SRC/.github/" "$BUILD/harvest/"
if [ -d "$SRC/vendor" ]; then
cp -r "$SRC/vendor" "$BUILD/harvest/"
fi
Expand All @@ -42,18 +43,16 @@ cp "$SRC/LICENSE" "$BUILD/harvest/"
# build binaries
echo "building binaries"
cd "$BUILD/harvest"
if [ -n "$ASUP_MAKE_TARGET" ] && [ -z "$GIT_TOKEN" ]
then
echo "GIT_TOKEN is required when ASUP_MAKE_TARGET is passed!"
exit 1
fi

if [ -n "$ASUP_MAKE_TARGET" ] && [ -n "$GIT_TOKEN" ]
then
make asup build VERSION=$VERSION RELEASE=$RELEASE ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET GIT_TOKEN=$GIT_TOKEN
make build asup VERSION=$VERSION RELEASE=$RELEASE ASUP_MAKE_TARGET=$ASUP_MAKE_TARGET GIT_TOKEN=$GIT_TOKEN
else
make build VERSION=$HARVEST_VERSION RELEASE=$HARVEST_RELEASE
fi

rm -rf $BUILD/harvest/asup/*

if [ ! $? -eq 0 ]; then
echo "build failed, aborting"
exit 1
Expand Down

0 comments on commit 5eefa40

Please sign in to comment.