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

* Action: Use local cache to speed up docker-publish

* Cleanup Dockerfile

* Dockerfile: Reduce duplication
This commit is contained in:
Luigi311 2022-03-15 19:52:27 -06:00 committed by GitHub
parent d480428fc6
commit 507a6e306f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 42 deletions

View file

@ -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
@ -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]
@ -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
@ -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 }}

View file

@ -1,44 +1,41 @@
FROM archlinux:base-devel AS planner
FROM archlinux:base-devel AS base
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
# 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
RUN cargo install cargo-chef
WORKDIR /tmp/Av1an
RUN cargo install cargo-chef
FROM build-base AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM build-base AS cacher
FROM archlinux:base-devel AS cacher
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
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 archlinux:base-devel AS build
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
@ -46,21 +43,15 @@ 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