Skip to content

Commit

Permalink
Cache docker build using registry cache.
Browse files Browse the repository at this point in the history
Use clang-16.
  • Loading branch information
sobomax committed Jul 25, 2024
1 parent 14d5eff commit 1b33894
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 55 deletions.
69 changes: 47 additions & 22 deletions .github/workflows/rtpproxy_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,18 @@ jobs:
if: needs.LoadJobs_conf.outputs.do_Docker == 'true' &&
(github.event_name == 'push' || github.event_name == 'pull_request')
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
env:
CLANG_VER: 16
DOCKER_REPO: sippylabs/rtpproxy
PLATFORMS: linux/amd64 #,linux/i386,linux/arm/v7,linux/arm64
LOCAL_REPO: localhost:5000/sippylabs/rtpproxy
PLATFORMS: linux/amd64,linux/i386,linux/arm/v7,linux/arm64
BASE_IMAGE: debian:12-slim
CCACHE_ROOT: ccache
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -416,6 +424,8 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host

- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
Expand All @@ -437,34 +447,55 @@ jobs:
type=raw,value=latest,enable={{is_default_branch}}
type=sha
# Cache the compiler cache
- name: Cache the compiler cache
uses: actions/cache@v4
with:
path: ccache
key: dockerhub-ccache-${{ github.run_id }}
restore-keys: |
dockerhub-ccache
- name: Get branch name
run: |
GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_ENV
CCACHE_IMAGE="${{ env.DOCKER_REPO }}:${GIT_BRANCH}-cccache-clang-${{ env.CLANG_VER }}"
if ! docker image inspect ${CCACHE_IMAGE} 2>&1 >/dev/null
then
CCACHE_BIMAGE="scratch"
else
CCACHE_BIMAGE="${CCACHE_IMAGE}"
fi
echo "CCACHE_IMAGE=${CCACHE_IMAGE}" >> $GITHUB_ENV
echo "CCACHE_BIMAGE=${CCACHE_BIMAGE}" >> $GITHUB_ENV
- name: Build Docker image
uses: docker/build-push-action@v6
env:
CACHE_SPEC: "type=registry,ref=${{ env.DOCKER_REPO }}:${{ env.GIT_BRANCH }}-buildcache"
with:
context: .
file: ./docker/Dockerfile
build-args: BASE_IMAGE=${{ env.BASE_IMAGE }}
tags: |
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
CLANG_VER=${{ env.CLANG_VER }}
BASE_IMAGE=${{ env.BASE_IMAGE }}
CCACHE_IMAGE=${{ env.CCACHE_BIMAGE }}
CCACHE_ROOT=${{ env.CCACHE_ROOT }}
tags: ${{ env.LOCAL_REPO }}:latest
platforms: ${{ env.PLATFORMS }}
push: true
cache-from: ${{ env.CACHE_SPEC }}
cache-to: ${{ env.CACHE_SPEC }},mode=max

- name: Export ccache
uses: docker/build-push-action@v6
with:
file: ./docker/Dockerfile.export_ccache
build-args: BUILD_IMAGE=${{ env.LOCAL_REPO }}:latest
tags: ${{ env.CCACHE_IMAGE }}
platforms: ${{ env.PLATFORMS }}
outputs: type=tar,dest=/tmp/ccache_export.tar
push: true

- name: Push Docker image
if: false
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile.push
build-args: BASE_IMAGE=${{ env.BASE_IMAGE }}
build-args: |
BASE_IMAGE=${{ env.BASE_IMAGE }}
BUILD_IMAGE=${{ env.LOCAL_REPO }}:latest
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand All @@ -476,9 +507,3 @@ jobs:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: sh -x docker/update_description.sh docker/README.md

- name: Extract ccaches
run: |
rm -rf ccache
tar --strip-components=2 --no-wildcards-match-slash --wildcards -x -f /tmp/ccache_export.tar "*/rtpproxy/ccache"
du -d1 -h ccache
30 changes: 26 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
# syntax=docker/dockerfile:1.7-labs

ARG BASE_IMAGE
FROM --platform=$TARGETPLATFORM $BASE_IMAGE as build
ARG CCACHE_IMAGE=scratch
FROM ${BASE_IMAGE} AS build
RUN mkdir -p /rtpproxy/ccache
FROM ${CCACHE_IMAGE} AS ccache
COPY --from=build /rtpproxy/ccache/ /rtpproxy/ccache/
FROM build
LABEL maintainer="Maksym Sobolyev <[email protected]>"

USER root

# Set Environment Variables
ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Build & install everything
ARG LIB_DEPS="libsrtp2-1 libbcg729-0 libgsm1 libsndfile1 libunwind8 libssl3"
ARG CLANG_VER=15
ARG BUILD_DEPS="file pkg-config clang-${CLANG_VER} llvm-${CLANG_VER} ccache git make \
libsrtp2-dev libbcg729-dev libgsm1-dev libsndfile1-dev \
libunwind-dev libssl-dev"

