diff --git a/README.md b/README.md index 9c3494c..5f47de3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # gitlink_golang_node +## 构建镜像命令 + +`docker build --tag gitlink_golang -f dockerfile/Dockerfile .` + +## 运行容器 + +```shell +docker run --name gitlink_golang_node \ + -e JIANMU_WORKSPACE="/Users/virus/work/keda/gitea_hat" + -e JIANMU_GOOS="linux" + -e JIANMU_GOOS="amd64" + -e JIANMU_OUT_BIN_NAME="gitea" gitlink_golang +``` \ No newline at end of file diff --git a/dockerfile/Dockerfile b/dockerfile/Dockerfile new file mode 100644 index 0000000..8d99e48 --- /dev/null +++ b/dockerfile/Dockerfile @@ -0,0 +1,8 @@ +FROM golang:1.20.2 + +ADD script/build.sh /usr/local/bin + +RUN chmod +x /usr/local/bin/build.sh + +ENTRYPOINT [ "/usr/local/bin/build.sh" ] + diff --git a/dsl/node_def.yml b/dsl/node_def.yml new file mode 100644 index 0000000..0e29cc6 --- /dev/null +++ b/dsl/node_def.yml @@ -0,0 +1,36 @@ +ref: yystopf/gitlink_golang_node +version: 0.0.1 +resultFile: /tmp/result.json +description: 用于构建golang程序 +inputParameters: + - ref: workspace + name: workspace + type: STRING + required: true + description: golang源代码所在目录 + - ref: out_bin_name + name: out_bin_name + type: STRING + required: true + description: 二进制文件名称 + - ref: goos + name: goos + type: STRING + required: true + description: 构建GOOS参数值 + - ref: goarch + name: goarch + type: STRING + required: true + description: 构建GOARCH参数值 +outputParameters: + - ref: bin_dir + name: bin_dir + type: STRING + required: true + description: 生成的二进制文件目录 + +spec: + image: golang:1.20.2 + entrypoint: ["/bin/bash", "-c"] + cmd: ["/usr/local/bin/build.sh"] \ No newline at end of file diff --git a/script/build.sh b/script/build.sh new file mode 100644 index 0000000..f5ba907 --- /dev/null +++ b/script/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +go env + +cd ${JIANMU_WORKSPACE} + +pwd + +echo "开始build" + +go mod tidy + +go mod vendor + +CGO_ENABLED=0 GOOS=${JIANMU_GOOS} GOARCH=${JIANMU_GOARCH} go build -o ${JIANMU_OUT_BIN_NAME} main.go + +ls -a + +echo "结束build" + +echo "{\"bin_dir\": \"${JIANMU_WORKSPACE}/${JIANMU_OUT_BIN_NAME}\"}" > /tmp/result.json \ No newline at end of file