Skip to content

Commit 36f5539

Browse files
ci: introduce reproducible builds (#1476)
* ci: introduce reproducible builds * ci: return 20.04 * smp server: increase timing test threshold * ci: test outside docker * ci: fix test step --------- Co-authored-by: Evgeny Poberezkin <[email protected]>
1 parent 1a2afe8 commit 36f5539

File tree

3 files changed

+77
-36
lines changed

3 files changed

+77
-36
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,53 @@ on:
1111

1212
jobs:
1313
build:
14-
name: build-${{ matrix.os }}-${{ matrix.ghc }}
15-
runs-on: ${{ matrix.os }}
14+
name: "Ubuntu: ${{ matrix.os }}, GHC: ${{ matrix.ghc }}"
15+
env:
16+
apps: "smp-server xftp-server ntf-server xftp"
17+
runs-on: ubuntu-${{ matrix.os }}
1618
strategy:
1719
fail-fast: false
1820
matrix:
1921
include:
20-
- os: ubuntu-20.04
21-
platform_name: 20_04-x86-64
22+
- os: 22.04
2223
ghc: "8.10.7"
23-
- os: ubuntu-20.04
2424
platform_name: 20_04-x86-64
25+
- os: 20.04
26+
ghc: "9.6.3"
27+
platform_name: 20_04-x86-64
28+
- os: 22.04
2529
ghc: "9.6.3"
26-
- os: ubuntu-22.04
2730
platform_name: 22_04-x86-64
31+
- os: 24.04
2832
ghc: "9.6.3"
33+
platform_name: 24_04-x86-64
2934
steps:
3035
- name: Clone project
3136
uses: actions/checkout@v3
3237

33-
- name: Setup Haskell
34-
uses: haskell-actions/setup@v2
35-
with:
36-
ghc-version: ${{ matrix.ghc }}
37-
cabal-version: "3.10.1.0"
38-
39-
- name: Cache dependencies
40-
uses: actions/cache@v3
41-
with:
42-
path: |
43-
~/.cabal/store
44-
dist-newstyle
45-
key: ${{ matrix.os }}-${{ hashFiles('cabal.project', 'simplexmq.cabal') }}
38+
- name: Prepare image
39+
shell: bash
40+
run: docker build -f Dockerfile.build --build-arg TAG=${{ matrix.os }} --build-arg GHC=${{ matrix.ghc }} -t local .
4641

47-
- name: Build
42+
- name: Start container
4843
shell: bash
49-
run: cabal build --enable-tests
44+
run: docker run -t -d --name builder local
5045

51-
- name: Test
52-
timeout-minutes: 40
46+
- name: Build binaries
5347
shell: bash
54-
run: cabal test --test-show-details=direct
48+
run: docker exec -t -e apps="$apps" builder sh -c 'cabal build --enable-tests && mkdir /out && for i in $apps; do bin=$(find /project/dist-newstyle -name "$i" -type f -executable); strip "$bin"; chmod +x "$bin"; mv "$bin" /out/; done'
5549

56-
- name: Prepare binaries
50+
- name: Copy binaries from container and prepare them
5751
if: startsWith(github.ref, 'refs/tags/v')
5852
shell: bash
5953
run: |
60-
mv $(cabal list-bin smp-server) smp-server-ubuntu-${{ matrix.platform_name}}
61-
mv $(cabal list-bin ntf-server) ntf-server-ubuntu-${{ matrix.platform_name}}
62-
mv $(cabal list-bin xftp-server) xftp-server-ubuntu-${{ matrix.platform_name}}
63-
mv $(cabal list-bin xftp) xftp-ubuntu-${{ matrix.platform_name}}
54+
docker cp builder:/out .
55+
for i in $apps; do mv ./out/$i ./$i-ubuntu-${{ matrix.platform_name }}; done
6456
6557
- name: Build changelog
6658
if: startsWith(github.ref, 'refs/tags/v')
6759
id: build_changelog
68-
uses: mikepenz/release-changelog-builder-action@v1
60+
uses: mikepenz/release-changelog-builder-action@v5
6961
with:
7062
configuration: .github/changelog_conf.json
7163
failOnError: true
@@ -76,7 +68,7 @@ jobs:
7668

7769
- name: Create release
7870
if: startsWith(github.ref, 'refs/tags/v') && matrix.ghc != '8.10.7'
79-
uses: softprops/action-gh-release@v1
71+
uses: softprops/action-gh-release@v2
8072
with:
8173
body: |
8274
See full changelog [here](https://github.com/simplex-chat/simplexmq/blob/master/CHANGELOG.md).
@@ -86,10 +78,17 @@ jobs:
8678
prerelease: true
8779
files: |
8880
LICENSE
89-
smp-server-ubuntu-${{ matrix.platform_name}}
90-
ntf-server-ubuntu-${{ matrix.platform_name}}
91-
xftp-server-ubuntu-${{ matrix.platform_name}}
92-
xftp-ubuntu-${{ matrix.platform_name}}
81+
smp-server-ubuntu-${{ matrix.platform_name }}
82+
ntf-server-ubuntu-${{ matrix.platform_name }}
83+
xftp-server-ubuntu-${{ matrix.platform_name }}
84+
xftp-ubuntu-${{ matrix.platform_name }}
9385
fail_on_unmatched_files: true
9486
env:
9587
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Test
90+
shell: bash
91+
run: |
92+
docker exec -t builder sh -c 'mv $(find /project/dist-newstyle -name "simplexmq-test" -type f -executable) /out/'
93+
docker cp builder:/out/simplexmq-test .
94+
./simplexmq-test

Dockerfile.build

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# syntax=docker/dockerfile:1.7.0-labs
2+
ARG TAG=24.04
3+
FROM ubuntu:${TAG} AS build
4+
5+
### Build stage
6+
7+
ARG GHC=9.6.3
8+
ARG CABAL=3.14.1.1
9+
10+
# Install curl, git and and simplexmq dependencies
11+
RUN apt-get update && apt-get install -y curl git sqlite3 libsqlite3-dev build-essential libgmp3-dev zlib1g-dev llvm llvm-dev libnuma-dev libssl-dev
12+
13+
# Specify bootstrap Haskell versions
14+
ENV BOOTSTRAP_HASKELL_GHC_VERSION=${GHC}
15+
ENV BOOTSTRAP_HASKELL_CABAL_VERSION=${CABAL}
16+
17+
# Do not install Stack
18+
ENV BOOTSTRAP_HASKELL_INSTALL_NO_STACK=true
19+
ENV BOOTSTRAP_HASKELL_INSTALL_NO_STACK_HOOK=true
20+
21+
# Install ghcup
22+
RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 sh
23+
24+
# Adjust PATH
25+
ENV PATH="/root/.cabal/bin:/root/.ghcup/bin:$PATH"
26+
27+
# Set both as default
28+
RUN ghcup set ghc "${GHC}" && \
29+
ghcup set cabal "${CABAL}"
30+
31+
# Copy only the source code
32+
COPY apps /project/apps/
33+
COPY cbits /project/cbits/
34+
COPY src /project/src/
35+
COPY tests /project/tests/
36+
37+
COPY cabal.project Setup.hs simplexmq.cabal LICENSE /project
38+
39+
WORKDIR /project
40+
41+
# Compile app
42+
RUN cabal update

tests/ServerTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ testTiming =
869869
(C.AuthAlg C.SX25519, C.AuthAlg C.SX25519, 200) -- correct key type
870870
]
871871
timeRepeat n = fmap fst . timeItT . forM_ (replicate n ()) . const
872-
similarTime t1 t2 = abs (t2 / t1 - 1) < 0.25 -- normally the difference between "no queue" and "wrong key" is less than 5%
872+
similarTime t1 t2 = abs (t2 / t1 - 1) < 0.30 -- normally the difference between "no queue" and "wrong key" is less than 5%
873873
testSameTiming :: forall c. Transport c => THandleSMP c 'TClient -> THandleSMP c 'TClient -> (C.AuthAlg, C.AuthAlg, Int) -> Expectation
874874
testSameTiming rh sh (C.AuthAlg goodKeyAlg, C.AuthAlg badKeyAlg, n) = do
875875
g <- C.newRandom

0 commit comments

Comments
 (0)