feat:add arm64

#42 #5
This commit is contained in:
samwaf
2024-11-18 08:39:29 +08:00
parent 05d24b87b6
commit 800a68d25f
12 changed files with 129 additions and 25 deletions

23
.dockerignore Normal file
View File

@@ -0,0 +1,23 @@
# 排除目录
/vue/
.release/
.vue/dist/
.conf/*
/data/*
/logs/*
/ssl/
# 排除特定文件
/data/local_log.db
/data/local_stats.db
/data/local.db
/data/local_log.db-shm
/data/local_log.db-wal
/data/local_stats.db-shm
/data/local_stats.db-wal
registration_data.bin
.idea/
# 排除 public/dist 目录下的内容,保留 .gitkeep 文件
/public/dist/*
!/public/dist/.gitkeep

View File

@@ -24,7 +24,7 @@ jobs:
- name: Install dependencies for Windows cross-compilation
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 build-essential
sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
@@ -42,24 +42,26 @@ jobs:
cd dist
- name: Get current tag
run: echo "IMAGE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
# Build Docker Image
- name: Build Docker Image
run: |
docker build -t samwaf/samwaf:latest .
docker tag samwaf/samwaf:latest samwaf/samwaf:${{ env.IMAGE_TAG }}
# Login Docker
- name: login to docker REGISTRY
# Login to Docker Hub
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Push Docker Image to Docker Hub
- name: Push Docker Image
run: |
docker push samwaf/samwaf:latest
docker push samwaf/samwaf:${{ env.IMAGE_TAG }}
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Build and Push Docker Image for Multi-Arch
- name: Build and Push Docker Image for Multi-Arch
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64 # Support for both architectures
push: true # Push to Docker Hub
tags: |
samwaf/samwaf:latest # Tag the image as 'latest'
samwaf/samwaf:${{ env.IMAGE_TAG }} # Tag the image with the current git tag
# Test the Docker Image
- name: Test Docker Image
run: |

View File

@@ -57,6 +57,24 @@ builds:
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}
- -s -w
- -extldflags "-static"
- id: "samwaf_linux_arm64"
binary: "SamWafLinuxArm64"
env:
- CGO_ENABLED=1
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
- CGO_CFLAGS=-Wno-unused-variable
goos:
- linux
goarch:
- arm64
ldflags:
- -X SamWaf/global.GWAF_RELEASE=true
- -X SamWaf/global.GWAF_RUNTIME_WIN7_VERSION=false
- -X SamWaf/global.GWAF_RELEASE_VERSION_NAME={{ time "20060102" }}
- -X SamWaf/global.GWAF_RELEASE_VERSION={{.Tag}}
- -s -w
- -extldflags "-static"
upx:
- # Whether to enable it or not.
#

View File

@@ -12,8 +12,17 @@ RUN apk update && \
ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo "${TZ}" > /etc/timezone
# 复制 release/SamWafLinux64 到镜像
COPY dist/samwaf_linux_linux_amd64_v1/SamWafLinux64 ./SamWafLinux64
# 复制适用架构的二进制文件到镜像
ARG TARGETARCH
# 使用RUN指令和if语句根据架构选择文件
RUN if [ "${TARGETARCH}" = "amd64" ]; then \
cp dist/samwaf_linux_linux_amd64_v1/SamWafLinux64 ./SamWafLinux64; \
elif [ "${TARGETARCH}" = "arm64" ]; then \
cp dist/samwaf_linux_arm64_linux_arm64_v8.0/SamWafLinuxArm64 ./SamWafLinux64; \
else \
echo "Unknown architecture: ${TARGETARCH}" && exit 1; \
fi
# 设置执行权限
RUN chmod +x SamWafLinux64

42
UbuntuDockerfile Normal file
View File

@@ -0,0 +1,42 @@
# 使用 Ubuntu 作为基础镜像
FROM ubuntu:20.04
# 设置环境变量,防止一些提示
ENV DEBIAN_FRONTEND=noninteractive
# 使用阿里云的 Ubuntu 镜像源
RUN sed -i 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list && \
sed -i 's|http://security.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list
# 更新系统并安装必要的软件包,确保使用阿里云镜像源
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
gcc-mingw-w64-x86-64 \
gcc-mingw-w64-i686 \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
build-essential \
wget \
curl \
unzip \
git \
golang-1.21-go && \
apt-get clean
# 安装 Go 1.21.4
RUN wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.21.4.linux-amd64.tar.gz && \
rm go1.21.4.linux-amd64.tar.gz
# 设置 Go 环境变量
ENV PATH=$PATH:/usr/local/go/bin
# 安装 Goreleaser
RUN curl -sSL https://github.com/goreleaser/goreleaser/releases/download/v2.4.4/goreleaser_Linux_x86_64.tar.gz | tar -xz -C /usr/local/bin
# 设置工作目录
WORKDIR /workspace
# 默认命令:运行并自动编译项目,使用 Goreleaser
CMD ["bash", "-c", "goreleaser release --snapshot"]

View File

@@ -74,6 +74,16 @@ linux
```
ubuntu docker 测试
```
docker build -f UbuntuDockerfile -t samwaflocalcompile .
docker run --rm samwaflocalcompile
docker run --rm -v $(pwd):/workspace samwaflocalcompile
docker run --rm -v %cd%:/workspace samwaflocalcompile
```
## 集成的三方库
前端: 使用TDesign Vue Starter
后端: gorm,excelize(360EntSecGroup-Skylar),godlp(bytedance),gin,gocron,

3
go.mod
View File

@@ -10,8 +10,6 @@ require (
github.com/bytedance/godlp v1.2.15
github.com/denisbrodbeck/machineid v1.0.1
github.com/dsnet/compress v0.0.1
github.com/edwingeng/deque v1.0.3
github.com/emirpasic/gods v1.18.1
github.com/gin-gonic/gin v1.8.1
github.com/go-co-op/gocron v1.17.1
github.com/gorilla/websocket v1.5.0
@@ -40,6 +38,7 @@ require (
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220527190237-ee62e23da966 // indirect
github.com/bmatcuk/doublestar v1.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect

2
go.sum
View File

@@ -77,8 +77,6 @@ github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbj
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/edwingeng/deque v1.0.3 h1:gx+5OnQK8qMcYNUxcD/M76BT/LujVNVAZEP/MGF8WNw=
github.com/edwingeng/deque v1.0.3/go.mod h1:3Ys1pJhyVaB6iWigv4o2r6Ug1GZmfDWqvqmO6bjojg0=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=

View File

@@ -183,6 +183,7 @@ func (m *wafSystenService) run() {
if global.GWAF_RUNTIME_WIN7_VERSION == "true" {
rversion = rversion + " Win7内核版本"
}
rversion = rversion + " plat:" + runtime.GOOS + "-" + runtime.GOARCH
zlog.Info(rversion)
zlog.Info("OutIp", global.GWAF_RUNTIME_IP)

View File

View File

@@ -6,3 +6,4 @@ set currentdescription=请在闲时升级,提升稳定性新增多项功能,
%currentpath%\setup\go_gen_updatefile\go_gen_updatefile.exe -desc %currentdescription% -o %currentpath%\release\web\samwaf_update -platform windows-amd64 %currentpath%\release\githubci\%currentversion%\SamWaf64.exe %currentversion%
%currentpath%\setup\go_gen_updatefile\go_gen_updatefile.exe -desc %currentdescription% -o %currentpath%\release\web\samwaf_update -platform linux-amd64 %currentpath%\release\githubci\%currentversion%\SamWafLinux64 %currentversion%
%currentpath%\setup\go_gen_updatefile\go_gen_updatefile.exe -desc %currentdescription% -o %currentpath%\release\web\win7\samwaf_update -platform windows-amd64 %currentpath%\release\githubci\%currentversion%\SamWaf64ForWin7Win8Win2008.exe %currentversion%
%currentpath%\setup\go_gen_updatefile\go_gen_updatefile.exe -desc %currentdescription% -o %currentpath%\release\web\samwaf_update -platform linux-arm64 %currentpath%\release\githubci\%currentversion%\SamWafLinuxArm64 %currentversion%

View File

@@ -2,6 +2,7 @@ package wafupdate
import (
"SamWaf/binarydist"
"SamWaf/global"
"bytes"
"compress/gzip"
"crypto/sha256"
@@ -303,10 +304,10 @@ func fromStream(updateWith io.Reader) (err error, errRecover error) {
return
}
// fetchInfo fetches the update JSON manifest at u.ApiURL/appname/platform.json
// fetchInfo fetches the update JSON manifest at u.ApiURL/appname/platform.json?v=currentVersion
// and updates u.Info.
func (u *Updater) fetchInfo() error {
r, err := u.fetch(u.ApiURL + url.QueryEscape(u.CmdName) + "/" + url.QueryEscape(plat) + ".json")
r, err := u.fetch(u.ApiURL + url.QueryEscape(u.CmdName) + "/" + url.QueryEscape(plat) + ".json?v=" + global.GWAF_RELEASE_VERSION)
if err != nil {
return err
}