Merge pull request #2 from lss233/master

Add static build and CI
This commit is contained in:
日下部 詩 2021-12-19 23:21:21 +08:00 committed by GitHub
commit d90fcdbd25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 289 additions and 0 deletions

98
.github/workflows/go.yml vendored Normal file
View File

@ -0,0 +1,98 @@
name: Go
on:
- workflow_dispatch
jobs:
x86_64:
runs-on: ubuntu-20.04
name: Build for ${{ matrix.distro }} x86_64 and mipsle
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Install requirements
run: |
echo "deb [trusted=yes] https://packagecloud.io/fdio/release/ubuntu focal main" | sudo tee -a /etc/apt/sources.list.d/99fd.io.list > /dev/null
curl -L https://packagecloud.io/fdio/release/gpgkey | sudo apt-key add -
sudo apt-get -y update
sudo apt-get install -y vpp vpp-plugin-core python3-vpp-api vpp-dbg vpp-dev libmemif libmemif-dev
sudo apt-get install -y wireguard-tools upx-ucl
- name: Build x86_64
run: |
make all static vpp
- uses: actions/upload-artifact@v2
with:
name: etherguard-x86_64
path: etherguard-go*
- name: Build mipsle
run: |
make clean
GOOS=linux GOARCH=mipsle GOMIPS=softfloat make all static
upx -9 etherguard-go*
- uses: actions/upload-artifact@v2
with:
name: etherguard-mipsle
path: etherguard-go*
multi-arch:
runs-on: ubuntu-20.04
name: Build on ${{ matrix.distro }} ${{ matrix.arch }}
strategy:
matrix:
include:
- arch: aarch64
- arch: armv7
steps:
- uses: actions/checkout@v2
- uses: uraimo/run-on-arch-action@v2.0.5
name: Build artifact
id: build
with:
arch: ${{ matrix.arch }}
distro: ubuntu20.04
githubToken: ${{ github.token }}
setup: |
mkdir -p "${PWD}/artifacts"
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
env: |
artifact_dir: ${{ matrix.arch }}
shell: /bin/sh
install: |
apt-get -y update
apt install software-properties-common curl -y
echo "deb [trusted=yes] https://packagecloud.io/fdio/release/ubuntu focal main" > /etc/apt/sources.list.d/99fd.io.list
curl -L https://packagecloud.io/fdio/release/gpgkey | apt-key add -
add-apt-repository ppa:longsleep/golang-backports
apt-get -y update
apt-get install -y vpp vpp-plugin-core python3-vpp-api vpp-dbg vpp-dev libmemif libmemif-dev || true
apt-get install -y wireguard-tools golang-go build-essential git
run: |
make all static
make vpp || true
mkdir /artifacts/${artifact_dir}
cp etherguard-go* /artifacts/${artifact_dir}
- uses: actions/upload-artifact@v2
if: ${{ matrix.arch == 'armv7' }}
with:
name: etherguard-arm32
path: artifacts/armv7
- uses: actions/upload-artifact@v2
if: ${{ matrix.arch == 'aarch64' }}
with:
name: etherguard-arm64
path: artifacts/aarch64

