Skip to content

Commit

Permalink
修改编译脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
bjdgyc committed Mar 15, 2024
1 parent 8455ef6 commit cca9e37
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 104 deletions.
57 changes: 32 additions & 25 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

#github action release.sh

set -x
function RETVAL() {
rt=$1
Expand All @@ -11,41 +13,46 @@ function RETVAL() {

#当前目录
cpath=$(pwd)
#ver=`cat server/base/app_ver.go | grep APP_VER | awk '{print $3}' | sed 's/"//g'`
ver=$(cat version)
echo "当前版本 $ver"

echo "编译前端项目"
cd $cpath/web

#国内可替换源加快速度
#npx browserslist@latest --update-db
yarn install --registry=https://registry.npmmirror.com
yarn run build
RETVAL $?
ver=$(cat version)
echo $ver

echo "编译二进制文件"
echo "copy二进制文件"
cd $cpath/server
rm -rf ui
cp -rf $cpath/web/ui .

# -tags osusergo,netgo,sqlite_omit_load_extension
# -tags musl
flags="-v -trimpath"

# -linkmode external
# -extldflags '-static'
ldflags="-s -w -X main.appVer=$ver -X main.commitId=$(git rev-parse HEAD) -X main.date=$(date -Iseconds)"
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

#国内可替换源加快速度
export GOPROXY=https://goproxy.io
dockercmd=$(
cat <<EOF
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
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

#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
Expand Down
5 changes: 2 additions & 3 deletions build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ echo $ver
# 生成时间 2024-01-30T21:41:27+08:00
# date -Iseconds

#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"
#bash ./build_web.sh

# 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 .

echo "docker tag latest $ver"
Expand Down
7 changes: 7 additions & 0 deletions build_web.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion docker/init_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go mod tidy

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
go build -v -o anylink -trimpath -ldflags "$ldflags"
Expand Down
74 changes: 0 additions & 74 deletions release_test.sh

This file was deleted.

14 changes: 13 additions & 1 deletion server/dbdata/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func addInitData() error {
}

g1 := Group{
Name: "ops",
Name: "all",
AllowLan: true,
ClientDns: []ValData{{Val: "114.114.114.114"}},
RouteInclude: []ValData{{Val: All}},
Expand All @@ -153,6 +153,18 @@ func addInitData() error {
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
}

Expand Down

0 comments on commit cca9e37

Please sign in to comment.