Skip to content

Commit

Permalink
修改 docker 编译
Browse files Browse the repository at this point in the history
  • Loading branch information
bjdgyc committed Jan 30, 2024
1 parent 10a335d commit f9ff92d
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 76 deletions.
44 changes: 20 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 changes: 19 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions docker/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 17 additions & 46 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 58 additions & 0 deletions release_bak.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit f9ff92d

Please sign in to comment.