mirror of https://github.com/bjdgyc/anylink.git
修改 docker 编译
This commit is contained in:
parent
10a335dc3d
commit
f9ff92d73d
|
@ -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
|
||||
|
|
20
build.sh
20
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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
63
release.sh
63
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)"
|
||||
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/
|
||||
}
|
||||
|
||||
#github action
|
||||
gopath=$(go env GOPATH)
|
||||
#go mod tidy
|
||||
|
||||
# alpine3
|
||||
apk add gcc musl-dev
|
||||
echo "copy二进制文件"
|
||||
|
||||
#使用 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
|
||||
archive linux amd64
|
||||
archive linux arm64
|
||||
|
||||
exit 0
|
||||
ls -lh archive
|
||||
|
||||
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
|
||||
|
|
|
@ -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"
|
Loading…
Reference in New Issue