Skip to content

Commit

Permalink
upgrade Dockerfile and fit videos within 1m (#129)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp authored Mar 27, 2023
1 parent 51ab376 commit 5b05ddd
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 41 deletions.
49 changes: 25 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# syntax=docker.io/docker/dockerfile:1@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
# syntax=docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb2724562a38360f4d6a7782a409b14

FROM --platform=$BUILDPLATFORM docker.io/whilp/buildifier@sha256:67da91fdddd40e9947153bc9157ab9103c141fcabcdbf646f040ba7a763bc531 AS buildifier
FROM --platform=$BUILDPLATFORM docker.io/library/ubuntu:20.04@sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322 AS ubuntu
FROM --platform=$BUILDPLATFORM docker.io/library/ubuntu@sha256:67211c14fa74f070d27cc59d69a7fa9aeff8e28ea118ef3babc295a0428a6d21 AS ubuntu

ARG BUILDOS
ARG BUILDARCH

FROM ubuntu AS base
WORKDIR /app
Expand All @@ -17,6 +19,7 @@ RUN \
set -ux \
&& apt update \
&& apt install -y --no-install-recommends \
bc \
build-essential \
ca-certificates \
clang \
Expand All @@ -25,47 +28,43 @@ RUN \
git \
gzip \
libgl1-mesa-dev \
python3 \
python-is-python3 \
python3-urllib3 \
software-properties-common \
tar \
unzip \
xauth \
xorg-dev \
xvfb \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN \
--mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
set -ux \
&& add-apt-repository -y ppa:openjdk-r/ppa \
&& apt update \
&& apt install -y --no-install-recommends \
openjdk-8-jdk
xvfb
COPY .bazelversion .
RUN \
--mount=type=cache,target=/root/.cache/bazel \
--mount=type=cache,target=/root/.cache/bazelisk \
set -ux \
&& mkdir /bazel \
&& curl -fsSLo /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/$(cat .bazelversion)/bazel-$(cat .bazelversion)-installer-linux-x86_64.sh" \
&& chmod +x /bazel/installer.sh \
&& /bazel/installer.sh \
&& rm /bazel/installer.sh
&& curl -#fsSLo /bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-$BUILDOS-$BUILDARCH \
&& chmod +x /bazelisk \
&& cd /usr/local/bin \
&& ln -s /bazelisk bazel \
&& bazel version
COPY . .

# buildifier
FROM base AS buildifier
RUN \
set -ux \
&& curl -#fsSLo /buildifier "https://github.com/bazelbuild/buildtools/releases/download/$(cat .bazelversion)/buildifier-$BUILDOS-$BUILDARCH" \
&& chmod +x /buildifier

# sync
FROM base AS sync-then-fmt
RUN \
--mount=type=cache,target=/root/.cache/bazel \
--mount=type=cache,target=/root/.cache/bazelisk \
set -ux \
&& bazel sync \
&& grep -v -F \"definition_information\": resolved.bzl >resolved.bzl~ \
&& mv resolved.bzl~ resolved.bzl
RUN \
# Ideally we'd be executing buildifier from within the context of its
# container but it turns out to need a shell:
#17 [sync-fmt 2/2] RUN --mount=from=sync-nofmt,source=/app/resolved.bzl,target=/resolved.bzl,readwrite /buildifier -lint=fix /resolved.bzl
#17 0.441 container_linux.go:367: starting container process caused: exec: "/bin/sh": stat /bin/sh: no such file or directory
#17 ERROR: executor failed running [/bin/sh -c /buildifier -lint=fix /resolved.bzl]: exit code: 1
--mount=from=buildifier,source=/buildifier,target=/buildifier \
set -ux \
&& /buildifier -lint=fix resolved.bzl
Expand All @@ -76,6 +75,7 @@ COPY --from=sync-then-fmt /app/resolved.bzl /
FROM base AS builder-clang
RUN \
--mount=type=cache,target=/root/.cache/bazel \
--mount=type=cache,target=/root/.cache/bazelisk \
set -ux \
&& bazel build voidstar --repo_env=CC=clang \
&& strip /app/bazel-bin/voidstar/voidstar \
Expand All @@ -86,6 +86,7 @@ RUN \
FROM base AS builder-gcc
RUN \
--mount=type=cache,target=/root/.cache/bazel \
--mount=type=cache,target=/root/.cache/bazelisk \
set -ux \
&& bazel build voidstar \
&& strip /app/bazel-bin/voidstar/voidstar \
Expand Down
53 changes: 40 additions & 13 deletions resolved.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ resolved = [
"rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository",
"attributes": {
"urls": [
"https://github.com/glfw/glfw/archive/c7a53338733fad040814fb5d6d9180921e7a107b.tar.gz",
"https://github.com/glfw/glfw/archive/4a33051456083a50cfe282bf50696bd8d667fbca.tar.gz",
],
"sha256": "b21a0711779aef4c9c8db12ee020c38ca36c97051133c9cc4d939f7aac414c7e",
"sha256": "fa82ad8eaeb4a30c51c7dfd0a64c83a0ec2e0efec45f24ebc56459a1e62cbff0",
"netrc": "",
"auth_patterns": {},
"canonical_id": "",
"strip_prefix": "glfw-c7a53338733fad040814fb5d6d9180921e7a107b",
"strip_prefix": "glfw-4a33051456083a50cfe282bf50696bd8d667fbca",
"type": "tar.gz",
"patches": [],
"patch_tool": "",
Expand All @@ -350,7 +350,7 @@ resolved = [
"tag": "",
"name": "glfw",
},
"output_tree_hash": "180790a01a167bd809bfe724088b9a73e95ffc055bf2c161064bfecb464b2eee",
"output_tree_hash": "1d9955f4567e3efa5f48f93ac293cc2e4e4a943ae9fd09007b9059c4eb00d97f",
},
],
},
Expand Down Expand Up @@ -450,13 +450,13 @@ resolved = [
"rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository",
"attributes": {
"urls": [
"https://github.com/KhronosGroup/OpenGL-Registry/archive/63161d674db04a96635c6ab300db793e83f6762c.tar.gz",
"https://github.com/KhronosGroup/OpenGL-Registry/archive/d127c3015a5429a5261b3bf464c9a07c00576048.tar.gz",
],
"sha256": "a06ad429b86d3ed4d5e0a1d3dca6bf35104c3f289ac58410ca855ed3ee61e1d7",
"sha256": "f3ca916a5ead08e6175543f4478ad5a3ec8eb300e7fc0095034e5a762d1a7aeb",
"netrc": "",
"auth_patterns": {},
"canonical_id": "",
"strip_prefix": "OpenGL-Registry-63161d674db04a96635c6ab300db793e83f6762c",
"strip_prefix": "OpenGL-Registry-d127c3015a5429a5261b3bf464c9a07c00576048",
"type": "tar.gz",
"patches": [],
"patch_tool": "",
Expand All @@ -474,7 +474,7 @@ resolved = [
"tag": "",
"name": "khronos_opengl_registry",
},
"output_tree_hash": "5984f251f3715f96ce043c457bb74c1b97dae112a136b12edc6ca916dc59d05b",
"output_tree_hash": "6694845719417e12cb272a74996618552c3f5fdda970c5531deafba401fa9979",
},
],
},
Expand Down Expand Up @@ -530,14 +530,14 @@ resolved = [
"rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository",
"attributes": {
"urls": [
"https://github.com/bazelbuild/rules_cc/archive/998319083bf25c9f1acdc2c73bc7cd099a151dff.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/998319083bf25c9f1acdc2c73bc7cd099a151dff.tar.gz",
"https://github.com/bazelbuild/rules_cc/archive/be9ff3eb412c5781eabd4a4b7b81de8b95da7b84.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/be9ff3eb412c5781eabd4a4b7b81de8b95da7b84.tar.gz",
],
"sha256": "c85b3d026bd66b8ba215145a8bd4cea7198f5ff122323984691d2b718d536a3c",
"sha256": "f5f6f86fe44c3fe1110d34611189c55c492d7ca3b350c4b84adb998167f7c636",
"netrc": "",
"auth_patterns": {},
"canonical_id": "",
"strip_prefix": "rules_cc-998319083bf25c9f1acdc2c73bc7cd099a151dff",
"strip_prefix": "rules_cc-be9ff3eb412c5781eabd4a4b7b81de8b95da7b84",
"type": "tar.gz",
"patches": [],
"patch_tool": "",
Expand Down Expand Up @@ -603,6 +603,33 @@ resolved = [
},
],
},
{
"original_rule_class": "@bazel_tools//tools/jdk:local_java_repository.bzl%_local_java_repository_rule",
"original_attributes": {
"name": "local_jdk",
"generator_name": "local_jdk",
"generator_function": "maybe",
"generator_location": None,
"java_home": "/root/.cache/bazel/_bazel_root/install/97c81a3bdd984debe0ff1b26c2dc04e0/embedded_tools/tools/jdk/nosystemjdk",
"version": "",
"build_file": "@bazel_tools//tools/jdk:jdk.BUILD",
},
"repositories": [
{
"rule_class": "@bazel_tools//tools/jdk:local_java_repository.bzl%_local_java_repository_rule",
"attributes": {
"name": "local_jdk",
"generator_name": "local_jdk",
"generator_function": "maybe",
"generator_location": None,
"java_home": "/root/.cache/bazel/_bazel_root/install/97c81a3bdd984debe0ff1b26c2dc04e0/embedded_tools/tools/jdk/nosystemjdk",
"version": "",
"build_file": "@bazel_tools//tools/jdk:jdk.BUILD",
},
"output_tree_hash": "b9a84448c35c3974e210e5efa7c1a8f9638b60c1d4fef278cb4622420aa47e28",
},
],
},
{
"original_rule_class": "@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
"original_attributes": {
Expand Down Expand Up @@ -2446,7 +2473,7 @@ resolved = [
"generator_function": "cc_configure",
"generator_location": None,
},
"output_tree_hash": "fe281f52cab4898d3a0ef8aef56579e634ad18625e25df9d50cdbe3fd2c84fb7",
"output_tree_hash": "36d471d158454cbf2b0f5f4bd21919324793edf25668839a1570d4c81d524b79",
},
],
},
Expand Down
19 changes: 15 additions & 4 deletions xvfb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ esac

