Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
Dockerfile: enable RUN --mount=type=cache
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Apr 18, 2020
1 parent 99ee195 commit 70a64a8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -56,10 +59,11 @@ COPY ./src/patches/anbox /patches
RUN git config user.email "[email protected]" && \
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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions hack/translate-dockerfile-runopt-directive.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 70a64a8

Please sign in to comment.