Compare commits

...

5 commits

Author SHA1 Message Date
Jonas Zohren
935e38c323 docker: This might work some day... 2024-01-17 22:06:57 +00:00
Jonas Zohren
1303d90507 ci: Attempts to improve caching 2023-10-20 11:11:45 +02:00
Jonas Zohren
531e706725 do not build for arm32 aka armv7 and use newer rust for sparse registry 2023-10-18 13:45:05 +00:00
Jonas Zohren
8fe42115a6 ci: Update some docker settings 2023-10-18 13:10:36 +00:00
Jonas Zohren
3b999ce82a ci: Test docker build on fsinfo runner 2023-10-18 12:24:45 +00:00
2 changed files with 103 additions and 81 deletions

View file

@ -17,28 +17,39 @@ variables:
.docker-shared-settings: .docker-shared-settings:
stage: "build docker image" stage: "build docker image"
needs: [] needs: []
tags: [ "docker" ] tags: [ "docker", "tudo-fsinfo" ]
variables: variables:
# Docker in Docker: # Docker in Docker:
DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 1
DOCKER_TLS_CERTDIR: "/certs"
image: image:
name: docker.io/docker name: docker.io/docker
services: services:
- name: docker.io/docker:dind - name: docker.io/docker:dind
alias: docker alias: docker
script: script:
- apk add openssh-client - free -h; lscpu || true
- eval $(ssh-agent -s) - docker context create ci-context
- mkdir -p ~/.ssh && chmod 700 ~/.ssh - >
- printf "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config docker buildx create
- sh .gitlab/setup-buildx-remote-builders.sh --name "multi"
--driver "docker-container"
--platform "linux/arm64,linux/amd64"
--use ci-context
# Authorize against this project's own image registry: # Authorize against this project's own image registry:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Build multiplatform image and push to temporary tag: # Build multiplatform image and push to temporary tag:
- > - >
docker buildx build docker buildx build
--platform "linux/arm/v7,linux/arm64,linux/amd64" --platform "linux/arm64,linux/amd64"
--pull --pull
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/$TAG"
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/matrix-conduit:next"
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/temporary-ci-images:buildkit-cache-$CI_COMMIT_REF_NAME"
--cache-to="type=registry,mode=max,compression=zstd,ref=$CI_REGISTRY_IMAGE/temporary-ci-images:buildkit-cache-$CI_COMMIT_REF_NAME"
--cache-to type=local,mode=max,dest=path/tmp/conduit-docker-buildcache
--cache-from type=local,src=path/tmp/conduit-docker-buildcache
--ulimit nofile=2048
--tag "$CI_REGISTRY_IMAGE/temporary-ci-images:$CI_JOB_ID" --tag "$CI_REGISTRY_IMAGE/temporary-ci-images:$CI_JOB_ID"
--push --push
--provenance=false --provenance=false
@ -46,7 +57,13 @@ variables:
# Build multiplatform image to deb stage and extract their .deb files: # Build multiplatform image to deb stage and extract their .deb files:
- > - >
docker buildx build docker buildx build
--platform "linux/arm/v7,linux/arm64,linux/amd64" --platform "linux/arm64,linux/amd64"
--pull
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/$TAG"
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/matrix-conduit:next"
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/temporary-ci-images:buildkit-cache-$CI_COMMIT_REF_NAME"
--cache-from type=local,src=path/tmp/conduit-docker-buildcache
--ulimit nofile=2048
--target "packager-result" --target "packager-result"
--output="type=local,dest=/tmp/build-output" --output="type=local,dest=/tmp/build-output"
--provenance=false --provenance=false
@ -54,7 +71,13 @@ variables:
# Build multiplatform image to binary stage and extract their binaries: # Build multiplatform image to binary stage and extract their binaries:
- > - >
docker buildx build docker buildx build
--platform "linux/arm/v7,linux/arm64,linux/amd64" --platform "linux/arm64,linux/amd64"
--pull
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/$TAG"
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/matrix-conduit:next"
--cache-from="type=registry,ref=$CI_REGISTRY_IMAGE/temporary-ci-images:buildkit-cache-$CI_COMMIT_REF_NAME"
--cache-from type=local,src=path/tmp/conduit-docker-buildcache
--ulimit nofile=2048
--target "builder-result" --target "builder-result"
--output="type=local,dest=/tmp/build-output" --output="type=local,dest=/tmp/build-output"
--provenance=false --provenance=false
@ -102,7 +125,6 @@ docker:tags:
variables: variables:
TAG: "matrix-conduit:$CI_COMMIT_TAG" TAG: "matrix-conduit:$CI_COMMIT_TAG"
docker build debugging: docker build debugging:
extends: .docker-shared-settings extends: .docker-shared-settings
rules: rules:
@ -116,7 +138,7 @@ docker build debugging:
cargo check: cargo check:
stage: test stage: test
image: docker.io/rust:1.70.0-bullseye image: docker.io/rust:1.73.0-bullseye
needs: [] needs: []
interruptible: true interruptible: true
before_script: before_script:

