From b3d0dfb704e8b022cfaa8daa30dfeabcdf30fcf3 Mon Sep 17 00:00:00 2001 From: hiepxanh Date: Fri, 4 Jun 2021 15:14:04 +0700 Subject: [PATCH 1/3] docs: dockerfiles buildkit add cache directory ex Add example how to cache directory on dockerfile --- docs/deployment/builders/dockerfiles.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/deployment/builders/dockerfiles.md b/docs/deployment/builders/dockerfiles.md index 581fb41e2..56eaf29b5 100644 --- a/docs/deployment/builders/dockerfiles.md +++ b/docs/deployment/builders/dockerfiles.md @@ -77,6 +77,17 @@ RUN echo $NODE_ENV If your Dockerfile is using Docker engine's [buildkit](https://docs.docker.com/develop/develop-images/build_enhancements/) (not to be confused with buildpacks), then the `DOCKER_BUILDKIT=1` environment variable needs to be set. One way to do this is to edit `/etc/environment` on your dokku host and reboot your instance. Note, for complete build log output, you should also set `BUILDKIT_PROGRESS=plain` in the same file. +Buildkit has implemented the RUN --mount option which lets you mount a cache directory for your run commands. E.g. here's one that mounts some of the debian directories (with a reconfigure of the debian image, this could speed up reinstalls of packages): +```Dockerfile +FROM debian:latest +RUN --mount=target=/var/lib/apt/lists,type=cache \ + --mount=target=/var/cache/apt,type=cache \ + apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git +``` +You would adjust the cache directory for whatever application cache you have, e.g. `/root/.pnpm-store/v3` for pnpm, `$HOME/.m2` for maven, or `/root/.cache` for golang. + ### Customizing the run command By default no arguments are passed to `docker run` when deploying the container and the `CMD` or `ENTRYPOINT` defined in the `Dockerfile` are executed. You can take advantage of docker ability of overriding the `CMD` or passing parameters to your `ENTRYPOINT` setting `$DOKKU_DOCKERFILE_START_CMD`. Let's say for example you are deploying a base Node.js image, with the following `ENTRYPOINT`: From c1df31b106da6eb8c7897deea67c143e2b5e611a Mon Sep 17 00:00:00 2001 From: hiepxanh Date: Fri, 4 Jun 2021 15:21:35 +0700 Subject: [PATCH 2/3] docs: dockerfiles buildkit add cache directory ex --- docs/deployment/builders/dockerfiles.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/deployment/builders/dockerfiles.md b/docs/deployment/builders/dockerfiles.md index 56eaf29b5..3f18ee880 100644 --- a/docs/deployment/builders/dockerfiles.md +++ b/docs/deployment/builders/dockerfiles.md @@ -77,17 +77,6 @@ RUN echo $NODE_ENV If your Dockerfile is using Docker engine's [buildkit](https://docs.docker.com/develop/develop-images/build_enhancements/) (not to be confused with buildpacks), then the `DOCKER_BUILDKIT=1` environment variable needs to be set. One way to do this is to edit `/etc/environment` on your dokku host and reboot your instance. Note, for complete build log output, you should also set `BUILDKIT_PROGRESS=plain` in the same file. -Buildkit has implemented the RUN --mount option which lets you mount a cache directory for your run commands. E.g. here's one that mounts some of the debian directories (with a reconfigure of the debian image, this could speed up reinstalls of packages): -```Dockerfile -FROM debian:latest -RUN --mount=target=/var/lib/apt/lists,type=cache \ - --mount=target=/var/cache/apt,type=cache \ - apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - git -``` -You would adjust the cache directory for whatever application cache you have, e.g. `/root/.pnpm-store/v3` for pnpm, `$HOME/.m2` for maven, or `/root/.cache` for golang. - ### Customizing the run command By default no arguments are passed to `docker run` when deploying the container and the `CMD` or `ENTRYPOINT` defined in the `Dockerfile` are executed. You can take advantage of docker ability of overriding the `CMD` or passing parameters to your `ENTRYPOINT` setting `$DOKKU_DOCKERFILE_START_CMD`. Let's say for example you are deploying a base Node.js image, with the following `ENTRYPOINT`: @@ -140,3 +129,17 @@ in your `Procfile` will be passed as arguments to the `ENTRYPOINT` script instea ### Exposed ports See the [port management documentation](/docs/networking/port-management.md) for more information on how Dokku exposes ports for applications and how you can configure these for your app. + +### Cache the directory that could help speed up reinstalls of packages on CI + +Buildkit has implemented the RUN --mount option which lets you mount a cache directory for your run commands. E.g. here's one that mounts some of the debian directories (with a reconfigure of the debian image, this could speed up reinstalls of packages): +```Dockerfile +FROM debian:latest +RUN --mount=target=/var/lib/apt/lists,type=cache \ + --mount=target=/var/cache/apt,type=cache \ + apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git +``` +You would adjust the cache directory for whatever application cache you have, e.g. `/root/.pnpm-store/v3` for pnpm, `$HOME/.m2` for maven, or `/root/.cache` for golang. + From 0759c055d3e62df86066df310e3466ddc99f8cfe Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 6 Jun 2021 17:49:40 -0400 Subject: [PATCH 3/3] chore: reword buildkit cache docs --- docs/deployment/builders/dockerfiles.md | 32 ++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/deployment/builders/dockerfiles.md b/docs/deployment/builders/dockerfiles.md index 3f18ee880..c0353de88 100644 --- a/docs/deployment/builders/dockerfiles.md +++ b/docs/deployment/builders/dockerfiles.md @@ -77,6 +77,24 @@ RUN echo $NODE_ENV If your Dockerfile is using Docker engine's [buildkit](https://docs.docker.com/develop/develop-images/build_enhancements/) (not to be confused with buildpacks), then the `DOCKER_BUILDKIT=1` environment variable needs to be set. One way to do this is to edit `/etc/environment` on your dokku host and reboot your instance. Note, for complete build log output, you should also set `BUILDKIT_PROGRESS=plain` in the same file. +#### Buildkit directory caching + +Buildkit implements the `RUN --mount` option, enabling mount directory caches for `RUN` directives. The following is an example that mounts debian packaging related directories, which can speed up fetching of remote package data. + +```Dockerfile +FROM debian:latest +RUN --mount=target=/var/lib/apt/lists,type=cache \ + --mount=target=/var/cache/apt,type=cache \ + apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git +``` + +Mount cache targets may vary depending on the tool in use, and users are encouraged to investigate the directories that apply for their language and framework. + + +You would adjust the cache directory for whatever application cache you have, e.g. `/root/.pnpm-store/v3` for pnpm, `$HOME/.m2` for maven, or `/root/.cache` for golang. + ### Customizing the run command By default no arguments are passed to `docker run` when deploying the container and the `CMD` or `ENTRYPOINT` defined in the `Dockerfile` are executed. You can take advantage of docker ability of overriding the `CMD` or passing parameters to your `ENTRYPOINT` setting `$DOKKU_DOCKERFILE_START_CMD`. Let's say for example you are deploying a base Node.js image, with the following `ENTRYPOINT`: @@ -129,17 +147,3 @@ in your `Procfile` will be passed as arguments to the `ENTRYPOINT` script instea ### Exposed ports See the [port management documentation](/docs/networking/port-management.md) for more information on how Dokku exposes ports for applications and how you can configure these for your app. - -### Cache the directory that could help speed up reinstalls of packages on CI - -Buildkit has implemented the RUN --mount option which lets you mount a cache directory for your run commands. E.g. here's one that mounts some of the debian directories (with a reconfigure of the debian image, this could speed up reinstalls of packages): -```Dockerfile -FROM debian:latest -RUN --mount=target=/var/lib/apt/lists,type=cache \ - --mount=target=/var/cache/apt,type=cache \ - apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - git -``` -You would adjust the cache directory for whatever application cache you have, e.g. `/root/.pnpm-store/v3` for pnpm, `$HOME/.m2` for maven, or `/root/.cache` for golang. -