diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bc64910e..f0c55988 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,20 +18,20 @@ jobs: - uses: actions/checkout@v4 - # - uses: actions/setup-node@v4 - # with: - # node-version: '16' - # cache: 'yarn' - # cache-dependency-path: 'web/yarn.lock' - # - uses: actions/setup-go@v4 - # with: - # go-version: '1.20' - # cache-dependency-path: 'server/go.sum' - # - name: Build web - # working-directory: web - # run: | - # yarn install - # yarn run build + - uses: actions/setup-node@v4 + with: + node-version: '16' + cache: 'yarn' + cache-dependency-path: 'web/yarn.lock' + - name: Build web + working-directory: web + run: | + yarn install + yarn run build + # - uses: actions/setup-go@v4 + # with: + # go-version: '1.20' + # cache-dependency-path: 'server/go.sum' - name: Set up QEMU # https://github.com/docker/setup-qemu-action @@ -54,9 +54,6 @@ jobs: echo "APP_VER=$appVer" >> $GITHUB_ENV echo "commitId=$commitId" >> $GITHUB_ENV - mkdir web/ui - touch web/ui/a.txt - #cd server;go mod tidy - name: Build and push @@ -67,19 +64,18 @@ jobs: #cache-to: type=gha,mode=max context: . file: ./docker/Dockerfile - #platforms: linux/amd64,linux/arm64 - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64 build-args: | appVer=${{ env.APP_VER }} commitId=${{ env.commitId }} #tags: bjdgyc/anylink:latest,bjdgyc/anylink:${{ env.APP_VER }} tags: bjdgyc/anylink:${{ env.APP_VER }} -# - name: Docker Build binary -# shell: bash -# run: | -# #sudo apt-get install -y -q gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -# bash release.sh + - name: Build Copy binary + shell: bash + run: | + #sudo apt-get install -y -q gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + bash release.sh # Docker: # name: build-docker diff --git a/build.sh b/build.sh index f09945d3..8fa34e5e 100644 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ 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" @@ -40,6 +40,24 @@ go build -o anylink "$flags" -ldflags "$ldflags" cd $cpath +exit 0 + +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" diff --git a/docker/Dockerfile b/docker/Dockerfile index e4297cf5..63d1b62d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -36,6 +36,7 @@ COPY --from=builder_golang /server/anylink /app/ COPY docker/docker_entrypoint.sh /app/ COPY ./server/bridge-init.sh /app/ COPY ./server/conf /app/conf +COPY ./systemd /app/systemd COPY ./README.md /app/README.md COPY ./LICENSE /app/LICENSE COPY ./home /app/home diff --git a/docker/init.sh b/docker/init.sh index 58535152..45b09b5e 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -8,7 +8,7 @@ if [[ $CN == "yes" ]]; then export GOPROXY=https://goproxy.cn fi -apk add tzdata gcc musl-dev +apk add tzdata gcc musl-dev upx uname -a env @@ -20,12 +20,13 @@ go mod tidy echo "start build" -#-extldflags '-static' - -ldflags="-s -w -extldflags \"-static\" -X main.appVer=$appVer -X main.commitId=$commitId -X main.buildDate=$(date -Iseconds)" +ldflags="-s -w -extldflags '-static' -X main.appVer=$appVer -X main.commitId=$commitId -X main.buildDate=$(date -Iseconds)" go build -o anylink -trimpath -ldflags "$ldflags" -ls -l /server/ +ls -lh /server/ + +# 压缩文件 +upx -9 -k anylink /server/anylink -v diff --git a/release.sh b/release.sh index 30821034..e1dd33d8 100644 --- a/release.sh +++ b/release.sh @@ -14,62 +14,33 @@ 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 -yarn run build -RETVAL $? -rm -rf $cpath/server/ui -cp -rf $cpath/web/ui . $cpath/server/ui +mkdir archive anylink-deploy -echo "编译二进制文件" -cd $cpath/server +function archive() { + os=$1 + arch=$2 + echo "整理部署文件 $os $arch" -# -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.date=$(date --iso-8601=seconds)" - -#github action -gopath=$(go env GOPATH) -#go mod tidy - -# alpine3 -apk add gcc musl-dev - -#使用 musl-dev 编译 -docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/amd64 \ - golang:1.20-alpine3.19 go build -o anylink_amd64 $flags -ldflags "$ldflags" -./anylink_amd64 -v -#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 + deploy="anylink-$ver-$os-$arch" + docker container create --platform $os/$arch --name $deploy bjdgyc/anylink + rm -rf anylink-deploy/* + docker cp -a $deploy:/app/ ./anylink-deploy/ + ls -lh anylink-deploy + tar zcf ${deploy}.tar.gz anylink-deploy + mv ${deploy}.tar.gz archive/ +} -cd $cpath -echo "整理部署文件" -deploy="anylink-deploy" -rm -rf $deploy ${deploy}.tar.gz -mkdir $deploy -mkdir $deploy/log +echo "copy二进制文件" -cp -r server/anylink $deploy -cp -r server/bridge-init.sh $deploy -cp -r server/conf $deploy +archive linux amd64 +archive linux arm64 -cp -r systemd $deploy -cp -r LICENSE $deploy -cp -r home $deploy +ls -lh archive -tar zcvf ${deploy}.tar.gz $deploy #注意使用root权限运行 #cd anylink-deploy diff --git a/release_bak.sh b/release_bak.sh new file mode 100644 index 00000000..d6775095 --- /dev/null +++ b/release_bak.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +#github action release.sh + +set -x +function RETVAL() { + rt=$1 + if [ $rt != 0 ]; then + echo $rt + exit 1 + fi +} + +#当前目录 +cpath=$(pwd) + +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.date=$(date --iso-8601=seconds)" +#github action +gopath=$(go env GOPATH) +go mod tidy +# alpine3 +apk add gcc musl-dev +#使用 musl-dev 编译 +docker run -q --rm -v $PWD:/app -v $gopath:/go -w /app --platform=linux/amd64 \ + golang:1.20-alpine3.19 go build -o anylink_amd64 $flags -ldflags "$ldflags" +./anylink_amd64 -v +#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"