View file

@ -1,81 +1,79 @@
# syntax=docker/dockerfile:1 # Platforms might be linux/amd64, linux/arm64
FROM docker.io/rust:1.70-bullseye AS base
FROM base AS builder FROM --platform=$BUILDPLATFORM docker.io/rust:1.75-bookworm AS builder
WORKDIR /usr/src/conduit
# Install required packages to build Conduit and it's dependencies
RUN apt-get update && \ RUN apt-get update && \
apt-get -y --no-install-recommends install libclang-dev=1:11.0-51+nmu5 apt-get -y --no-install-recommends install libclang-dev
# == Build dependencies without our own code separately for caching == # Install Zig
# ARG ZIG_VERSION=0.11.0
# Need a fake main.rs since Cargo refuses to build anything otherwise. RUN curl -L "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz" | tar -J -x -C /usr/local && \
# ln -s "/usr/local/zig-linux-$(uname -m)-${ZIG_VERSION}/zig" /usr/local/bin/zig
# See https://github.com/rust-lang/cargo/issues/2644 for a Cargo feature
# request that would allow just dependencies to be compiled, presumably ARG TARGETARCH
# regardless of whether source files are available.
RUN mkdir src && touch src/lib.rs && echo 'fn main() {}' > src/main.rs # Install zigbuild
COPY Cargo.toml Cargo.lock ./ RUN cargo install cargo-zigbuild
RUN cargo build --release && rm -r src
RUN <<EOL
case $TARGETARCH in \
(amd64) rustarch="x86_64-unknown-linux-gnu";; \
(arm64) rustarch="aarch64-unknown-linux-gnu";; \
(arm) rustarch="armv7-unknown-linux-gnueabihf";; \
esac
echo "$TARGETARCH"
rustup target add "$rustarch"
EOL
## # == Build dependencies without our own code separately for caching ==
## #
## # Need a fake main.rs since Cargo refuses to build anything otherwise.
## #
## # See https://github.com/rust-lang/cargo/issues/2644 for a Cargo feature
## # request that would allow just dependencies to be compiled, presumably
## # regardless of whether source files are available.
## COPY Cargo.toml Cargo.lock ./
##
## RUN <<EOL
## case $TARGETARCH in \
## (amd64) rustarch="x86_64-unknown-linux-gnu";; \
## (arm64) rustarch="aarch64-unknown-linux-gnu";; \
## (arm) rustarch="armv7-unknown-linux-gnueabihf";; \
## esac
##
## mkdir src && touch src/lib.rs && echo 'fn main() {}' > src/main.rs
## cargo zigbuild --target --release "$rustarch"
## rm -r src
## EOL
# Copy over actual Conduit sources # Copy over actual Conduit sources
COPY Cargo.toml Cargo.lock ./
COPY src src COPY src src
# main.rs and lib.rs need their timestamp updated for this to work correctly since # main.rs and lib.rs need their timestamp updated for this to work correctly since
# otherwise the build with the fake main.rs from above is newer than the # otherwise the build with the fake main.rs from above is newer than the
# source files (COPY preserves timestamps). # source files (COPY preserves timestamps).
# #
# Builds conduit and places the binary at /usr/src/conduit/target/release/conduit # Builds conduit and places the binary at /conduit
RUN touch src/main.rs && touch src/lib.rs && cargo build --release RUN <<EOL
case $TARGETARCH in \
(amd64) rustarch="x86_64-unknown-linux-gnu";; \
(arm64) rustarch="aarch64-unknown-linux-gnu";; \
(arm) rustarch="armv7-unknown-linux-gnueabihf";; \
esac
touch src/main.rs
# ONLY USEFUL FOR CI: target stage to extract build artifacts touch src/lib.rs
FROM scratch AS builder-result cargo zigbuild --release --target "$rustarch"
COPY --from=builder /usr/src/conduit/target/release/conduit /conduit mv "target/$rustarch/debug/conduit" /conduit
EOL
# ---------------------------------------------------------------------------------------------------------------
# Build cargo-deb, a tool to package up rust binaries into .deb packages for Debian/Ubuntu based systems:
# ---------------------------------------------------------------------------------------------------------------
FROM base AS build-cargo-deb
RUN apt-get update && \ # On the target arch:
apt-get install -y --no-install-recommends \ FROM docker.io/debian:bookworm-slim AS runtime
dpkg \
dpkg-dev \
liblzma-dev
RUN cargo install cargo-deb
# => binary is in /usr/local/cargo/bin/cargo-deb
# ---------------------------------------------------------------------------------------------------------------
# Package conduit build-result into a .deb package:
# ---------------------------------------------------------------------------------------------------------------
FROM builder AS packager
WORKDIR /usr/src/conduit
COPY ./LICENSE ./LICENSE
COPY ./README.md ./README.md
COPY debian ./debian
COPY --from=build-cargo-deb /usr/local/cargo/bin/cargo-deb /usr/local/cargo/bin/cargo-deb
# --no-build makes cargo-deb reuse already compiled project
RUN cargo deb --no-build
# => Package is in /usr/src/conduit/target/debian/<project_name>_<version>_<arch>.deb
# ONLY USEFUL FOR CI: target stage to extract build artifacts
FROM scratch AS packager-result
COPY --from=packager /usr/src/conduit/target/debian/*.deb /conduit.deb
# ---------------------------------------------------------------------------------------------------------------
# Stuff below this line actually ends up in the resulting docker image
# ---------------------------------------------------------------------------------------------------------------
FROM docker.io/debian:bullseye-slim AS runner
# Standard port on which Conduit launches. # Standard port on which Conduit launches.
# You still need to map the port when using the docker command or docker-compose. # You still need to map the port when using the docker command or docker-compose.
@ -89,24 +87,19 @@ ENV CONDUIT_PORT=6167 \
CONDUIT_CONFIG='' CONDUIT_CONFIG=''
# └─> Set no config file to do all configuration with env vars # └─> Set no config file to do all configuration with env vars
# Test if Conduit is still alive, uses the same endpoint as Element
COPY ./docker/healthcheck.sh /srv/conduit/healthcheck.sh
HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
# Conduit needs: # Conduit needs:
# dpkg: to install conduit.deb
# ca-certificates: for https # ca-certificates: for https
# iproute2 & wget: for the healthcheck script # iproute2 & wget: for the healthcheck script
RUN apt-get update && apt-get -y --no-install-recommends install \ RUN apt-get update && apt-get -y --no-install-recommends install \
dpkg \
ca-certificates \ ca-certificates \
iproute2 \ iproute2 \
wget \ wget \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Test if Conduit is still alive, uses the same endpoint as Element
COPY ./docker/healthcheck.sh /srv/conduit/healthcheck.sh
HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
# Install conduit.deb:
COPY --from=packager /usr/src/conduit/target/debian/*.deb /srv/conduit/
RUN dpkg -i /srv/conduit/*.deb
# Improve security: Don't run stuff as root, that does not need to run as root # Improve security: Don't run stuff as root, that does not need to run as root
# Most distros also use 1000:1000 for the first real user, so this should resolve volume mounting problems. # Most distros also use 1000:1000 for the first real user, so this should resolve volume mounting problems.
@ -130,3 +123,10 @@ WORKDIR /srv/conduit
# Run Conduit and print backtraces on panics # Run Conduit and print backtraces on panics
ENV RUST_BACKTRACE=1 ENV RUST_BACKTRACE=1
ENTRYPOINT [ "/usr/sbin/matrix-conduit" ] ENTRYPOINT [ "/usr/sbin/matrix-conduit" ]
FROM runtime AS final
# Actually copy over conduit binary
COPY --from=builder /conduit /usr/sbin/matrix-conduit