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

Use github cache action instead of using gha. Dedupe Dockerfile #594

Merged
merged 3 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Build
id: docker_build
uses: docker/build-push-action@v2
Expand All @@ -251,11 +259,17 @@ jobs:
file: ./Dockerfile
push: false
tags: av1an:action
cache-from: type=gha
cache-to: type=gha, mode=max
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Move cache
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

docker-publish:
needs: [all-tests, docker]
Expand Down Expand Up @@ -284,6 +298,14 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
Expand All @@ -293,8 +315,7 @@ jobs:
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: type=local,src=/tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
61 changes: 26 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,66 +1,57 @@
FROM archlinux:base-devel AS planner
RUN pacman -Syy --noconfirm
FROM archlinux:base-devel AS base

# Install all dependencies (except for rav1e)
RUN pacman -S --noconfirm rsync rust clang nasm git aom ffmpeg vapoursynth ffms2 libvpx mkvtoolnix-cli svt-av1 vapoursynth-plugin-lsmashsource vmaf
RUN pacman -Syy --noconfirm

WORKDIR /tmp/Av1an
RUN cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# Install dependancies needed by all steps including runtime step
RUN pacman -S --noconfirm aom ffmpeg vapoursynth ffms2 libvpx mkvtoolnix-cli svt-av1 vapoursynth-plugin-lsmashsource vmaf


FROM base AS build-base

# Install dependancies needed by build steps
RUN pacman -S --noconfirm rust clang nasm git

FROM archlinux:base-devel AS cacher
RUN pacman -Syy --noconfirm
RUN cargo install cargo-chef
WORKDIR /tmp/Av1an

# Install all dependencies (except for rav1e)
RUN pacman -S --noconfirm rsync rust clang nasm git aom ffmpeg vapoursynth ffms2 libvpx mkvtoolnix-cli svt-av1 vapoursynth-plugin-lsmashsource vmaf

WORKDIR /tmp/Av1an
RUN cargo install cargo-chef
COPY --from=planner /tmp/Av1an/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
FROM build-base AS planner

COPY . .
RUN cargo chef prepare --recipe-path recipe.json


FROM build-base AS cacher

FROM archlinux:base-devel AS build
COPY --from=planner /tmp/Av1an/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json

RUN pacman -Syy --noconfirm

# Install all dependencies (except for rav1e)
RUN pacman -S --noconfirm rsync rust clang nasm git aom ffmpeg vapoursynth ffms2 libvpx mkvtoolnix-cli svt-av1 vapoursynth-plugin-lsmashsource vmaf
FROM build-base AS build

# Compile rav1e from git, as archlinux is still on rav1e 0.4
RUN git clone https://github.com/xiph/rav1e /tmp/rav1e
WORKDIR /tmp/rav1e
RUN cargo build --release && \
strip ./target/release/rav1e
RUN mv ./target/release/rav1e /usr/local/bin
RUN git clone https://github.com/xiph/rav1e && \
cd rav1e && \
cargo build --release && \
strip ./target/release/rav1e && \
mv ./target/release/rav1e /usr/local/bin && \
cd .. && rm -rf ./rav1e

# Build av1an
COPY . /tmp/Av1an

# Copy over the cached dependencies
COPY --from=cacher /tmp/Av1an/target /tmp/Av1an/target

WORKDIR /tmp/Av1an
RUN cargo build --release
RUN mv ./target/release/av1an /usr/local/bin

RUN cargo build --release && \
mv ./target/release/av1an /usr/local/bin && \
cd .. && rm -rf ./Av1an


FROM archlinux:base-devel AS runtime
FROM base AS runtime

ENV MPLCONFIGDIR="/home/app_user/"

RUN pacman -Syy --noconfirm

# Install all optional dependencies (except for rav1e)
RUN pacman -S --noconfirm aom ffmpeg vapoursynth ffms2 libvpx mkvtoolnix-cli svt-av1 vapoursynth-plugin-lsmashsource vmaf

COPY --from=build /usr/local/bin/rav1e /usr/local/bin/rav1e
COPY --from=build /usr/local/bin/av1an /usr/local/bin/av1an

Expand Down