mirror of https://github.com/bjdgyc/anylink.git
修改编译脚本
This commit is contained in:
parent
8455ef6ed4
commit
cca9e377c5
57
build.sh
57
build.sh
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#github action release.sh
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
function RETVAL() {
|
function RETVAL() {
|
||||||
rt=$1
|
rt=$1
|
||||||
|
@ -11,41 +13,46 @@ function RETVAL() {
|
||||||
|
|
||||||
#当前目录
|
#当前目录
|
||||||
cpath=$(pwd)
|
cpath=$(pwd)
|
||||||
#ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'`
|
|
||||||
ver=$(cat version)
|
ver=$(cat version)
|
||||||
echo "当前版本 $ver"
|
echo $ver
|
||||||
|
|
||||||
echo "编译前端项目"
|
echo "copy二进制文件"
|
||||||
cd $cpath/web
|
|
||||||
|
|
||||||
#国内可替换源加快速度
|
|
||||||
#npx browserslist@latest --update-db
|
|
||||||
yarn install --registry=https://registry.npmmirror.com
|
|
||||||
yarn run build
|
|
||||||
RETVAL $?
|
|
||||||
|
|
||||||
echo "编译二进制文件"
|
|
||||||
cd $cpath/server
|
cd $cpath/server
|
||||||
rm -rf ui
|
|
||||||
cp -rf $cpath/web/ui .
|
|
||||||
|
|
||||||
# -tags osusergo,netgo,sqlite_omit_load_extension
|
# -tags osusergo,netgo,sqlite_omit_load_extension
|
||||||
# -tags musl
|
flags="-trimpath"
|
||||||
flags="-v -trimpath"
|
ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.buildDate=$(date --iso-8601=seconds)"
|
||||||
|
#github action
|
||||||
|
gopath=/go
|
||||||
|
|
||||||
# -linkmode external
|
dockercmd=$(
|
||||||
# -extldflags '-static'
|
cat <<EOF
|
||||||
ldflags="-s -w -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date -Iseconds)"
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
|
||||||
|
apk add gcc g++ musl musl-dev tzdata
|
||||||
#国内可替换源加快速度
|
export GOPROXY=https://goproxy.cn
|
||||||
export GOPROXY=https://goproxy.io
|
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go build -o anylink $flags -ldflags "$ldflags"
|
echo "build:"
|
||||||
|
export CGO_ENABLED=1
|
||||||
|
go build -v -o anylink_amd64 $flags -ldflags "$ldflags"
|
||||||
|
./anylink_amd64 -v
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
cd $cpath
|
#使用 musl-dev 编译
|
||||||
|
docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/amd64 \
|
||||||
|
golang:1.20-alpine3.19 sh -c "$dockercmd"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
#arm64编译
|
||||||
|
docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/arm64 \
|
||||||
|
golang:1.20-alpine3.19 go build -o anylink_arm64 $flags -ldflags "$ldflags"
|
||||||
|
./anylink_arm64 -v
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
cd $cpath
|
||||||
|
|
||||||
echo "整理部署文件"
|
echo "整理部署文件"
|
||||||
deploy="anylink-deploy"
|
deploy="anylink-deploy"
|
||||||
rm -rf $deploy ${deploy}.tar.gz
|
rm -rf $deploy ${deploy}.tar.gz
|
||||||
|
|
|
@ -8,11 +8,10 @@ echo $ver
|
||||||
# 生成时间 2024-01-30T21:41:27+08:00
|
# 生成时间 2024-01-30T21:41:27+08:00
|
||||||
# date -Iseconds
|
# date -Iseconds
|
||||||
|
|
||||||
#docker run -it --rm -v $PWD/web:/app -w /app node:16-alpine \
|
#bash ./build_web.sh
|
||||||
# sh -c "yarn install --registry=https://registry.npmmirror.com && yarn run build"
|
|
||||||
|
|
||||||
# docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 本地不生成镜像
|
# docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 本地不生成镜像
|
||||||
docker buildx build -t bjdgyc/anylink:latest --no-cache --progress=plain --platform linux/amd64 \
|
docker build -t bjdgyc/anylink:latest --no-cache --progress=plain --platform linux/amd64 \
|
||||||
--build-arg CN="yes" --build-arg appVer=$ver --build-arg commitId=$(git rev-parse HEAD) -f docker/Dockerfile .
|
--build-arg CN="yes" --build-arg appVer=$ver --build-arg commitId=$(git rev-parse HEAD) -f docker/Dockerfile .
|
||||||
|
|
||||||
echo "docker tag latest $ver"
|
echo "docker tag latest $ver"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
docker run -it --rm -v $PWD/web:/app -w /app node:16-alpine \
|
||||||
|
sh -c "yarn install --registry=https://registry.npmmirror.com && yarn run build"
|
||||||
|
|
||||||
|
rm -rf server/ui
|
||||||
|
cp -r web/ui server/ui
|
|
@ -21,7 +21,7 @@ go mod tidy
|
||||||
|
|
||||||
echo "start build"
|
echo "start build"
|
||||||
|
|
||||||
ldflags="-s -w -X main.appVer=$appVer -X main.commitId=$commitId -X main.buildDate=$(date -Iseconds) -extldflags '-static' "
|
ldflags="-s -w -X main.appVer=$appVer -X main.commitId=$commitId -X main.buildDate=$(date -Iseconds) -extldflags \"-static\" "
|
||||||
|
|
||||||
export CGO_ENABLED=1
|
export CGO_ENABLED=1
|
||||||
go build -v -o anylink -trimpath -ldflags "$ldflags"
|
go build -v -o anylink -trimpath -ldflags "$ldflags"
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#github action release.sh
|
|
||||||
|
|
||||||
set -x
|
|
||||||
function RETVAL() {
|
|
||||||
rt=$1
|
|
||||||
if [ $rt != 0 ]; then
|
|
||||||
echo $rt
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#当前目录
|
|
||||||
cpath=$(pwd)
|
|
||||||
|
|
||||||
ver=$(cat version)
|
|
||||||
echo $ver
|
|
||||||
|
|
||||||
echo "copy二进制文件"
|
|
||||||
cd $cpath/server
|
|
||||||
# -tags osusergo,netgo,sqlite_omit_load_extension
|
|
||||||
flags="-trimpath"
|
|
||||||
ldflags="-s -w -extldflags '-static' -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.buildDate=$(date --iso-8601=seconds)"
|
|
||||||
#github action
|
|
||||||
gopath=/go
|
|
||||||
|
|
||||||
dockercmd=$(
|
|
||||||
cat <<EOF
|
|
||||||
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
|
|
||||||
apk add gcc g++ musl musl-dev tzdata
|
|
||||||
export GOPROXY=https://goproxy.cn
|
|
||||||
go mod tidy
|
|
||||||
echo "build:"
|
|
||||||
export CGO_ENABLED=1
|
|
||||||
go build -v -o anylink_amd64 $flags -ldflags "$ldflags"
|
|
||||||
./anylink_amd64 -v
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
#使用 musl-dev 编译
|
|
||||||
docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/amd64 \
|
|
||||||
golang:1.20-alpine3.19 sh -c "$dockercmd"
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
#arm64编译
|
|
||||||
docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/arm64 \
|
|
||||||
golang:1.20-alpine3.19 go build -o anylink_arm64 $flags -ldflags "$ldflags"
|
|
||||||
./anylink_arm64 -v
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
cd $cpath
|
|
||||||
|
|
||||||
echo "整理部署文件"
|
|
||||||
deploy="anylink-deploy"
|
|
||||||
rm -rf $deploy ${deploy}.tar.gz
|
|
||||||
mkdir $deploy
|
|
||||||
mkdir $deploy/log
|
|
||||||
|
|
||||||
cp -r server/anylink $deploy
|
|
||||||
cp -r server/bridge-init.sh $deploy
|
|
||||||
cp -r server/conf $deploy
|
|
||||||
|
|
||||||
cp -r systemd $deploy
|
|
||||||
cp -r LICENSE $deploy
|
|
||||||
cp -r home $deploy
|
|
||||||
|
|
||||||
tar zcvf ${deploy}.tar.gz $deploy
|
|
||||||
|
|
||||||
#注意使用root权限运行
|
|
||||||
#cd anylink-deploy
|
|
||||||
#sudo ./anylink --conf="conf/server.toml"
|
|
|
@ -142,7 +142,7 @@ func addInitData() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
g1 := Group{
|
g1 := Group{
|
||||||
Name: "ops",
|
Name: "all",
|
||||||
AllowLan: true,
|
AllowLan: true,
|
||||||
ClientDns: []ValData{{Val: "114.114.114.114"}},
|
ClientDns: []ValData{{Val: "114.114.114.114"}},
|
||||||
RouteInclude: []ValData{{Val: All}},
|
RouteInclude: []ValData{{Val: All}},
|
||||||
|
@ -153,6 +153,18 @@ func addInitData() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g2 := Group{
|
||||||
|
Name: "ops",
|
||||||
|
AllowLan: true,
|
||||||
|
ClientDns: []ValData{{Val: "114.114.114.114"}},
|
||||||
|
RouteInclude: []ValData{{Val: "10.0.0.0/8"}},
|
||||||
|
Status: 1,
|
||||||
|
}
|
||||||
|
err = SetGroup(&g2)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue