From 6bb86e82a0adfd520883aa395f25be96bd125d42 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Tue, 29 Nov 2022 11:54:27 +0530 Subject: [PATCH 1/2] Github action to check static binary --- .github/workflows/build.yml | 10 +++++++++- .github/workflows/release.yml | 15 +++++---------- Dockerfile | 7 +++++++ justfile | 21 +++++++++++++++++++++ 4 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 Dockerfile create mode 100644 justfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8fdec1e..18a7452 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,9 @@ jobs: uses: actions/checkout@v2 with: submodules: 'true' - + - uses: extractions/setup-just@v1 + with: + just-version: 1.1.3 - name: Cache dependencies uses: actions/cache@v2 with: @@ -44,3 +46,9 @@ jobs: set -exuo pipefail curl -sSL https://get.haskellstack.org/ | sh -s - -f stack test --fast --no-terminal --stack-yaml=${{ matrix.stack-yaml }} --resolver=${{ matrix.resolver }} + - name: Static Binary check + shell: bash + run: | + set -exuo pipefail + just copy-static-pid1 + just test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index faa8d69..1ebbdd1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,14 +13,9 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') with: - tag_name: ${{ github.ref }} - release_name: pid1-${{ github.ref }} - body_path: ChangeLog.md - draft: false - prerelease: false + files: pid1 + generate_release_notes: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..14e9ca0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM fpco/alpine-haskell-stack:9.2.5 + +COPY . /app + +RUN apk add upx \ + && env STACK_YAML=/app/stack.yaml stack --system-ghc install --local-bin-path /app --flag pid1:static \ + && upx --best /app/pid1 diff --git a/justfile b/justfile new file mode 100644 index 0000000..50fc79a --- /dev/null +++ b/justfile @@ -0,0 +1,21 @@ +# List all recipies +default: + just --list --unsorted + +# Build image +build-image: + docker build --file Dockerfile . --tag pid1 + +# Copy static binary from container +copy-static-pid1: build-image + #!/usr/bin/env bash + set -euo pipefail + CID=$(docker create pid1) + docker cp ${CID}:/app/pid1 . + docker rm ${CID} + ls -lah pid1 + +# Sanity test the binary +test: + file ./pid1 + ./pid1 -- ps From 92b6dc757078cb51435d91defed89370efb6fae0 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Tue, 29 Nov 2022 12:06:05 +0530 Subject: [PATCH 2/2] Generate static binary in release workflow --- .github/workflows/release.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1ebbdd1..ecda934 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,15 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 + - uses: extractions/setup-just@v1 + with: + just-version: 1.1.3 + - name: Static Binary Generation + shell: bash + run: | + set -exuo pipefail + just copy-static-pid1 + just test - name: Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/')