From 67f99ba1b25af9f6dc17093e71671f3f7b6f1c06 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 22 Jan 2023 20:20:30 -0500 Subject: [PATCH] Build static binary (#29) --- .github/workflows/ci.yml | 19 ++++++------------- Dockerfile | 31 ++++++++++++++----------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecf362d..f8bbeaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,25 +4,18 @@ jobs: build_and_test: name: Build and test runs-on: ubuntu-latest - container: - image: ubuntu:focal steps: - uses: actions/checkout@v2 - - name: Install GCC multilib + - name: Install dependencies run: | - apt-get update - apt-get install -y cmake file gcc-multilib g++-multilib unzip wget - - - name: Configure - # Replace with RelWithDebInfo when -O2 crash is fixed - run: | - mkdir build - cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug + sudo apt-get update + sudo apt-get install -y file unzip wget - name: Build - run: cmake --build build + env: + DOCKER_BUILDKIT: 1 + run: docker build --target export --output build . - name: Test run: | diff --git a/Dockerfile b/Dockerfile index 1b70ad3..54943b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,23 @@ -FROM ubuntu:20.04 as build +# Build stage +FROM --platform=linux/i386 alpine:latest AS build -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - g++ \ - g++-multilib \ - cmake \ - ninja-build +# Install dependencies +RUN apk add --no-cache cmake ninja g++ linux-headers binutils +# Copy source files COPY . /wibo +# Build static binary # Replace with RelWithDebInfo when -O2 crash is fixed -RUN cmake -S /wibo -B /wibo/build -G Ninja -DCMAKE_BUILD_TYPE=Debug -RUN cmake --build /wibo/build +RUN cmake -S /wibo -B /wibo/build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-static" \ + && cmake --build /wibo/build \ + && strip -g /wibo/build/wibo +# Export binary (usage: docker build --target export --output build .) +FROM scratch AS export +COPY --from=build /wibo/build/wibo . -FROM ubuntu:22.04 - -RUN dpkg --add-architecture i386 \ - && apt-get update \ - && apt-get install -y --no-install-recommends \ - libstdc++6:i386 - +# Runnable container +FROM alpine:latest COPY --from=build /wibo/build/wibo /usr/local/sbin/wibo - CMD /usr/local/sbin/wibo