Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Alpine static improved #1243

Merged
merged 9 commits into from
Oct 19, 2024
156 changes: 156 additions & 0 deletions .github/workflows/docker-alpine-improved.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# This is the Github action to build and push the gocv/opencv Docker images.
#
name: Docker
on:
push:
branches: [build-opencv-alpine, alpine-static-improved]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
gstreamer:
name: gstreamer
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check out the repo
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
gocv/gstreamer:1.24-alpine
ghcr.io/${{ github.repository_owner }}/gstreamer:1.24-alpine
tags: |
type=sha,format=long
type=raw,value=latest
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Log in to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: Dockerfile.gstreamer-static-alpine
platforms: linux/amd64,linux/arm64
context: .
push: true
tags: |
gocv/gstreamer:1.24-alpine
ghcr.io/${{ github.repository_owner }}/gstreamer:1.24-alpine
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

ffmpeg:
name: ffmpeg
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check out the repo
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
gocv/ffmpeg:5.16-alpine
ghcr.io/${{ github.repository_owner }}/ffmpeg:5.16-alpine
tags: |
type=sha,format=long
type=raw,value=latest
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Log in to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: Dockerfile.ffmpeg-static-alpine
platforms: linux/amd64,linux/arm64
context: .
push: true
tags: |
gocv/ffmpeg:5.16-alpine
ghcr.io/${{ github.repository_owner }}/ffmpeg:5.16-alpine
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

opencv:
name: opencv
runs-on: ubuntu-latest
needs: [gstreamer, ffmpeg]
permissions:
packages: write
contents: read
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check out the repo
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
gocv/opencv:4.10.0-alpine
ghcr.io/${{ github.repository_owner }}/opencv:4.10.0-alpine
tags: |
type=sha,format=long
type=raw,value=latest
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Log in to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: Dockerfile.opencv-static-alpine
platforms: linux/amd64,linux/arm64
context: .
push: true
tags: |
gocv/opencv:4.10.0-alpine
ghcr.io/${{ github.repository_owner }}/opencv:4.10.0-alpine
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
91 changes: 91 additions & 0 deletions .github/workflows/docker-alpine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This is the Github action to build and push the gocv/opencv Docker images.
#
name: Docker
on:
push:
branches: [build-opencv-alpine, alpine-static]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
opencv-static:
name: opencv-static
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Check disk space
run: df . -h
- name: Free disk space
run: |
sudo docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true
sudo rm -rf \
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
/usr/lib/jvm || true
echo "extra directories deleted"
sudo apt install aptitude -y >/dev/null 2>&1
sudo aptitude purge aria2 ansible azure-cli shellcheck rpm xorriso zsync \
esl-erlang firefox gfortran-8 gfortran-9 google-chrome-stable \
google-cloud-sdk imagemagick \
libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional kubectl \
mercurial apt-transport-https mono-complete libmysqlclient \
unixodbc-dev yarn chrpath libssl-dev libxft-dev \
libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev \
snmp pollinate libpq-dev postgresql-client powershell ruby-full \
sphinxsearch subversion mongodb-org azure-cli microsoft-edge-stable \
-y -f >/dev/null 2>&1
sudo aptitude purge google-cloud-sdk -f -y >/dev/null 2>&1
sudo aptitude purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true
sudo apt purge microsoft-edge-stable -f -y >/dev/null 2>&1 || true
sudo aptitude purge '~n ^mysql' -f -y >/dev/null 2>&1
sudo aptitude purge '~n ^php' -f -y >/dev/null 2>&1
sudo aptitude purge '~n ^dotnet' -f -y >/dev/null 2>&1
sudo apt-get autoremove -y >/dev/null 2>&1
sudo apt-get autoclean -y >/dev/null 2>&1
echo "extra packages purged"
- name: Check disk space
run: df . -h
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check out the repo
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
gocv/opencv:4.10.0-alpine
ghcr.io/${{ github.repository_owner }}/opencv:4.10.0-alpine
tags: |
type=sha,format=long
type=raw,value=latest
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Log in to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: Dockerfile.opencv-static-alpine
platforms: linux/amd64,linux/arm64
context: .
push: true
tags: |
gocv/opencv:4.10.0-alpine
ghcr.io/${{ github.repository_owner }}/opencv:4.10.0-alpine
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
136 changes: 136 additions & 0 deletions Dockerfile.ffmpeg-static-alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# syntax=docker/dockerfile:1.3