step=1024
filesize=$(stat --printf=%s "$file")
[[ "$filesize" -ge 999999 ]] && ((step*=2))
[[ "$filesize" -ge 9999999 ]] && ((step*=2))
[[ "$filesize" -ge 99999999 ]] && ((step*=2))
[[ "$filesize" -ge 999999999 ]] && ((step*=2))
[[ "$filesize" -ge 9999999999 ]] && ((step*=2))
[[ "$filesize" -ge 999999999 ]] && ((step*=2))
[[ "$filesize" -ge 99999999 ]] && ((step*=2))
[[ "$filesize" -ge 9999999 ]] && ((step*=2))
[[ "$filesize" -ge 999999 ]] && ((step*=2))

rm -rf /tmp/xvfb-run.*

Expand Down Expand Up @@ -107,3 +107,14 @@ esac
wait $xvfb
echo q >stop # https://stackoverflow.com/a/21032143/1418165
wait $companion

max_seconds=60
# Must be shorter than $max_seconds
duration=$(ffprobe -v error -show_format -show_streams -i "$out" | grep 'duration=' | head -n 1 | sed 's%duration=%%')
if [[ "$(echo "$duration < $max_seconds" | bc)" = 0 ]]; then
ffmpeg \
-i "$out" \
-filter:v "setpts=PTS/$(echo "1 + $duration / $max_seconds" | bc)" \
/tmp/"$out"
mv -v /tmp/"$out" "$out"
fi

0 comments on commit 5b05ddd

Please sign in to comment.