Static builds for Linux on x64 (amd64) and arm32v7 architectures (#1571)

Adding new CI workflows building static executables for linux, both intel 64-bit and ARM32v7. 

These will be useful for providing hledger on Nextcloud, and also as general linux executables, more robust than the ubuntu executable we have been providing.
This commit is contained in:
Garret McGraw 2021-07-01 00:05:27 -04:00 committed by GitHub
parent 2a9d358627
commit 3d0afd5444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,53 @@
name: Static build arm32v7 arch CI
on:
push:
branches: [ ci-linux-static-arm32 ]
#tags:
# - '[0-9]+.[0-9]+'
# - '[0-9]+.[0-9]+-*'
# - '[0-9]+.[0-9]+.[0-9]+'
# - '[0-9]+.[0-9]+.[0-9]+-*'
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
file: ./docker-static-arm32v7/Dockerfile
platforms: linux/arm
tags: hledger-static-linux-arm32v7:latest
load: true
- name: Extract binaries from docker
run: |
# Create temporary container from it
container_id=$(docker create hledger-static-linux-arm32v7:latest)
# Copy stuff from temp container
docker cp $container_id:/root/hledger /tmp/hledger-static-linux-arm32v7
# Delete temp container
docker rm -v $container_id
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: Static Binary
path: /tmp/hledger-static-linux-arm32v7
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: /tmp/hledger-static-linux-arm32v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

60
.github/workflows/static-linux.yml vendored Normal file
View File

@ -0,0 +1,60 @@
name: Static build x64 arch CI
on:
push:
branches: [ ci-linux-static ]
#tags:
# - '[0-9]+.[0-9]+'
# - '[0-9]+.[0-9]+-*'
# - '[0-9]+.[0-9]+.[0-9]+'
# - '[0-9]+.[0-9]+.[0-9]+-*'
jobs:
build:
runs-on: ubuntu-latest
container: alpine:edge
steps:
- name: Setup environment
# Borrowed from fossas/haskell-static-alpine, copied here for transparency
run: |
apk --no-cache add binutils-gold curl gcc g++ git gmp-dev ncurses-dev ncurses-static libffi-dev make xz tar perl zlib-dev zlib-static
mkdir -p ~/.ghcup/bin && curl https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > ~/.ghcup/bin/ghcup && chmod +x ~/.ghcup/bin/ghcup
~/.ghcup/bin/ghcup install ghc 8.10.4 && ~/.ghcup/bin/ghcup set ghc 8.10.4 && ~/.ghcup/bin/ghcup install cabal
echo "$HOME/.ghcup/bin/" >> $GITHUB_PATH
- name: Check out
uses: actions/checkout@v2
- name: Update cabal
run: cabal update
- name: Build on alpine
run: cabal build --enable-executable-static all
- name: Extract and strip binaries
run: |
mkdir /tmp/hledger
cp dist-newstyle/build/x86_64-linux/ghc-*/hledger-web-*/x/hledger-web/build/hledger-web/hledger-web /tmp/hledger/hledger-web-static-linux-x64
cp dist-newstyle/build/x86_64-linux/ghc-*/hledger-ui-*/x/hledger-ui/build/hledger-ui/hledger-ui /tmp/hledger/hledger-ui-static-linux-x64
cp dist-newstyle/build/x86_64-linux/ghc-*/hledger-*/x/hledger/build/hledger/hledger /tmp/hledger/hledger-static-linux-x64
strip /tmp/hledger/hledger-web-static-linux-x64
strip /tmp/hledger/hledger-ui-static-linux-x64
strip /tmp/hledger/hledger-static-linux-x64
- name: Upload binaries
uses: actions/upload-artifact@v2
with:
name: Static Binaries
path: /tmp/hledger
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
/tmp/hledger/hledger-static-linux-x64
/tmp/hledger/hledger-web-static-linux-x64
/tmp/hledger/hledger-ui-static-linux-x64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -0,0 +1,39 @@
FROM arm32v7/ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update && apt-get install -y --no-install-recommends tzdata && apt-get install -y gcc g++ make xz-utils wget vim libtinfo5 git python3 libgmp-dev libtinfo-dev zlib1g-dev locales && rm -rf /var/lib/apt/lists/*
RUN locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 && update-locale LANG=en_US.UTF-8 && update-locale LANGUAGE=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.UTF-8
# Download and install LLVM 9.0, GHC 8.10.4, cabal 3.0, and newer libffi (for cabal)
RUN wget --no-check-certificate "https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/clang+llvm-9.0.1-armv7a-linux-gnueabihf.tar.xz" \
&& wget --no-check-certificate "https://downloads.haskell.org/~ghc/8.10.4/ghc-8.10.4-armv7-deb10-linux.tar.xz" \
&& wget --no-check-certificate "http://ports.ubuntu.com/ubuntu-ports/pool/universe/libf/libffi/libffi8ubuntu1-udeb_3.4~20200819gead65ca871-0ubuntu3_armhf.udeb" \
&& wget --no-check-certificate "http://ports.ubuntu.com/ubuntu-ports/pool/universe/h/haskell-cabal-install/cabal-install_3.0.0.0-3build1_armhf.deb" \
&& echo "91638613913537f8c0c84a59f59f00fafeafb6b189164cae471d4e3bccaf1df3 clang+llvm-9.0.1-armv7a-linux-gnueabihf.tar.xz" | sha256sum -c \
&& echo "0d18ef83593272f6196a41cc3abdc48dfe5e14372db75d71ea19fe35320c4e81 ghc-8.10.4-armv7-deb10-linux.tar.xz" | sha256sum -c \
&& echo "d9c2ab89b31b156e83320431922a8cc9302f0e4ddd89900028362d18a938cf00 libffi8ubuntu1-udeb_3.4~20200819gead65ca871-0ubuntu3_armhf.udeb" | sha256sum -c \
&& echo "3afd883584ea01d8253b0273a3704c60c4f704ae7d7ac92dbb709ef951f8b2d6 cabal-install_3.0.0.0-3build1_armhf.deb" | sha256sum -c \
&& tar xvf clang+llvm-9.0.1-armv7a-linux-gnueabihf.tar.xz \
&& tar xvf ghc-8.10.4-armv7-deb10-linux.tar.xz \
&& cd clang+llvm-9.0.1-armv7a-linux-gnueabihf && mv bin/* /usr/local/bin/ && mv include/* /usr/local/include/ && mv lib/* /usr/local/lib/ && cd .. && rm clang+llvm-9.0.1-armv7a-linux-gnueabihf.tar.xz \
&& cd ghc-8.10.4 && ./configure && make install && cd .. && rm -r ghc-8.10.4 && rm ghc-8.10.4-armv7-deb10-linux.tar.xz \
&& dpkg -i --force-all libffi8ubuntu1-udeb_3.4~20200819gead65ca871-0ubuntu3_armhf.udeb cabal-install_3.0.0.0-3build1_armhf.deb \
&& rm libffi8ubuntu1-udeb_3.4~20200819gead65ca871-0ubuntu3_armhf.udeb cabal-install_3.0.0.0-3build1_armhf.deb
# Run cabal update
RUN cabal update
# Get access to hledger source to build
COPY . /hledger
# Build static hledger binary
RUN cd /hledger && cabal build --enable-executable-static --with-compiler=/usr/local/bin/ghc-8.10.4 hledger
# Strip symbols from binary
RUN cp /hledger/dist-newstyle/build/arm-linux/ghc-*/hledger-*/x/hledger/build/hledger/hledger /root/ && strip /root/hledger