# To build release:
# docker buildx build -f Dockerfile.ffmpeg-static-alpine -t ghcr.io/hybridgroup/ffmpeg:5.16-alpine --platform=linux/arm64,linux/amd64 --load .

# linux/amd64 build
FROM --platform=linux/amd64 alpine:3.20 AS builder-amd64

WORKDIR /

ARG FFMPEG_VERSION=5.1.6
ARG XZ_VERSION=5.6.3

# download xz
RUN wget -O xz-${XZ_VERSION}.tar.bz2 "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.bz2" && \
tar -xf xz-${XZ_VERSION}.tar.bz2

# download bzip2
RUN wget -O bzip2-master.tar.bz2 "https://gitlab.com/bzip2/bzip2/-/archive/master/bzip2-master.tar.bz2" && \
tar -xf bzip2-master.tar.bz2

# download ffmpeg source
RUN wget -O ffmpeg-5.0.tar.bz2 "https://www.ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2" && \
tar -xf ffmpeg-5.0.tar.bz2

# Install dependencies
RUN apk update && apk add --no-cache \
build-base \
cmake \
git \
diffutils \
perl \
wget \
unzip \
pkgconfig \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev python3

# Build and install xz
RUN cd xz-${XZ_VERSION} && \
./configure --disable-shared && \
make && make install

# Build and install bzip2
RUN cd bzip2-master && \
mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE="Release" -DENABLE_STATIC_LIB=ON -DENABLE_LIB_ONLY=ON && \
cmake --build . --target install

# Build and install libvpx
RUN cd ffmpeg-${FFMPEG_VERSION} && \
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
./configure --enable-static --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
make -j $(nproc --all) && make install

# Now finish building ffmpeg
RUN cd ffmpeg-${FFMPEG_VERSION} && \
./configure --pkg-config-flags="--static" \
--enable-static --disable-shared --enable-gpl --enable-libx264 --enable-libvpx --enable-zlib \
--disable-sdl2 --disable-vaapi --disable-vdpau --disable-v4l2-m2m --disable-doc && \
make -j $(nproc --all) && make install


# linux/arm64 build
FROM --platform=linux/arm64 alpine:3.20 AS builder-arm64

WORKDIR /

ARG FFMPEG_VERSION=5.1.6
ARG XZ_VERSION=5.6.3

# download xz
RUN wget -O xz-${XZ_VERSION}.tar.bz2 "https://github.com/tukaani-project/xz/releases/download/v${XZ_VERSION}/xz-${XZ_VERSION}.tar.bz2" && \
tar -xf xz-${XZ_VERSION}.tar.bz2

# download bzip2
RUN wget -O bzip2-master.tar.bz2 "https://gitlab.com/bzip2/bzip2/-/archive/master/bzip2-master.tar.bz2" && \
tar -xf bzip2-master.tar.bz2

# download ffmpeg source
RUN wget -O ffmpeg-5.0.tar.bz2 "https://www.ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2" && \
tar -xf ffmpeg-5.0.tar.bz2

# Install dependencies
RUN apk update && apk add --no-cache \
build-base \
cmake \
git \
diffutils \
perl \
wget \
unzip \
pkgconfig \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
eigen-dev \
nasm yasm \
bzip2 xz zlib-dev x264-dev libvpx-dev \
opus-dev dav1d-dev python3

# Build and install xz
RUN cd xz-${XZ_VERSION} && \
./configure --disable-shared && \
make && make install

# Build and install bzip2
RUN cd bzip2-master && \
mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE="Release" -DENABLE_STATIC_LIB=ON -DENABLE_LIB_ONLY=ON && \
cmake --build . --target install

# Build and install libvpx
RUN cd ffmpeg-${FFMPEG_VERSION} && \
git -C libvpx pull 2> /dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git && \
cd libvpx && \
./configure --enable-static --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm && \
make -j $(nproc --all) && make install

# Now finish building ffmpeg
RUN cd ffmpeg-${FFMPEG_VERSION} && \
./configure --pkg-config-flags="--static" \
--enable-static --disable-shared --enable-gpl --enable-libx264 --enable-libvpx --enable-zlib \
--disable-sdl2 --disable-vaapi --disable-vdpau --disable-v4l2-m2m --disable-doc && \
make -j $(nproc --all) && make install

# Stage 2: Create final image
FROM builder-${TARGETARCH} AS final

CMD ["ffmpeg"]
Loading
Loading