diff --git a/.github/actions/build-go/action.yml b/.github/actions/build-go/action.yml index d952eee56..bd55a35c0 100644 --- a/.github/actions/build-go/action.yml +++ b/.github/actions/build-go/action.yml @@ -17,6 +17,11 @@ inputs: description: "OS for cross-build" required: false default: "linux" + + goarch: + description: "ARCH for cross-build" + required: false + default: "amd64" runs: using: 'docker' diff --git a/.github/actions/build-go/entrypoint.sh b/.github/actions/build-go/entrypoint.sh index f40cc59d1..3039b2131 100644 --- a/.github/actions/build-go/entrypoint.sh +++ b/.github/actions/build-go/entrypoint.sh @@ -6,7 +6,7 @@ function build() { # Copying this from previous build (cpp) cp -rf ./version.go /src/pkg/client/version.go cd /src - GOOS=$INPUT_GOOS go build -o pktvisor-cli cmd/pktvisor-cli/main.go + GOOS=$INPUT_GOOS GOARCH=$INPUT_GOARCH go build -o pktvisor-cli cmd/pktvisor-cli/main.go } function copy() { diff --git a/.github/workflows/build_cross.yml b/.github/workflows/build_cross.yml index 6fa2c8a0b..195a2454f 100644 --- a/.github/workflows/build_cross.yml +++ b/.github/workflows/build_cross.yml @@ -11,7 +11,6 @@ on: branches: - develop - jobs: pkvisor: name: pktvisor @@ -173,33 +172,44 @@ jobs: - os: macos arch: armv7lh steps: - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - name: Checkout sources uses: actions/checkout@v3 - with: - path: src - - name: Configure + - name: Configure CMake to generate VERSION + shell: bash + run: VERSION_ONLY=1 cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=Release + + - name: Rename folder and copy version + shell: bash run: | - VERSION_ONLY=1 cmake src - - - name: Build - run: | - if [ "${{matrix.os}}" = macos ]; then - export GOOS=darwin - fi + mv src pktvisor-src + cp -rpf golang/pkg/client/version.go . + + - name: Build pktvisor-cli macos + if: ${{matrix.os}} == macos + uses: ./.github/actions/build-go + with: + context: "." + file: "./Dockerfile" + goos: "darwin" - if [ "${{matrix.arch}}" = armv7lh ]; then - export GOARCH=arm - elif [ "${{matrix.arch}}" = aarch64 ]; then - export GOARCH=arm64 - fi - - cd src/golang - go build -o ${{github.workspace}}/pktvisor-cli ./cmd/pktvisor-cli + - name: Build pktvisor-cli linux armv7lh + if: ${{matrix.arch}} == armv7lh + uses: ./.github/actions/build-go + with: + context: "." + file: "./Dockerfile" + goos: "linux" + goarch: "arm" + + - name: Build pktvisor-cli linux aarch64 + if: ${{matrix.arch}} == aarch64 + uses: ./.github/actions/build-go + with: + context: "." + file: "./Dockerfile" + goos: "linux" + goarch: "arm64" - name: Upload pktvisor-cli uses: actions/upload-artifact@v2 diff --git a/docker/Dockerfile.pktvisor-cli b/docker/Dockerfile.pktvisor-cli deleted file mode 100644 index d612ada13..000000000 --- a/docker/Dockerfile.pktvisor-cli +++ /dev/null @@ -1,32 +0,0 @@ -FROM debian:bullseye-slim AS cppbuild - -ENV BUILD_DEPS "g++ cmake make git pkgconf jq python3-pip python3-setuptools ca-certificates" - -RUN \ - apt-get update && \ - apt-get upgrade --yes --force-yes && \ - apt-get install --yes --force-yes --no-install-recommends ${BUILD_DEPS} && \ - pip3 install conan - -# need git for current hash for VERSION -COPY ./.git/ /pktvisor-src/.git/ -COPY ./golang/ /pktvisor-src/golang/ -COPY ./CMakeLists.txt /pktvisor-src/ - -WORKDIR /tmp/build - -# ONLY run cmake configure to get version need for go build (no c++ build) -RUN VERSION_ONLY=1 cmake /pktvisor-src - -FROM golang:latest AS gobuild -COPY golang/ /src/ -WORKDIR /src/ -COPY --from=cppbuild /pktvisor-src/golang/pkg/client/version.go /src/pkg/client/version.go -RUN CGO_ENABLED=0 go build -o pktvisor-cli cmd/pktvisor-cli/main.go - -FROM alpine:latest AS runtime - -COPY --from=gobuild /src/pktvisor-cli /pktvisor-cli -COPY docker/entry-cli.sh / - -ENTRYPOINT [ "/entry-cli.sh" ] diff --git a/docker/entry-cli.sh b/docker/entry-cli.sh deleted file mode 100755 index 14b6cd666..000000000 --- a/docker/entry-cli.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# this is the entry point to the docker container, and is only used there -set -e -export PATH=$PATH:/usr/local/bin/:/usr/local/sbin/ - -# Add sleep to allow tty to be ready for Docker when using -it -echo "starting pktvisor-cli..." -sleep 1 - -exec /pktvisor-cli