chore: provide a single way to build prod IOx images

Closes #3310.
pull/24376/head
Marco Neumann 2021-12-06 15:11:28 +01:00
parent 1099f5c417
commit 1706bc94a0
5 changed files with 54 additions and 85 deletions

View File

@ -323,8 +323,10 @@ jobs:
# To change the contents of the build container, modify docker/Dockerfile.ci
# To change the final release container, modify docker/Dockerfile.iox
perf_image:
docker:
- image: quay.io/influxdb/rust:ci
# need a machine executor to have a full-powered docker daemon (the `setup_remote_docker` system just provides a
# kinda small node)
machine:
image: ubuntu-2004:202111-01
resource_class: xlarge # use of a smaller executor tends crashes on link
environment:
# Disable incremental compilation to avoid overhead. We are not preserving these files anyway.
@ -337,49 +339,27 @@ jobs:
RUSTFLAGS: "-C target-feature=+avx2"
steps:
- checkout
- rust_components
- cache_restore
- run:
name: Cargo release build with target arch set for CRoaring
command: cargo build --release --no-default-features --features="aws,gcp,azure,jemalloc_replacing_malloc"
# linking might take a while and doesn't produce CLI output
no_output_timeout: 20m
- run:
name: Compress debug symbols
command: objcopy --compress-debug-sections target/release/influxdb_iox
- run: |
echo "binary sha256sum after build is (not to be confused w/ the GIT SHA and the resulting image SHA!)"
sha256sum target/release/influxdb_iox
- run:
name: Print rustc target CPU options
command: target/release/influxdb_iox debug print-cpu
- setup_remote_docker:
# There seems to be a cache invalidation bug in docker
# or in the way that circleci implements layer caching.
# Disabling for now, and tracked further investigations
# in https://github.com/influxdata/k8s-idpe/issues/3038
docker_layer_caching: false
version: 20.10.7
- run: |
sudo apt-get update
sudo apt-get install -y docker.io
docker --version
- run: |
echo "$QUAY_INFLUXDB_IOX_PASS" | docker login quay.io --username $QUAY_INFLUXDB_IOX_USER --password-stdin
- run:
# Docker has functionality to support per-Dockerfile .dockerignore
# This was added in https://github.com/moby/buildkit/pull/901
# And included in 19.03 - https://docs.docker.com/engine/release-notes/19.03/#19030
# Unfortunately CircleCI only seems to understand a root-level .dockerignore
# So we need to move it into position for it to not send ~10GB of build context
name: Fudge CircleCI Docker Context
command: mv docker/Dockerfile.iox.dockerignore .dockerignore
- run: |
name: Cargo release build with target arch set for CRoaring
command: |
BRANCH=$(git rev-parse --abbrev-ref HEAD | tr '/' '.')
COMMIT_SHA=$(git rev-parse --short HEAD)
docker build -t quay.io/influxdb/iox:$COMMIT_SHA -t quay.io/influxdb/iox:main -f docker/Dockerfile.iox .
docker buildx build \
--build-arg RUSTFLAGS="-C target-feature=+avx2" \
--tag quay.io/influxdb/iox:$COMMIT_SHA \
--tag quay.io/influxdb/iox:main \
.
docker run -it --rm quay.io/influxdb/iox:$COMMIT_SHA debug print-cpu
docker push --all-tags quay.io/influxdb/iox
echo "export COMMIT_SHA=${COMMIT_SHA}" >> $BASH_ENV
# linking might take a while and doesn't produce CLI output
no_output_timeout: 20m
- run:
name: Deploy tags
command: |

View File

@ -1,30 +1,47 @@
#syntax=docker/dockerfile:1.2
FROM rust:1.56-slim-bullseye as build
ARG RUST_VERSION=1.57
FROM rust:${RUST_VERSION}-slim-bullseye as build
# cache mounts below may already exist and owned by root
USER root
RUN apt update \
&& apt install --yes build-essential pkg-config libssl-dev clang \
&& apt install --yes binutils build-essential pkg-config libssl-dev clang \
&& rm -rf /var/lib/{apt,dpkg,cache,log}
# Build influxdb_iox
COPY . /influxdb_iox
WORKDIR /influxdb_iox
ARG CARGO_INCREMENTAL=yes
ARG CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
ARG CARGO_PROFILE_RELEASE_LTO=thin
ARG FEATURES=aws,gcp,azure,jemalloc_replacing_malloc
ARG ROARING_ARCH="haswell"
ARG RUSTFLAGS=""
ENV CARGO_INCREMENTAL=$CARGO_INCREMENTAL \
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=$CARGO_PROFILE_RELEASE_CODEGEN_UNITS \
CARGO_PROFILE_RELEASE_LTO=$CARGO_PROFILE_RELEASE_LTO \
FEATURES=$FEATURES \
ROARING_ARCH=$ROARING_ARCH \
RUSTFLAGS=$RUSTFLAGS
RUN \
--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/cargo/registry /usr/local/cargo/git /influxdb_iox/target && \
cargo build --target-dir /influxdb_iox/target --release --no-default-features --features=aws,gcp,azure && \
cargo build --target-dir /influxdb_iox/target --release --no-default-features --features="$FEATURES" && \
objcopy --compress-debug-sections target/release/influxdb_iox && \
cp /influxdb_iox/target/release/influxdb_iox /root/influxdb_iox && \
du -cshx /usr/local/cargo/registry /usr/local/cargo/git /influxdb_iox/target
FROM debian:bullseye-slim
RUN apt update \
&& apt install --yes libssl1.1 ca-certificates --no-install-recommends \
&& apt install --yes ca-certificates gettext-base libssl1.1 --no-install-recommends \
&& rm -rf /var/lib/{apt,dpkg,cache,log}
RUN groupadd --gid 1500 iox \
@ -36,9 +53,12 @@ RUN mkdir ~/.influxdb_iox
RUN ls -la ~/.influxdb_iox
COPY --from=build /root/influxdb_iox /usr/bin/influxdb_iox
COPY docker/entrypoint.sh /usr/bin/entrypoint.sh
ENV INFLUXDB_IOX_SERVER_MODE=database
EXPOSE 8080 8082
ENTRYPOINT ["/usr/bin/influxdb_iox"]
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["run", "database"]
CMD ["run", "$INFLUXDB_IOX_SERVER_MODE"]

View File

@ -2,3 +2,4 @@
target/
tests/
docker/
!docker/entrypoint.sh

View File

@ -1,27 +0,0 @@
###
# Dockerfile used for deploying IOx
##
FROM debian:bullseye-slim
RUN apt-get update \
&& apt-get install -y libssl1.1 libgcc1 libc6 ca-certificates gettext-base --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
ENV INFLUXDB_IOX_SERVER_MODE=database
COPY docker/entrypoint.sh /usr/bin/entrypoint.sh
COPY target/release/influxdb_iox /usr/bin/influxdb_iox
EXPOSE 8080 8082
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["run", "$INFLUXDB_IOX_SERVER_MODE"]

View File

@ -1,5 +0,0 @@
# Ignore everything
**
# Except
!docker/entrypoint.sh
!target/release/influxdb_iox