ocurrent / obuilder

Experimental "docker build" alternative using btrfs/zfs snapshots
Apache License 2.0
60 stars 17 forks source link

Obuilder_spec.run isn't translating to Dockerfile correctly #66

Open dra27 opened 3 years ago

dra27 commented 3 years ago

Merely picking a recent build from opam-repo-ci.

This fragment from opam-repo-ci:

run ~cache ~network {|
        opam remove -y %s && opam %s%s %s
        res=$?
        test "$res" = 0 && exit 0
        if test "$res" = 60 && diff -q /usr/bin/opam /usr/bin/opam-2.0; then
          sudo ln -f /usr/bin/opam-2.1 /usr/bin/opam
          opam remove -y %s && opam install -vy%s %s%s
          exit 1
        fi
        test "$res" != 31 && exit 1
        export OPAMCLI=2.0
        build_dir=$(opam var prefix)/.opam-switch/build
        failed=$(ls "$build_dir")
        for pkg in $failed; do
          if opam show -f x-ci-accept-failures: "$pkg" | grep -qF "\"%s\""; then
            echo "A package failed and has been disabled for CI using the 'x-ci-accept-failures' field."
          fi
        done
        exit 1
      |}
      pkg (if upgrade_opam then "install -vy" else "depext -uivy") (if with_tests then "t" else "") pkg
      pkg (if with_tests then "t" else "") pkg (if with_tests then "" else " && opam reinstall -vyt "^pkg)
      (Variant.distribution variant)

is rendered:

RUN  \
    opam remove -y leveldb.1.3.0 && opam depext -uivy leveldb.1.3.0 \
    res=$? \
    test "$res" = 0 && exit 0 \
    if test "$res" = 60 && diff -q /usr/bin/opam /usr/bin/opam-2.0; then \
    sudo ln -f /usr/bin/opam-2.1 /usr/bin/opam \
    opam remove -y leveldb.1.3.0 && opam install -vy leveldb.1.3.0 && opam reinstall -vyt leveldb.1.3.0 \
    exit 1 \
    fi \
    test "$res" != 31 && exit 1 \
    export OPAMCLI=2.0 \
    build_dir=$(opam var prefix)/.opam-switch/build \
    failed=$(ls "$build_dir") \
    for pkg in $failed; do \
    if opam show -f x-ci-accept-failures: "$pkg" | grep -qF "\"alpine-3.12\""; then \
    echo "A package failed and has been disabled for CI using the 'x-ci-accept-failures' field." \
    fi \
    done \
    exit 1 \

but it needs semi-colons at the end of most lines. Not sure if escaping is the answer or possibly invoking via a HERE document?!

talex5 commented 3 years ago

I think the problem here is that the Dockerfile format just doesn't support this (see https://stackoverflow.com/questions/33439230/how-to-write-commands-with-multiple-lines-in-dockerfile-while-preserving-the-new).

Perhaps we should just reject attempts to convert to Dockerfile format in this case?

dra27 commented 3 years ago

Ouch, yes - if there isn't a workaround for here then we should just reject, I agree. I'll open an issue on opam-repo-ci to workaround it.

dra27 commented 3 years ago

Oh, there is a possible workaround, remembering horrid things we used to do in OCaml's testsuite - escaping newlines as :; \ certainly works here.

talex5 commented 3 years ago

Note that OBuilder allows you to use any shell, so shell-specific hacks won't work here.