Skip to content

Commit

Permalink
add make dist
Browse files Browse the repository at this point in the history
  • Loading branch information
yyuuttaaoo committed Jul 11, 2022
1 parent bb3d0ed commit 0d0f42e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 29 deletions.
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ GO_PACKR = $(GO_PATH)/bin/packr2
GO_BUILD_FLAGS = -v

LICENSE_COVERAGE_FILE=license_coverage.txt
OUT_DIR = bin
OUT_DIR = output
DIST_DIR = ilogtail-$(VERSION)

.PHONY: tools
tools:
$(GO_LINT) version || curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin v1.39.0
$(GO_ADDLICENSE) version || GO111MODULE=off $(GO_GET) -u github.com/google/addlicense


.PHONY: clean
clean:
rm -rf $(LICENSE_COVERAGE_FILE)
rm -rf $(OUT_DIR)
rm -rf $(OUT_DIR) $(DIST_DIR)
rm -rf behavior-test
rm -rf performance-test
rm -rf core-test
Expand Down Expand Up @@ -83,13 +83,13 @@ lint-e2e: clean tools

.PHONY: core
core: clean
./scripts/gen_build_scripts.sh core $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY)
./scripts/gen_build_scripts.sh core $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY) $(OUT_DIR)
./scripts/docker_build.sh build $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY) false
./$(GENERATED_HOME)/gen_copy_docker.sh

.PHONY: plugin
plugin: clean
./scripts/gen_build_scripts.sh plugin $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY)
./scripts/gen_build_scripts.sh plugin $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY) $(OUT_DIR)
./scripts/docker_build.sh build $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY) false
./$(GENERATED_HOME)/gen_copy_docker.sh

Expand All @@ -101,12 +101,12 @@ plugin_main: clean

.PHONY: docker
docker: clean
./scripts/gen_build_scripts.sh all $(GENERATED_HOME) $(VERSION) $(DOCKER_REPOSITORY)
./scripts/gen_build_scripts.sh all $(GENERATED_HOME) $(VERSION) $(DOCKER_REPOSITORY) $(OUT_DIR)
./scripts/docker_build.sh production $(GENERATED_HOME) $(VERSION) $(DOCKER_REPOSITORY) $(DOCKER_PUSH)

.PHONY: e2edocker
e2edocker: clean
./scripts/gen_build_scripts.sh e2e $(GENERATED_HOME) $(VERSION) $(DOCKER_REPOSITORY)
./scripts/gen_build_scripts.sh e2e $(GENERATED_HOME) $(VERSION) $(DOCKER_REPOSITORY) $(OUT_DIR)
./scripts/docker_build.sh development $(GENERATED_HOME) $(VERSION) $(DOCKER_REPOSITORY) false

# provide a goc server for e2e testing
Expand Down Expand Up @@ -167,6 +167,10 @@ unittest_pluginmanager: clean

.PHONY: all
all: clean
./scripts/gen_build_scripts.sh all $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY)
./scripts/gen_build_scripts.sh all $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY) $(OUT_DIR)
./scripts/docker_build.sh build $(GENERATED_HOME) $(VERSION) $(BUILD_REPOSITORY) false
./$(GENERATED_HOME)/gen_copy_docker.sh

.PHONY: dist
dist: all
./scripts/dist.sh $(OUT_DIR) $(DIST_DIR)
2 changes: 1 addition & 1 deletion docker/Dockerfile_development_part
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ARG VERSION=1.1.0

WORKDIR /ilogtail

COPY --from=build /src/bin/libPluginBase.so /ilogtail/
COPY --from=build /src/output/libPluginBase.so /ilogtail/
COPY --from=build /src/example_config/quick_start/ilogtail_config.json /ilogtail/
COPY --from=build /src/core/build/ilogtail /ilogtail/
COPY --from=build /src/core/build/plugin/libPluginAdapter.so /ilogtail/
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile_production_part
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ARG VERSION=1.1.0

WORKDIR /usr/local/ilogtail

COPY --from=build /src/bin/libPluginBase.so /usr/local/ilogtail/
COPY --from=build /src/output/libPluginBase.so /usr/local/ilogtail/
COPY --from=build /src/example_config/start_with_container/ilogtail_config.json /usr/local/ilogtail/
COPY --from=build /src/core/build/ilogtail /usr/local/ilogtail/
COPY --from=build /src/core/build/plugin/libPluginAdapter.so /usr/local/ilogtail/
Expand Down
37 changes: 37 additions & 0 deletions scripts/dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Copyright 2021 iLogtail Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ue
set -o pipefail

