Skip to content

Commit 507a6e3

Browse files
authored
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
1 parent d480428 commit 507a6e3

File tree

2 files changed

+53
-41
lines changed

2 files changed

+53
-41
lines changed

.github/workflows/tests.yml

+27-6
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ jobs:
243243
- name: Set up Docker Buildx
244244
uses: docker/setup-buildx-action@v1
245245

246+
- name: Cache Docker layers
247+
uses: actions/cache@v2
248+
with:
249+
path: /tmp/.buildx-cache
250+
key: ${{ runner.os }}-buildx-${{ github.sha }}
251+
restore-keys: |
252+
${{ runner.os }}-buildx-
253+
246254
- name: Build
247255
id: docker_build
248256
uses: docker/build-push-action@v2
@@ -251,11 +259,17 @@ jobs:
251259
file: ./Dockerfile
252260
push: false
253261
tags: av1an:action
254-
cache-from: type=gha
255-
cache-to: type=gha, mode=max
262+
cache-from: type=local,src=/tmp/.buildx-cache
263+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
264+
265+
- name: Move cache
266+
# Temp fix
267+
# https://github.com/docker/build-push-action/issues/252
268+
# https://github.com/moby/buildkit/issues/1896
269+
run: |
270+
rm -rf /tmp/.buildx-cache
271+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
256272
257-
- name: Image digest
258-
run: echo ${{ steps.docker_build.outputs.digest }}
259273
260274
docker-publish:
261275
needs: [all-tests, docker]
@@ -284,6 +298,14 @@ jobs:
284298
username: ${{ secrets.DOCKERHUB_USERNAME }}
285299
password: ${{ secrets.DOCKERHUB_TOKEN }}
286300

301+
- name: Cache Docker layers
302+
uses: actions/cache@v2
303+
with:
304+
path: /tmp/.buildx-cache
305+
key: ${{ runner.os }}-buildx-${{ github.sha }}
306+
restore-keys: |
307+
${{ runner.os }}-buildx-
308+
287309
- name: Build and push
288310
id: docker_build
289311
uses: docker/build-push-action@v2
@@ -293,8 +315,7 @@ jobs:
293315
push: true
294316
tags: ${{ steps.docker_meta.outputs.tags }}
295317
labels: ${{ steps.docker_meta.outputs.labels }}
296-
cache-from: type=gha
297-
cache-to: type=gha,mode=max
318+
cache-from: type=local,src=/tmp/.buildx-cache
298319

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

Dockerfile

+26-35
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,57 @@
1-
FROM archlinux:base-devel AS planner
2-
RUN pacman -Syy --noconfirm
1+
FROM archlinux:base-devel AS base
32

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

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

128

9+
FROM base AS build-base
1310

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

15-
FROM archlinux:base-devel AS cacher
16-
RUN pacman -Syy --noconfirm
14+
RUN cargo install cargo-chef
15+
WORKDIR /tmp/Av1an
1716

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

21-
WORKDIR /tmp/Av1an
22-
RUN cargo install cargo-chef
23-
COPY --from=planner /tmp/Av1an/recipe.json recipe.json
24-
RUN cargo chef cook --release --recipe-path recipe.json
18+
FROM build-base AS planner
2519

20+
COPY . .
21+
RUN cargo chef prepare --recipe-path recipe.json
2622

2723

24+
FROM build-base AS cacher
2825

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

31-
RUN pacman -Syy --noconfirm
3229

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

3632
# Compile rav1e from git, as archlinux is still on rav1e 0.4
37-
RUN git clone https://github.com/xiph/rav1e /tmp/rav1e
38-
WORKDIR /tmp/rav1e
39-
RUN cargo build --release && \
40-
strip ./target/release/rav1e
41-
RUN mv ./target/release/rav1e /usr/local/bin
33+
RUN git clone https://github.com/xiph/rav1e && \
34+
cd rav1e && \
35+
cargo build --release && \
36+
strip ./target/release/rav1e && \
37+
mv ./target/release/rav1e /usr/local/bin && \
38+
cd .. && rm -rf ./rav1e
4239

4340
# Build av1an
4441
COPY . /tmp/Av1an
4542

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

49-
WORKDIR /tmp/Av1an
50-
RUN cargo build --release
51-
RUN mv ./target/release/av1an /usr/local/bin
52-
46+
RUN cargo build --release && \
47+
mv ./target/release/av1an /usr/local/bin && \
48+
cd .. && rm -rf ./Av1an
5349

5450

55-
FROM archlinux:base-devel AS runtime
51+
FROM base AS runtime
5652

5753
ENV MPLCONFIGDIR="/home/app_user/"
5854

59-
RUN pacman -Syy --noconfirm
60-
61-
# Install all optional dependencies (except for rav1e)
62-
RUN pacman -S --noconfirm aom ffmpeg vapoursynth ffms2 libvpx mkvtoolnix-cli svt-av1 vapoursynth-plugin-lsmashsource vmaf
63-
6455
COPY --from=build /usr/local/bin/rav1e /usr/local/bin/rav1e
6556
COPY --from=build /usr/local/bin/av1an /usr/local/bin/av1an
6657

0 commit comments

Comments
 (0)