Skip to content

Commit

Permalink
docker: Adjust Dockerfile to Aya
Browse files Browse the repository at this point in the history
After lockc-project#199 we don't have to use libbpf anymore. Since building stuff
with Rust locally is easy (and only rustup is required), it's also time
to get rid of dapper.

Signed-off-by: Michal Rostecki <[email protected]>
  • Loading branch information
vadorovsky committed May 15, 2022
1 parent d953e56 commit daa4133
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 70 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/container-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
- main
tags:
- "v*"
pull_request:
branches:
- main

name: build container image

Expand All @@ -24,6 +27,16 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container image
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v2
with:
context:
file: ./Dockerfile
platforms: linux/amd64
push: false
tags: |
ghcr.io/lockc-project/lockc:latest
- name: Build and push development container image
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v2
Expand Down
81 changes: 23 additions & 58 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,62 +1,27 @@
FROM registry.opensuse.org/opensuse/leap:15.3 as builder
# zypper ar -p 90 -r https://download.opensuse.org/repositories/devel:/languages:/rust/openSUSE_Leap_15.3/devel:languages:rust.repo
RUN zypper ar -p 90 -r https://download.opensuse.org/repositories/devel:/tools:/compiler/openSUSE_Leap_15.3/devel:tools:compiler.repo \
&& zypper --gpg-auto-import-keys ref \
&& zypper --non-interactive dup --allow-vendor-change
RUN zypper --non-interactive install -t pattern \
devel_C_C++ \
devel_basis \
&& zypper --non-interactive install \
clang \
curl \
libelf-devel \
libopenssl-devel \
llvm \
rustup \
sudo \
tar \
xz \
zlib-devel \
&& zypper clean
RUN rustup-init -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup toolchain install nightly
RUN rustup component add \
clippy \
rustfmt
RUN cargo install \
libbpf-cargo
RUN cargo +nightly install \
cargo-udeps
FROM rustlang/rust:nightly-bullseye as builder

FROM builder AS build
WORKDIR /usr/local/src
# Build bpftool from the newest stable kernel sources.
RUN curl -Lso linux.tar.xz \
$(curl -s https://www.kernel.org/ | grep -A1 "latest_link" | grep -Eo '(http|https)://[^"]+') \
&& tar -xf linux.tar.xz \
&& mv $(find . -maxdepth 1 -type d -name "linux*") linux \
&& cd linux \
&& cd tools/bpf/bpftool \
&& make -j $(nproc)
# Prepare lockc sources and build it.
WORKDIR /usr/local/src/lockc
COPY . ./
ARG profile=release
RUN apt-get update \
&& apt-get install -y software-properties-common \
&& wget https://apt.llvm.org/llvm-snapshot.gpg.key \
&& apt-key add llvm-snapshot.gpg.key \
&& rm -f llvm-snapshot.gpg.key \
&& add-apt-repository "deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-14 main" \
&& apt-get update \
&& apt-get install -y libssl-dev llvm-14-dev musl
RUN rustup component add rust-src
RUN rustup target add x86_64-unknown-linux-musl
RUN cargo install bpf-linker
COPY . /src
WORKDIR /src
RUN --mount=type=cache,target=/.root/cargo/registry \
--mount=type=cache,target=/usr/local/src/lockc/target \
if [[ "$profile" == "debug" ]]; then cargo build; else cargo build --profile ${profile}; fi \
&& cp target/${profile}/lockcd /usr/local/bin/lockcd
--mount=type=cache,target=/src/target \
cargo xtask build-ebpf --release \
&& cargo build --release --target=x86_64-unknown-linux-musl

FROM registry.opensuse.org/opensuse/leap:15.3 AS lockcd
FROM alpine:3.15
# runc links those libraries dynamically
RUN zypper --non-interactive install \
libseccomp2 \
libselinux1 \
&& zypper clean
ARG profile=release
# Install rust-gdb and rust-lldb for debug profile
RUN if [[ "$profile" == "debug" ]]; then zypper --non-interactive install gdb lldb python3-lldb rust; fi
COPY --from=build /usr/local/src/linux/tools/bpf/bpftool/bpftool /usr/sbin/bpftool
COPY --from=build /usr/local/bin/lockcd /usr/bin/lockcd
ENTRYPOINT ["/usr/bin/lockcd"]
RUN apk update \
&& apk add libseccomp \
libselinux
COPY --from=builder /src/target/x86_64-unknown-linux-musl/release/lockc /usr/sbin/
ENTRYPOINT [ "/usr/sbin/lockc" ]
12 changes: 0 additions & 12 deletions Dockerfile.dapper

This file was deleted.

0 comments on commit daa4133

Please sign in to comment.