From 485024cb5b0f0b504ac72dc2127c5e44da108072 Mon Sep 17 00:00:00 2001 From: Jacob Marble Date: Mon, 1 Mar 2021 08:21:30 -0800 Subject: [PATCH] feat(docker): add one-command Dockerfile This adds a simple Dockerfile for anyone to just `docker build .` and get a Docker image. This Dockerfile is optimized for human consumption, not for build performance. --- Dockerfile | 51 +++++++++++++++++++ Dockerfile.dockerignore | 4 ++ README.md | 12 +++++ docker/Dockerfile.ci | 3 +- docker/Dockerfile.ci.dockerignore | 2 + .../Dockerfile.iox.dockerignore | 0 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 Dockerfile.dockerignore create mode 100644 docker/Dockerfile.ci.dockerignore rename .dockerignore => docker/Dockerfile.iox.dockerignore (100%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..0610b45ae2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +#syntax=docker/dockerfile:1.2 +FROM rust:slim-buster AS build + +# Build flatbuffers, a dependency of influxdb_iox +ARG flatbuffers_version="v1.12.0" +RUN apt-get update \ + && apt-get install -y \ + git make clang cmake llvm libssl-dev pkg-config \ + --no-install-recommends \ + && git clone -b ${flatbuffers_version} -- https://github.com/google/flatbuffers.git /usr/local/src/flatbuffers \ + && cmake -S /usr/local/src/flatbuffers -B /usr/local/src/flatbuffers \ + -G "Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=Release \ + && make -C /usr/local/src/flatbuffers -j $(nproc) flatc \ + && ln /usr/local/src/flatbuffers/flatc /usr/bin/flatc + +# Build influxdb_iox +COPY . /influxdb_iox +WORKDIR /influxdb_iox +RUN \ + --mount=type=cache,id=influxdb_iox_rustup,sharing=locked,target=/usr/local/rustup \ + rustup component add rustfmt +RUN \ + --mount=type=cache,id=influxdb_iox_rustup,sharing=locked,target=/usr/local/rustup \ + --mount=type=cache,id=influxdb_iox_registry,sharing=locked,target=/usr/local/cargo/registry \ + --mount=type=cache,id=influxdb_iox_git,sharing=locked,target=/usr/local/cargo/git \ + --mount=type=cache,id=influxdb_iox_target,sharing=locked,target=/influxdb_iox/target \ + du -cshx /usr/local/rustup /usr/local/cargo/registry /usr/local/cargo/git /influxdb_iox/target && \ + cargo build --target-dir /influxdb_iox/target --release && \ + cp /influxdb_iox/target/release/influxdb_iox /root/influxdb_iox && \ + du -cshx /usr/local/rustup /usr/local/cargo/registry /usr/local/cargo/git /influxdb_iox/target + +FROM debian:buster-slim + +RUN apt-get update \ + && apt-get install -y libssl1.1 libgcc1 libc6 --no-install-recommends \ + && rm -rf /var/lib/{apt,dpkg,cache,log} + +RUN groupadd -g 1500 rust \ + && useradd -u 1500 -g rust -s /bin/bash -m rust + +USER rust + +RUN mkdir ~/.influxdb_iox +RUN ls -la ~/.influxdb_iox + +COPY --from=build /root/influxdb_iox /usr/bin/influxdb_iox + +EXPOSE 8080 8082 + +ENTRYPOINT ["/usr/bin/influxdb_iox"] diff --git a/Dockerfile.dockerignore b/Dockerfile.dockerignore new file mode 100644 index 0000000000..c09b63f912 --- /dev/null +++ b/Dockerfile.dockerignore @@ -0,0 +1,4 @@ +.*/ +target/ +tests/ +docker/ diff --git a/README.md b/README.md index a64ad54b5a..4762e4839a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,18 @@ We're also hosting monthly tech talks and community office hours on the project To compile and run InfluxDB IOx from source, you'll need a Rust compiler and a `flatc` FlatBuffers compiler. +### Build a Docker Image + +To build a Docker image in one command: +``` +docker build . +``` + +To enable caching, and to respect `Dockerfile.dockerignore`, we strongly suggest that you [enable BuildKit](https://docs.docker.com/develop/develop-images/build_enhancements/#to-enable-buildkit-builds). +- Use Docker version 18.09 or later +- Enable BuildKit by default by setting `{ "features": { "buildkit": true } }` + - ...or run `docker build .` with env var `DOCKER_BUILDKIT=1` + ### Cloning the Repository Using `git`, check out the code by cloning this repository. If you use the `git` command line, this diff --git a/docker/Dockerfile.ci b/docker/Dockerfile.ci index 95aa9f76a7..58fd958d5e 100644 --- a/docker/Dockerfile.ci +++ b/docker/Dockerfile.ci @@ -12,12 +12,13 @@ # Build any binaries that can be copied into the CI image # Note we build flatbuffers from source (pinned to a particualar version) FROM rust:slim-buster AS flatc +ARG flatbuffers_version="v1.12.0" RUN apt-get update \ && mkdir -p /usr/share/man/man1 \ && apt-get install -y \ git make clang cmake llvm \ --no-install-recommends \ - && git clone -b v1.12.0 -- https://github.com/google/flatbuffers.git /usr/local/src/flatbuffers \ + && git clone -b ${flatbuffers_version} -- https://github.com/google/flatbuffers.git /usr/local/src/flatbuffers \ && cmake -S /usr/local/src/flatbuffers -B /usr/local/src/flatbuffers \ -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=Release \ diff --git a/docker/Dockerfile.ci.dockerignore b/docker/Dockerfile.ci.dockerignore new file mode 100644 index 0000000000..484eb504cc --- /dev/null +++ b/docker/Dockerfile.ci.dockerignore @@ -0,0 +1,2 @@ +# Ignore everything +** diff --git a/.dockerignore b/docker/Dockerfile.iox.dockerignore similarity index 100% rename from .dockerignore rename to docker/Dockerfile.iox.dockerignore