WORKDIR /tmp
ARG APT_INSTALL="apt-get install --no-install-recommends -y"
COPY docker/install_depends.sh /tmp
RUN ./install_depends.sh

COPY --exclude=.git* --link . /rtpproxy/

ARG CCACHE_ROOT

WORKDIR /rtpproxy
COPY . /rtpproxy/

# Build & install everything
COPY --from=ccache /rtpproxy/ccache /rtpproxy/ccache
RUN /rtpproxy/docker/build.sh
RUN ls -l /usr/local/bin/rtpproxy*
RUN ls -l /usr/local/bin/makeann*
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile.export_ccache
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG BUILD_IMAGE
FROM ${BUILD_IMAGE} AS build
FROM scratch
COPY --from=build /rtpproxy/ccache /rtpproxy/ccache
20 changes: 7 additions & 13 deletions docker/Dockerfile.push
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
# syntax=docker/dockerfile:1.7-labs

ARG BASE_IMAGE
FROM --platform=$TARGETPLATFORM $BASE_IMAGE as build
ARG BUILD_IMAGE
FROM $BUILD_IMAGE AS build
RUN rm -rf /rtpproxy && rm -rf /var/cache/*
FROM $BASE_IMAGE
LABEL maintainer="Maksym Sobolyev <[email protected]>"

USER root

# Set Environment Variables
ENV DEBIAN_FRONTEND noninteractive

WORKDIR /rtpproxy
COPY . /rtpproxy/

#install basic components
RUN /rtpproxy/docker/build.sh
RUN ls -l /usr/local/bin/rtpproxy*
RUN ls -l /usr/local/bin/makeann*
RUN ls -l /usr/local/lib/*rtpproxy*
ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /
RUN rm -rf /rtpproxy && rm -rf /var/cache/*

FROM --platform=$TARGETPLATFORM $BASE_IMAGE
COPY --from=build / /

ENTRYPOINT ["/usr/local/bin/rtpproxy", "-fF"]
27 changes: 11 additions & 16 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ set -x
MYPATH="`realpath "${0}"`"
RTPDIR="`dirname "${MYPATH}"`/.."

LIB_DEPS="libsrtp2-1 libbcg729-0 libgsm1 libsndfile1 libunwind8 libssl3"

BUILD_DEPS="file pkg-config clang-15 ccache git make \
libsrtp2-dev libbcg729-dev libgsm1-dev libsndfile1-dev \
libunwind-dev libssl-dev"

apt-get -y update -qq

apt-get -y install ${LIB_DEPS} ${BUILD_DEPS}

CONFIGURE_ARGS="--enable-librtpproxy"
ARCH="`dpkg --print-architecture`"

Expand All @@ -26,7 +16,8 @@ fi

cd "${RTPDIR}"

CCACHE_ROOT="${RTPDIR}/ccache"
_CCACHE_ROOT="${CCACHE_ROOT:-"${RTPDIR}/ccache"}"
CCACHE_ROOT="`realpath "${_CCACHE_ROOT}"`"
export PATH="/usr/lib/ccache:${PATH}"
export CCACHE_DIR="${CCACHE_ROOT}/${ARCH}"
if [ ! -e "${CCACHE_DIR}" ]
Expand All @@ -47,12 +38,16 @@ ccache --set-config=sloppiness=file_macro
ccache --cleanup
ccache --zero-stats

CC=clang-15 AR=llvm-ar-15 RANLIB=llvm-ranlib-15 NM=llvm-nm-15 \
STRIP=llvm-strip-15 CFLAGS="-O3 -pipe" ./configure ${CONFIGURE_ARGS}
make all
CC=clang-${CLANG_VER} AR=llvm-ar-${CLANG_VER} RANLIB=llvm-ranlib-${CLANG_VER} \
NM=llvm-nm-${CLANG_VER} STRIP=llvm-strip-${CLANG_VER} CFLAGS="-O3 -pipe" \
./configure ${CONFIGURE_ARGS}
make -j8 all
make install

ccache --show-stats

apt-get -y remove ${BUILD_DEPS}
apt-get -y autoremove
apt-get -y remove --purge ${BUILD_DEPS}
apt-get -y autoremove --purge

find / -xdev -xtype l
find / -xdev -xtype l -delete
11 changes: 11 additions & 0 deletions docker/install_depends.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e
set -x

MYPATH="`realpath "${0}"`"
RTPDIR="`dirname "${MYPATH}"`/.."

apt-get -y update -qq

${APT_INSTALL} ${LIB_DEPS} ${BUILD_DEPS}

0 comments on commit 1b33894

Please sign in to comment.