Skip to content

Commit

Permalink
add make dist (#192)
Browse files Browse the repository at this point in the history
* add make dist

* fix docs
  • Loading branch information
yyuuttaaoo authored Jul 11, 2022
1 parent bb3d0ed commit cfe75b5
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 56 deletions.
26 changes: 17 additions & 9 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,30 +83,34 @@ 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

.PHONY: plugin_main
plugin_main: clean
./scripts/plugin_build.sh vendor default
./scripts/plugin_build.sh vendor default $(OUT_DIR)
cp pkg/logtail/libPluginAdapter.so bin/libPluginAdapter.so
cp pkg/logtail/PluginAdapter.dll bin/PluginAdapter.dll

.PHONY: plugin_local
plugin_main:
./scripts/plugin_build.sh vendor c-shared $(OUT_DIR)

.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 +171,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)
10 changes: 5 additions & 5 deletions README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ iLogtail 为可观测场景而生,拥有的轻量级、高性能、自动化
# Build ilogtail and plugins
make all
# Let's start with a simple config
cp -a example_config/quick_start/* bin
cp -a example_config/quick_start/* output
# Start ilogtail
cd bin
cd output
nohup ./ilogtail > stdout.log 2> stderr.log &
# Generate a log
echo 'hello world!' >> simple.log
Expand All @@ -61,22 +61,22 @@ cat stdout.log
2.完整模式Docker启动

```shell
make wholedocker
make docker
docker run -d --name ilogtail-ds -v core/example_config/user_yaml_config.d:/usr/local/ilogtail/user_yaml_config.d aliyun/ilogtail:local-build
```

3.完整模式K8s启动

```shell
VERSION=snapshot make wholedocker
VERSION=snapshot make docker
kubectl apply -f xxx-configmap.yaml
kubectl apply -f xxx-deployment.yaml
```

4.纯插件模式本地启动

```shell
make build && sh bin/ilogtail
make pluin_main && sh output/ilogtail
```

> **注意**: 对一些高版本Linux需要提前安装systemd-devel
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This repository is the golang part of **iLogtail**,it contains most of the fea
1. Start with local

```shell
make build && sh bin/ilogtail
make pluin_main && sh output/ilogtail
```

> **NOTE**: for some higher linux version, you have to install systemd-devel in advance
Expand Down
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
12 changes: 6 additions & 6 deletions docs/en/guides/How-to-do-manual-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ familiar with [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/289

You can verify your case with the following 3 steps on standalone mode:

1. Run *make build* to compile, and the binary program will be located in *bin/ilogtail*.
1. Run *make plugin_main* to compile, and the binary program will be located in *output/ilogtail*.
2. Prepare to test the demo.json file.
3. Run *./bin/ilogtail --plugin=./demo.json* to start the program,
3. Run *./output/ilogtail --plugin=./demo.json* to start the program,

The following parts will introduce how the input and processor plugins perform local manual testing with standalone
mode.
Expand All @@ -24,7 +24,7 @@ to run it, such as [E2E nginx](../../../test/case/behavior/input_nginx). Of cour
environment locally, you can also run it locally. The following example shows the collection of nginx status, and
IntervalMs indicates that the acquisition frequency is 1s once. You cloud test the running state with **
TEST_SCOPE=input_nginx TEST_DEBUG=true make e2e** command in the project root path. For the local startup, the collected
output is saved in the *logtail_plugin.LOG* file, that is also cloud be printed to the stdout with *./bin/ilogtail
output is saved in the *logtail_plugin.LOG* file, that is also cloud be printed to the stdout with *./output/ilogtail
--plugin=./demo.json --logger-console=true --logger-retain=false* command.

```json
Expand Down Expand Up @@ -56,7 +56,7 @@ For the processor plugin, you can use metric_mock or service_mock to mock the co
to verify and test the processor_add_fields plugin function, and metric_mock simulates the collection of input Key/Value
data is 1111:2222 pair, the final output contains 3 fields after processor_add_fields processing. For the local startup,
the collected output is saved in the *logtail_plugin.LOG* file, that is also cloud be printed to the stdout with *
./bin/ilogtail --plugin=./demo.json --logger-console=true --logger-retain=false* command.
./output/ilogtail --plugin=./demo.json --logger-console=true --logger-retain=false* command.

```json
{
Expand Down Expand Up @@ -105,15 +105,15 @@ program written by yourself.

### Run [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html) on ECS

1. Run `make solib` to compile so library, and the compiled program is `bin/libPluginBase.so`.
1. Run `make plugin` to compile so library, and the compiled program is `output/libPluginBase.so`.
2. Login the ECS host.
3. Execute `cd /usr/local/ilogtail/`, and stop the [Logtail AlibabaCloud] program with `README` guides.
4. Replace the compiled `libPluginBase.so` program with the compiled `libPluginBase.so` program.
5. Restart the [Logtail AlibabaCloud] program with `README` guides.

### Run [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html) on container

1. Run `make wholedocker` to compile [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html) docker
1. Run `make docker` to compile [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html) docker
images named `aliyun/ilogtail:1.1.0`.
2. Rename `aliyun/ilogtail:1.1.0` to a custom name and push to the remotes, such
as `registry.cn-beijing.aliyuncs.com/aliyun/ilogtail:1.1.0`.
Expand Down
8 changes: 4 additions & 4 deletions docs/en/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Please debug in the corresponding environment. More details please see [here](..

### Local start

Execute the `make build` command in the root directory, and you will get the `bin/ilogtail` executable file. Use the
Execute the `make plugin_main` command in the root directory, and you will get the `output/ilogtail` executable file. Use the
following command to quickly start the iLogtail program.

```shell
# The default startup behavior is to use the metric_mock plugin to mock data and print the data to the logs.
./bin/ilogtail --logger-console=true --logger-retain=false
./output/ilogtail --logger-console=true --logger-retain=false
```

### Docker start
Expand Down Expand Up @@ -143,7 +143,7 @@ The following is a very simple example configuration file (plugin.quickstart.jso
}
```

Execute `./bin/ilogtail --plugin=plugin.quickstart.json`, after a period of time, use ctrl+c to interrupt the operation.
Execute `./output/ilogtail --plugin=plugin.quickstart.json`, after a period of time, use ctrl+c to interrupt the operation.
By checking the directory, you will find that two files, quickstart_1.stdout and quickstart_2.stdout, are generated, and
their contents are the same.

Expand All @@ -155,7 +155,7 @@ running independently, port 18689 is enabled by default for monitoring configura
Next, we will use the HTTP mode to re-load the static configuration example in the section **Specified configuration
file mode startup**.

1. First we start the iLogtail program: `./bin/ilogtail`
1. First we start the iLogtail program: `./output/ilogtail`
2. Use the following command to reload the configuration.

```shell
Expand Down
12 changes: 6 additions & 6 deletions docs/zh/guides/How-to-do-manual-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ iLogtail作为[Logtail AlibabaCloud](https://help.aliyun.com/document_detail/289

独立模式运行步骤仅仅以下3个步骤:

1. 运行*make build* 进行编译,编译后的程序将位于*bin/ilogtail*
1. 运行*make plugin_main* 进行编译,编译后的程序将位于*output/ilogtail*
2. 准备测试 demo.json 文件。
3. 运行 *./bin/ilogtail --plugin=./demo.json* 启动程序,
3. 运行 *./output/ilogtail --plugin=./demo.json* 启动程序,

以下内容将详细介绍 input 与 processor 插件如何进行本地调试。

Expand All @@ -20,7 +20,7 @@ iLogtail作为[Logtail AlibabaCloud](https://help.aliyun.com/document_detail/289
进行运行,比如 [E2E nginx](../../../test/case/behavior/input_nginx),当然如果你本地准备好了相关依赖环境,也本地进行调试。 以下的例子展示了采集nginx
状态的输入型插件配置文件,IntervalMs表示采集的频率为1s一次。你可以直接在项目根路径运行 *TEST_SCOPE=input_nginx TEST_DEBUG=true make e2e*
命令使用E2E测试插件运行效果。对于本地启动后,采集的输出保存于*logtail_plugin.LOG*文件,当然你也可以使用
*./bin/ilogtail --plugin=./demo.json --logger-console=true --logger-retain=false* 启动,采集信息将直接输出与控制台。
*./output/ilogtail --plugin=./demo.json --logger-console=true --logger-retain=false* 启动,采集信息将直接输出与控制台。

```json
{
Expand Down Expand Up @@ -49,7 +49,7 @@ iLogtail作为[Logtail AlibabaCloud](https://help.aliyun.com/document_detail/289

对于 processor 插件来说,可以使用 metric_mock或service_mock 模拟采集输入,以下例子为验证测试 processor_add_fields 插件功能, metric_mock 模拟采集输入数据
Key/Value 为1111:2222 的数据,通过processor_add_fields 插件,最终输出含有3个字段的输出。对于本地启动后,采集的输出保存于*logtail_plugin.LOG*文件,当然你也可以使用
*./bin/ilogtail --plugin=./demo.json --logger-console=true --logger-retain=false* 启动,采集信息将直接输出与控制台。
*./output/ilogtail --plugin=./demo.json --logger-console=true --logger-retain=false* 启动,采集信息将直接输出与控制台。

```json
{
Expand Down Expand Up @@ -95,13 +95,13 @@ library,直接使用 [SLS observable platform](https://www.aliyun.com/product/
控制台进行配置设置,使用控制台查看采集数据。以下将分别介绍2种情况下如何使用AlibabaCloud 运行你自己编写的插件程序。

### 基于ECS 主机运行 [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html)
1. 运行 `make solib` 进行so library 编译,编译后程序为 `bin/libPluginBase.so`
1. 运行 `make plugin` 进行so library 编译,编译后程序为 `output/libPluginBase.so`
2. 登录ECS主机。
3. 执行 `cd /usr/local/ilogtail/`,参考 `README` 停止 [Logtail AlibabaCloud] 程序。
4. 将编译后的`libPluginBase.so` 程序替换原有`libPluginBase.so`程序。
5. 参考`README` 重新启动[Logtail AlibabaCloud] 程序。

### 基于容器运行 [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html)
1. 运行 `make wholedocker` 进行 [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html)docker 模式编译,编译后的镜像为 `aliyun/ilogtail:latest`
1. 运行 `make docker` 进行 [Logtail AlibabaCloud](https://help.aliyun.com/document_detail/28979.html)docker 模式编译,编译后的镜像为 `aliyun/ilogtail:latest`
2.`aliyun/ilogtail:latest` 重命名为镜像仓库镜像并push到远程仓库,如 `registry.cn-beijing.aliyuncs.com/aliyun/ilogtail:0.0.1`
3.[ACK](https://www.aliyun.com/product/list/alibabacloudnative)) logtail-ds 组件镜像进行替换并重启,或将自建平台镜像进行替换并重启。
8 changes: 4 additions & 4 deletions docs/zh/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ iLogtail 插件基于 Go 语言实现,所以在进行开发前,需要安装
目前Logtail 插件支持Linux/Windows/macOS 上运行的,某些插件可能存在条件编译仅在Linux或Windows 下运行,请在相应环境进行调试,详细的描述可以参考 [此文档](../guides/How-to-do-manual-test.md)

### 本地启动
在根目录下执行 `make build` 命令,会得到 `bin/ilogtail` 可执行文件,使用以下命令可以快速启动iLogtail 程序,并将日志使用控制台输出。
在根目录下执行 `make plugin_main` 命令,会得到 `output/ilogtail` 可执行文件,使用以下命令可以快速启动iLogtail 程序,并将日志使用控制台输出。
```shell
# 默认插件启动行为是使用metric_mock 插件mock 数据,并将数据进行日志模式打印。
./bin/ilogtail --logger-console=true --logger-retain=false
./output/ilogtail --logger-console=true --logger-retain=false
```

### Docker 启动
Expand Down Expand Up @@ -110,7 +110,7 @@ iLogtail 目前提供以下3种模式进行配置设置:
}
```

执行 `./bin/ilogtail --plugin=plugin.quickstart.json`,在一段时间后,使用 ctrl+c 中断运行。通过查看目录,会发现生成了 quickstart_1.stdout 和 quickstart_2.stdout 两个文件,并且它们的内容一致。查看内容可以发现,其中的每条数据都包含 Index 和 Content 两个键,并且由于有两个输入插件,Content 会有所不同。
执行 `./output/ilogtail --plugin=plugin.quickstart.json`,在一段时间后,使用 ctrl+c 中断运行。通过查看目录,会发现生成了 quickstart_1.stdout 和 quickstart_2.stdout 两个文件,并且它们的内容一致。查看内容可以发现,其中的每条数据都包含 Index 和 Content 两个键,并且由于有两个输入插件,Content 会有所不同。

### HTTP API 配置变更

Expand All @@ -119,7 +119,7 @@ iLogtail 目前提供以下3种模式进行配置设置:
- 接口:/loadconfig

接下来我们将使用HTTP 模式重新进行动态加载**指定配置文件模式启动**篇幅中的静态配置案例。
1. 首先我们启动 iLogtail 程序: `./bin/ilogtail`
1. 首先我们启动 iLogtail 程序: `./output/ilogtail`
2. 使用以下命令进行配置重新加载。
```shell
curl 127.0.0.1:18689/loadconfig -X POST -d '[{"project":"e2e-test-project","logstore":"e2e-test-logstore","config_name":"test-case_0","logstore_key":1,"json_str":"{\"inputs\":[{\"type\":\"metric_mock\",\"detail\":{\"Index\":0,\"
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 -
Loading

0 comments on commit cfe75b5

Please sign in to comment.