174
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,174 @@
name: Publish
on:
push:
tags:
- '*'
jobs:
x86_64:
runs-on: ubuntu-20.04
name: Build for ${{ matrix.distro }} x86_64 and mipsle
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Install requirements
run: |
echo "deb [trusted=yes] https://packagecloud.io/fdio/release/ubuntu focal main" | sudo tee -a /etc/apt/sources.list.d/99fd.io.list > /dev/null
curl -L https://packagecloud.io/fdio/release/gpgkey | sudo apt-key add -
sudo apt-get -y update
sudo apt-get install -y vpp vpp-plugin-core python3-vpp-api vpp-dbg vpp-dev libmemif libmemif-dev
sudo apt-get install -y wireguard-tools upx-ucl
- name: Build x86_64
run: |
make all static vpp
- uses: actions/upload-artifact@v2
with:
name: etherguard-x86_64
path: etherguard-go*
- name: Upload x86_64 dynamic build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: etherguard-go
asset_name: etherguard-go-x86_64
tag: ${{ github.ref }}
- name: Upload x86_64 dynamic vpp build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: etherguard-go-vpp
asset_name: etherguard-go-x86_64
tag: ${{ github.ref }}
- name: Upload x86_64 static build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: etherguard-go-static
asset_name: etherguard-go-static-x86_64
tag: ${{ github.ref }}
- name: Build mipsle
run: |
make clean
GOOS=linux GOARCH=mipsle GOMIPS=softfloat make all static
upx -9 etherguard-go*
- uses: actions/upload-artifact@v2
with:
name: etherguard-mipsle
path: etherguard-go*
- name: Upload mipsle dynamic build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: etherguard-go
asset_name: etherguard-go-mipsle
tag: ${{ github.ref }}
- name: Upload mipsle dynamic vpp build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: etherguard-go-vpp
asset_name: etherguard-go-mipsle
tag: ${{ github.ref }}
- name: Upload mipsle static build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: etherguard-go-static
asset_name: etherguard-go-static-mipsle
tag: ${{ github.ref }}
multi-arch:
runs-on: ubuntu-20.04
name: Build on ${{ matrix.distro }} ${{ matrix.arch }}
strategy:
matrix:
include:
- arch: aarch64
- arch: armv7
steps:
- uses: actions/checkout@v2
- uses: uraimo/run-on-arch-action@v2.0.5
name: Build artifact
id: build
with:
arch: ${{ matrix.arch }}
distro: ubuntu20.04
githubToken: ${{ github.token }}
setup: |
mkdir -p "${PWD}/artifacts"
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
env: |
artifact_dir: ${{ matrix.arch }}
shell: /bin/sh
install: |
apt-get -y update
apt install software-properties-common curl -y
echo "deb [trusted=yes] https://packagecloud.io/fdio/release/ubuntu focal main" > /etc/apt/sources.list.d/99fd.io.list
curl -L https://packagecloud.io/fdio/release/gpgkey | apt-key add -
add-apt-repository ppa:longsleep/golang-backports
apt-get -y update
apt-get install -y vpp vpp-plugin-core python3-vpp-api vpp-dbg vpp-dev libmemif libmemif-dev || true
apt-get install -y wireguard-tools golang-go build-essential git
run: |
make all static
make vpp || true
mkdir /artifacts/${artifact_dir}
cp etherguard-go* /artifacts/${artifact_dir}
- uses: actions/upload-artifact@v2
if: ${{ matrix.arch == 'armv7' }}
with:
name: etherguard-arm32
path: artifacts/armv7
- uses: actions/upload-artifact@v2
if: ${{ matrix.arch == 'aarch64' }}
with:
name: etherguard-arm64
path: artifacts/aarch64
- name: Upload ${{ matrix.arch }} dynamic build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: artifacts/${{ martix.arch }}/etherguard-go
asset_name: etherguard-go-${{ martix.arch }}
tag: ${{ github.ref }}
- name: Upload ${{ matrix.arch }} dynamic vpp build
if: ${{ matrix.arch == 'aarch64' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: artifacts/${{ martix.arch }}/etherguard-go
asset_name: etherguard-go-${{ martix.arch }}
tag: ${{ github.ref }}
- name: Upload ${{ matrix.arch }} static build
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: artifacts/${{ martix.arch }}/etherguard-go-static
asset_name: etherguard-go-static-${{ martix.arch }}
tag: ${{ github.ref }}

View File

@ -22,6 +22,12 @@ etherguard-go: $(wildcard *.go) $(wildcard */*.go)
go mod vendor && \
go build -v -o "$@"
etherguard-go-static: $(wildcard *.go) $(wildcard */*.go)
go mod download && \
go mod tidy && \
go mod vendor && \
CGO_ENABLED=0 go build -a -trimpath -ldflags '-s -w -extldflags "-static"' -v -o "$@"
vpp:
@export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \
tag="$$(git describe 2>/dev/null)" && \
@ -39,6 +45,15 @@ etherguard-go-vpp: $(wildcard *.go) $(wildcard */*.go)
patch -p0 -i govpp_remove_crcstring_check.patch && \
go build -v -tags vpp -o "$@"
static:
@export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \
tag="$$(git describe 2>/dev/null)" && \
ver="$$(printf 'package main\n\nconst Version = "%s"\n' "$$tag")" && \
[ "$$(cat version.go 2>/dev/null)" != "$$ver" ] && \
echo "$$ver" > version.go && \
git update-index --assume-unchanged version.go || true
@$(MAKE) etherguard-go-static
install: etherguard-go
@install -v -d "$(DESTDIR)$(BINDIR)" && install -v -m 0755 "$<" "$(DESTDIR)$(BINDIR)/etherguard-go"
@ -47,6 +62,8 @@ test:
clean:
rm -f etherguard-go
rm -f etherguard-go-static
rm -f etherguard-go-vpp
rm -f etherguard-go-vpp-static
.PHONY: all clean test install generate-version-and-build