diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 179be7c..cf42c54 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -10,7 +10,7 @@ jobs: - run: docker version - run: cat /proc/cpuinfo # test - - run: DOCKER_BUILDKIT=1 docker build -t aind/aind:local . + - run: ./hack/translate-dockerfile-runopt-directive.sh < Dockerfile | DOCKER_BUILDKIT=1 docker build -f - -t aind/aind:local . - run: sudo ./hack/install-kmod.sh - run: docker run -td --name aind --privileged -p 5900:5900 -v /lib/modules:/lib/modules:ro aind/aind:local - run: timeout 60 sh -exc "until docker exec aind pgrep -f org.anbox.appmgr; do sleep 10; done" diff --git a/Dockerfile b/Dockerfile index b3b15c9..9f6ad2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,6 @@ +# this dockerfile can be translated to `docker/dockerfile:1-experimental` syntax for enabling cache mounts: +# $ ./hack/translate-dockerfile-runopt-directive.sh < Dockerfile | DOCKER_BUILDKIT=1 docker build -f - . + ARG BASE=ubuntu:20.04 # Apr 14, 2020 @@ -56,10 +59,11 @@ COPY ./src/patches/anbox /patches RUN git config user.email "nobody@example.com" && \ git config user.name "AinD Build Script" && \ git am /patches/* && git show --summary -RUN mkdir build && \ - cd build && \ - cmake .. && \ - make -j10 anbox +# runopt = --mount=type=cache,id=aind-anbox,target=/build +RUN mkdir -p /build && cd /build && \ + cmake ../anbox && \ + make -j10 anbox && \ + cp -f ./src/anbox /anbox-binary FROM ${BASE} AS android-img ENV DEBIAN_FRONTEND=noninteractive @@ -112,7 +116,7 @@ RUN mkdir -p /apk-pre.d /apk.d && \ chmod 444 /apk-pre.d/* COPY --from=lxc /usr/local /usr/local/ COPY --from=android-img /android.img /aind-android.img -COPY --from=anbox /anbox/build/src/anbox /usr/local/bin/anbox +COPY --from=anbox /anbox-binary /usr/local/bin/anbox COPY --from=anbox /anbox/scripts/anbox-bridge.sh /usr/local/share/anbox/anbox-bridge.sh COPY --from=anbox /anbox/data/ui /usr/local/share/anbox/ui RUN ldconfig diff --git a/hack/translate-dockerfile-runopt-directive.sh b/hack/translate-dockerfile-runopt-directive.sh new file mode 100755 index 0000000..f18555c --- /dev/null +++ b/hack/translate-dockerfile-runopt-directive.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# From https://raw.githubusercontent.com/rootless-containers/usernetes/v20200309.0/hack/translate-dockerfile-runopt-directive.sh + +# Input: +# FROM ... +# ... +# # runopt = --mount=type=cache,target=/root/.cache +# RUN foo + +# Output: +# # syntax = docker/dockerfile:1-experimental +# FROM ... +# ... +# RUN --mount=type=cache,target=/root/.cache foo + +echo '# syntax = docker/dockerfile:1-experimental' + +last_runopt="" +while IFS="" read -r line || [[ -n $line ]]; do + run=$(echo $line | grep -ioP '^\s*RUN\s+\K.+') + printed="" + if [[ -n $run && -n $last_runopt ]]; then + echo "RUN $last_runopt $run" + printed=1 + fi + last_runopt=$(echo $line | grep -ioP '^#\s*runopt\s*=\s*\K.+') + if [[ -z $last_runopt && -z $printed ]]; then + echo "$line" + fi +done