# intialize variables
OUT_DIR=${1:-output}
DIST_DIR=${2:-ilogtail-1.1.0}
ROOTDIR=$(cd $(dirname "${BASH_SOURCE[0]}") && cd .. && pwd)

# prepare dist dir
mkdir "${ROOTDIR}/${DIST_DIR}"
cp LICENSE README.md README-cn.md "${ROOTDIR}/${DIST_DIR}"
cp "${ROOTDIR}/${OUT_DIR}/ilogtail" "${ROOTDIR}/${DIST_DIR}"
cp "${ROOTDIR}/${OUT_DIR}/libPluginAdapter.so" "${ROOTDIR}/${DIST_DIR}"
cp "${ROOTDIR}/${OUT_DIR}/libPluginBase.so" "${ROOTDIR}/${DIST_DIR}"
cp -a "${ROOTDIR}/example_config" "${ROOTDIR}/${DIST_DIR}"

# pack dist dir
cd "${ROOTDIR}"
tar -cvzf "${DIST_DIR}.tar.gz" "${DIST_DIR}"
rm -rf "${DIST_DIR}"
cd -
13 changes: 7 additions & 6 deletions scripts/gen_build_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,37 @@ export CATEGORY=$1
GENERATED_HOME=$2
export VERSION=${3:-1.1.0}
export REPOSITORY=${4:-aliyun/ilogtail}
export OUT_DIR=${5:-output}

BUILD_SCRIPT_FILE=$GENERATED_HOME/gen_build.sh
COPY_SCRIPT_FILE=$GENERATED_HOME/gen_copy_docker.sh

function generateBuildScript() {
rm -rf $BUILD_SCRIPT_FILE && touch $BUILD_SCRIPT_FILE && chmod 755 $BUILD_SCRIPT_FILE
if [ $CATEGORY = "plugin" ]; then
echo './scripts/plugin_build.sh vendor c-shared' >> $BUILD_SCRIPT_FILE;
echo './scripts/plugin_build.sh vendor c-shared '${OUT_DIR} >> $BUILD_SCRIPT_FILE;
elif [ $CATEGORY = "core" ]; then
echo "mkdir -p core/build && cd core/build && cmake -D LOGTAIL_VERSION=${VERSION} .. && make -sj\$(nproc)" >> $BUILD_SCRIPT_FILE;
elif [ $CATEGORY = "all" ]; then
echo "./scripts/plugin_build.sh vendor c-shared && mkdir -p core/build && cd core/build && cmake -D LOGTAIL_VERSION=${VERSION} .. && make -sj\$(nproc)" >> $BUILD_SCRIPT_FILE;
echo "./scripts/plugin_build.sh vendor c-shared ${OUT_DIR} && mkdir -p core/build && cd core/build && cmake -D LOGTAIL_VERSION=${VERSION} .. && make -sj\$(nproc)" >> $BUILD_SCRIPT_FILE;
elif [ $CATEGORY = "e2e" ]; then
echo "./scripts/plugin_gocbuild.sh && mkdir -p core/build && cd core/build && cmake -D LOGTAIL_VERSION=${VERSION} .. && make -sj\$(nproc)" >> $BUILD_SCRIPT_FILE;
echo "./scripts/plugin_gocbuild.sh ${OUT_DIR} && mkdir -p core/build && cd core/build && cmake -D LOGTAIL_VERSION=${VERSION} .. && make -sj\$(nproc)" >> $BUILD_SCRIPT_FILE;
fi
}

function generateCopyScript() {
rm -rf $COPY_SCRIPT_FILE && touch $COPY_SCRIPT_FILE && chmod 755 $COPY_SCRIPT_FILE
echo 'BINDIR=$(cd $(dirname "${BASH_SOURCE[0]}")&& cd .. && pwd)/bin/' >> $COPY_SCRIPT_FILE
echo 'BINDIR=$(cd $(dirname "${BASH_SOURCE[0]}")&& cd .. && pwd)/'${OUT_DIR}'/' >> $COPY_SCRIPT_FILE
echo 'rm -rf $BINDIR && mkdir $BINDIR' >> $COPY_SCRIPT_FILE
echo "id=\$(docker create ${REPOSITORY}:${VERSION})" >> $COPY_SCRIPT_FILE

if [ $CATEGORY = "plugin" ]; then
echo 'docker cp "$id":/src/bin/libPluginBase.so $BINDIR' >> $COPY_SCRIPT_FILE;
echo 'docker cp "$id":/src/'${OUT_DIR}'/libPluginBase.so $BINDIR' >> $COPY_SCRIPT_FILE;
elif [ $CATEGORY = "core" ]; then
echo 'docker cp "$id":/src/core/build/ilogtail $BINDIR' >> $COPY_SCRIPT_FILE;
echo 'docker cp "$id":/src/core/build/plugin/libPluginAdapter.so $BINDIR' >> $COPY_SCRIPT_FILE;
else
echo 'docker cp "$id":/src/bin/libPluginBase.so $BINDIR' >> $COPY_SCRIPT_FILE;
echo 'docker cp "$id":/src/'${OUT_DIR}'/libPluginBase.so $BINDIR' >> $COPY_SCRIPT_FILE;
echo 'docker cp "$id":/src/core/build/ilogtail $BINDIR' >> $COPY_SCRIPT_FILE;
echo 'docker cp "$id":/src/core/build/plugin/libPluginAdapter.so $BINDIR' >> $COPY_SCRIPT_FILE;
fi
Expand Down
8 changes: 4 additions & 4 deletions scripts/plugin_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# limitations under the License.

function os() {

if uname -s | grep Darwin; then
return 2
elif uname -s | grep Linux; then
Expand All @@ -25,8 +24,9 @@ function os() {
fi
}

MOD=$1
BUILDMODE=$2
MOD=${1:-vendor}
BUILDMODE=${2:-default}
OUT_DIR=${3:-output}
NAME=ilogtail
IDFLAGS=''

Expand All @@ -51,4 +51,4 @@ elif [ $OS_FLAG = 2 ]; then
BUILDMODE=default
fi

go build -mod="$MOD" -buildmode="$BUILDMODE" -ldflags="$IDFLAGS" -o "$ROOTDIR"/bin/${NAME} "$ROOTDIR"/plugin_main
go build -mod="$MOD" -buildmode="$BUILDMODE" -ldflags="$IDFLAGS" -o "$ROOTDIR/$OUT_DIR/${NAME}" "$ROOTDIR"/plugin_main
19 changes: 10 additions & 9 deletions scripts/plugin_gocbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
NAME=libPluginBase.so
goc version
if [ $? != 0 ]; then
echo "==========================================================================================================="
echo "goc is not install on your test machine, please install it by the doc https://github.com/qiniu/goc."
echo "If you don't find binary lib on your platform or arch, you also could run e2e with normal docker container."
echo "==========================================================================================================="
exit 1
echo "==========================================================================================================="
echo "goc is not install on your test machine, please install it by the doc https://github.com/qiniu/goc."
echo "If you don't find binary lib on your platform or arch, you also could run e2e with normal docker container."
echo "==========================================================================================================="
exit 1
fi

OUT_DIR=${1:-output}
ROOTDIR=$(cd $(dirname "${BASH_SOURCE[0]}") && cd .. && pwd)
if [ -d "$ROOTDIR"/bin ]; then
rm -rf $ROOTDIR/bin
if [ -d "$ROOTDIR/$OUT_DIR" ]; then
rm -rf "$ROOTDIR/$OUT_DIR"
fi
mkdir "$ROOTDIR"/bin
mkdir "$ROOTDIR/$OUT_DIR"

cd "$ROOTDIR"/plugin_main
pwd

if uname -s | grep Linux; then
goc build '--buildflags=-mod=vendor -buildmode=c-shared -ldflags="-extldflags "-Wl,--wrap=memcpy""' --center=http://goc:7777 -o "$ROOTDIR"/bin/${NAME}
goc build '--buildflags=-mod=vendor -buildmode=c-shared -ldflags="-extldflags "-Wl,--wrap=memcpy""' --center=http://goc:7777 -o "$ROOTDIR/$OUT_DIR/${NAME}"
else
echo "goc build only build a dynamic library in linux platform"
exit 1
Expand Down

0 comments on commit 0d0f42e

Please sign in to comment.