From 782c93c2dc80fc355046def79b715d3b14591d09 Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Wed, 5 Jun 2024 17:03:43 -0700 Subject: [PATCH] Bring back the ability to build Scrapscript in Docker (#145) --- .github/workflows/ci.yml | 1 + Dockerfile | 29 ++++++++++++++++++++++++++++- README.md | 13 +++++++++++++ fly.toml | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e47f5880..48f60ea3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,7 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + target: main deploy: runs-on: ubuntu-latest if: | diff --git a/Dockerfile b/Dockerfile index becbcb1e..fc6c1a33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,34 @@ -FROM caddy +FROM caddy as web COPY . . RUN echo ":8000" > /etc/caddy/Caddyfile RUN echo "rewrite /repl /repl.html" >> /etc/caddy/Caddyfile RUN echo "rewrite /compilerepl /compilerepl.html" >> /etc/caddy/Caddyfile RUN echo "log" >> /etc/caddy/Caddyfile RUN echo "file_server" >> /etc/caddy/Caddyfile + +FROM alpine:latest as build +RUN printf -- '-m\nscrapscript\n...' > .args +RUN wget https://cosmo.zip/pub/cosmos/bin/assimilate +RUN wget https://cosmo.zip/pub/cosmos/bin/ape-x86_64.elf +RUN wget https://cosmo.zip/pub/cosmos/bin/python +RUN wget https://cosmo.zip/pub/cosmos/bin/zip +RUN chmod +x assimilate +RUN chmod +x ape-x86_64.elf +RUN chmod +x python +RUN chmod +x zip +RUN mkdir Lib +COPY scrapscript.py Lib/ +COPY compiler.py Lib/ +COPY runtime.c Lib/ +COPY cli.c Lib/ +RUN ./ape-x86_64.elf ./python -m compileall -b Lib/scrapscript.py Lib/compiler.py +RUN mv python scrapscript.com +RUN ./ape-x86_64.elf ./zip -r scrapscript.com Lib .args +RUN ./ape-x86_64.elf ./assimilate ./scrapscript.com +RUN echo "Testing..." +RUN ./scrapscript.com apply "1+2" + +# Set up the container +FROM scratch as main +COPY --from=build scrapscript.com . +ENTRYPOINT ["./scrapscript.com"] diff --git a/README.md b/README.md index aa915cbc..094869bd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,19 @@ or with [Cosmopolitan](https://justine.lol/cosmopolitan/index.html): (if you have an exec format error and use Zsh, either upgrade Zsh or prefix with `sh`) +or with Docker: + +```bash +# With a file (mount your local directory) +docker run --mount type=bind,source="$(pwd)",target=/mnt -i -t ghcr.io/tekknolagi/scrapscript:trunk eval /mnt/examples/0_home/factorial.scrap + +# With a string literal +docker run -i -t ghcr.io/tekknolagi/scrapscript:trunk apply "1 + 2" + +# With a REPL +docker run -i -t ghcr.io/tekknolagi/scrapscript:trunk repl +``` + ### The experimental compiler: #### Normal ELF diff --git a/fly.toml b/fly.toml index 84fe9873..f8193fbb 100644 --- a/fly.toml +++ b/fly.toml @@ -7,6 +7,7 @@ app = "scrapscript" primary_region = "ewr" [build] +build-target = "web" [http_service] internal_port = 8000