Skip to content

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

Open

Description

@dra27

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?!

Activity

  1. changed the title [-]Obuilder_spec.Docker.pp_run needs to escape backslashes[/-] [+]Obuilder_spec.run isn't translating to Dockerfile correctly[/+] on Mar 22, 2021
  2. talex5 commented on Mar 22, 2021

    @talex5
    Contributor

    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?

  3. dra27 commented on Mar 22, 2021

    @dra27
    ContributorAuthor

    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.

  4. dra27 commented on Mar 22, 2021

    @dra27
    ContributorAuthor

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

  5. talex5 commented on Mar 22, 2021

    @talex5
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions