Skip to content

Commit

Permalink
use a docker image for ci
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Jan 10, 2024
1 parent fae1898 commit fae139c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 149 deletions.
85 changes: 8 additions & 77 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:

jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -47,89 +46,22 @@ jobs:
- smalltalk
# - tcl
- zig
runs-on: ubuntu-latest
container:
image: acheronfail/count
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
target/
key: ${{ runner.os }}-cargo
- uses: actions/cache@v3
with:
path: scripts/node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
# install dependencies
- uses: extractions/setup-just@v1
- uses: oven-sh/setup-bun@v1
- uses: denoland/setup-deno@v1
with:
deno-version: "~1"
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cargo \
clang \
coffeescript \
curl \
erlang \
fp-compiler \
gforth \
gfortran \
gnu-smalltalk \
gnucobol3 \
haskell-platform \
jq \
kotlin \
lua5.4 \
mono-devel \
moreutils \
nasm \
nodejs \
php \
rustc \
scala \
swi-prolog \
tar \
tcl \
wget \
xz-utils
cargo install timers
cargo install hyperfine
cargo install ripgrep --features 'pcre2'
cargo install juliaup
juliaup add release
wget -qO choosenim.sh https://nim-lang.org/choosenim/init.sh
bash ./choosenim.sh -y
echo "$HOME/.nimble/bin" >> $GITHUB_PATH
export PATH="$HOME/.nimble/bin:$PATH"
curl -fsSL https://crystal-lang.org/install.sh | sudo bash
mkdir -p /opt/zig && cd $_
wget --quiet -O zig.tar.xz $(curl --silent https://ziglang.org/download/index.json | jq -r '.[keys_unsorted[1]]["x86_64-linux"].tarball')
tar -xvf zig.tar.xz --strip-components=1 2>&1 >/dev/null
echo "/opt/zig" >> $GITHUB_PATH
export PATH="/opt/zig:$PATH"
cd -
# really github? why do you override $HOME?
# https://github.com/actions/runner/issues/863
- run: 'echo HOME=/root >> $GITHUB_ENV'
# do the thing
- run: just test ${{ matrix.build }}
- run: just measure ${{ matrix.build }}
# report
- uses: actions/upload-artifact@v3
with:
path: "${{ matrix.build }}.json"
path: "results/${{ matrix.build }}.json"

report:
needs: ["run"]
Expand All @@ -145,8 +77,7 @@ jobs:
- name: Generate Summary
run: |
cd scripts
npm install
node ./summary.js --results ../artifact > summary.txt
npm start -- --results ../artifact > summary.txt
cat summary.txt
- uses: actions/upload-artifact@v3
with:
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build
results
results/*.json
*.out
*.dump
*.beam
Expand All @@ -13,4 +13,5 @@ java/
kotlin/
scala/
CMD
VERSION
VERSION
STATS
84 changes: 30 additions & 54 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,43 @@
FROM ubuntu:latest

ENV DEBIAN_FRONTEND="noninteractive" TZ="Europe/London"
RUN apt-get update && apt-get install -y \
build-essential clang curl jq moreutils sudo tar unzip wget xz-utils

RUN useradd -m runner && echo "runner ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/runner
USER runner
RUN apt-get update && apt-get install -y \
build-essential clang coffeescript curl default-jdk default-jre erlang \
fp-compiler gdb lldb gforth gfortran git gnu-smalltalk gnucobol3 golang \
haskell-platform jq kotlin lua5.4 mono-complete moreutils nasm php ruby \
scala swi-prolog tar tcl unzip wget xz-utils \
&& apt-get clean
RUN curl -fSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs

RUN curl \
-sSfL \
--proto '=https' \
--tlsv1.2 \
https://sh.rustup.rs | sh -s -- --default-toolchain stable -y
RUN curl -fSL https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
ENV PATH="/root/.cargo/bin:$PATH"

RUN curl \
-sSfL \
--proto '=https' \
--tlsv1.2 \
https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN curl -fSL \
https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh \
| bash
RUN cargo install ripgrep --features pcre2
RUN cargo binstall --no-confirm hyperfine just timers juliaup

ENV PATH="/home/runner/.cargo/bin:$PATH"
RUN cargo binstall --no-confirm hyperfine just ripgrep timers
RUN juliaup add release

RUN cargo binstall --no-confirm juliaup && juliaup add release
RUN curl -fsSL https://bun.sh/install | bash
RUN curl -fsSL https://deno.land/x/install/install.sh | sh
RUN sudo -E apt-get install -y coffeescript
RUN sudo -E apt-get install -y erlang
RUN sudo -E apt-get install -y fp-compiler
RUN sudo -E apt-get install -y gforth
RUN sudo -E apt-get install -y gfortran
RUN sudo -E apt-get install -y gnu-smalltalk
RUN sudo -E apt-get install -y gnucobol3
RUN sudo -E apt-get install -y haskell-platform
RUN sudo -E apt-get install -y kotlin
RUN sudo -E apt-get install -y lua5.4
RUN sudo -E apt-get install -y nasm
RUN sudo -E apt-get install -y nodejs
RUN sudo -E apt-get install -y php
RUN sudo -E apt-get install -y scala
RUN sudo -E apt-get install -y swi-prolog
RUN sudo -E apt-get install -y tcl
RUN curl -fSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:$PATH"

RUN curl -fsSL https://crystal-lang.org/install.sh | sudo bash
RUN curl -fSL https://deno.land/x/install/install.sh | sh
ENV PATH="/root/.deno/bin:$PATH"

RUN curl \
-sSfL \
--proto '=https' \
--tlsv1.2 \
https://nim-lang.org/choosenim/init.sh | sh -s -- -y
ENV PATH="/home/runner/.nimble/bin:$PATH"
RUN curl -fSL https://crystal-lang.org/install.sh | bash

RUN sudo mkdir -p /opt/zig && cd $_ && \
wget \
--quiet \
-O zig.tar.xz \
$(curl --silent https://ziglang.org/download/index.json | jq -r '.[keys_unsorted[1]]["x86_64-linux"].tarball') && \
tar -xvf zig.tar.xz --strip-components=1 2>&1 >/dev/null
ENV PATH="/opt/zig:$PATH"
RUN curl -fSL https://nim-lang.org/choosenim/init.sh | sh -s -- -y
ENV PATH="/root/.nimble/bin:$PATH"

# FIXME: https://github.com/mono/mono/issues/21423
# installing gdb/lldb provide a better error message when mono-devel fails to install
RUN sudo -E apt-get install -y gdb lldb
RUN sudo -E apt-get install -y mono-complete
RUN cd && curl -fSL "$(curl -fSL https://ziglang.org/download/index.json | jq -r '.[keys_unsorted[1]]["x86_64-linux"].tarball')" \
> zig.tar.xz \
&& mkdir -p "/root/.zig" \
&& tar -xvf zig.tar.xz --strip-components=1 -C "/root/.zig" \
&& rm zig.tar.xz
ENV PATH="/root/.zig:$PATH"

# TODO: when this docker image works, get CI to use it
WORKDIR /var/count
54 changes: 38 additions & 16 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
i := '1000000000'
tag := 'acheronfail/count'
mount := '/var/count'

_default:
just -l
Expand All @@ -9,18 +11,37 @@ _default:
setup: (_check "npm")
cd scripts && npm install

docker-amd64:
docker run --rm -ti --platform 'linux/amd64' -v "$PWD:/data" ubuntu:22.04 bash
docker-sh:
docker run --rm -ti --platform 'linux/amd64' -v "$PWD:{{mount}}" {{tag}}

build-docker:
docker build --platform 'linux/amd64' -t count .
# NOTE: there are issues if you try to build this on an arm macbook via rosetta emulation
# - mono fails to install (https://github.com/mono/mono/issues/21423)
# - getting erlang version segfaults
docker-build:
docker build --progress=plain --platform 'linux/amd64' -t {{tag}} .

# just checks if mono can be installed in docker, since there's an issue with it
# currently preventing us from shipping this docker image properly
# see: https://github.com/mono/mono/issues/21423
check-docker:
docker run --rm -ti --platform 'linux/amd64' ubuntu \
sh -c 'apt update && DEBIAN_FRONTEND=noninteractive TZ="Europe/London" apt install -y mono-complete'
docker-pull:
docker pull {{tag}}

docker-push: docker-build
docker push {{tag}}

docker-measure what:
docker run --rm -ti --platform 'linux/amd64' -v "$PWD:{{mount}}" {{tag}} just measure {{what}}

docker-measure-all:
docker run --rm -ti --platform 'linux/amd64' -v "$PWD:{{mount}}" {{tag}} just measure-all

measure-all:
#!/usr/bin/env bash
set -exuo pipefail
for lang in $(just -l | grep 'build-' | cut -d'-' -f2- | xargs); do
just test "$lang";
just measure "$lang";
done

cd scripts && npm start

build what:
rm -f CMD VERSION
Expand All @@ -33,9 +54,7 @@ run what:
measure what:
#!/usr/bin/env bash
set -euxo pipefail
just build {{what}}

slow_langs=(
cobol
haskell
Expand All @@ -57,18 +76,21 @@ measure what:
fi
done

out="{{what}}.json"
mkdir -p results
out="results/{{what}}.json"

hyperfine $args --shell=none --export-json "$out" "$(cat CMD)"
jq '.results[0] | del(.exit_codes)' "$out" | sponge "$out"
jq '. += {"name":"{{what}}","version":"'"$(cat VERSION)"'"}' "$out" | sponge "$out"
timers $(cat CMD) >/dev/null 2> >(jq '. += {"max_rss":'$(rg -oP '(?:max_rss:\s*)(\d+)' -r '$1')'}' "$out" | sponge "$out")
timers $(cat CMD) >/dev/null 2> STATS
jq '. += {"max_rss":'$(rg -oP '(?:max_rss:\s*)(\d+)' -r '$1' ./STATS)'}' "$out" | sponge "$out"

summary results:
cd scripts && node ./summary.js --results ..
summary:
cd scripts && npm start -- --results ../results

test what:
#!/usr/bin/env bash
set -euo pipefail
just build {{what}}
tests=(
1 1
Expand Down
Empty file added results/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"type": "module",
"scripts": {
"start": "npm install && node summary.js"
},
"dependencies": {
"human-readable": "^0.2.1",
"minimist": "^1.2.8",
Expand Down

0 comments on commit fae139c

Please sign in to comment.