Skip to content

Commit

Permalink
consolidate dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gael-connan-cybex committed Aug 21, 2024
1 parent cf96af0 commit ef3106d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 43 deletions.
29 changes: 12 additions & 17 deletions app/Jobs/TranscodeVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Storage;
use Streaming\FFMpeg;
use Streaming\Media as StreamingMedia;
use Streaming\Streaming;
use Throwable;
use Transcode;

Expand Down Expand Up @@ -151,15 +150,10 @@ protected function transcode(): void
\Log::info(sprintf('Downloading video for media %s and version %s.', $this->version->Media->identifier, $this->version->getKey()));
$video = $this->loadVideo($ffmpeg);

// Set the necessary file path information.
$this->setFilePaths();

// Generate MP4.
$this->generateMp4($video);
// Generate HLS
$this->saveVideo(StreamingFormat::HLS->configure($video, $this->encoder), StreamingFormat::HLS->value);
// Generate DASH
$this->saveVideo(StreamingFormat::DASH->configure($video, $this->encoder), StreamingFormat::DASH->value);
$this->saveVideo($video, StreamingFormat::HLS);
$this->saveVideo($video, StreamingFormat::DASH);

$this->localDisk->delete($this->tempOriginalFilename);
$this->localDisk->deleteDirectory($this->getFfmpegTempDirectory());
Expand Down Expand Up @@ -213,27 +207,28 @@ protected function setFilePaths(): void
/**
* Saves the transcoded video to storage.
*
* @param Streaming $video
* @param string $format
* @param StreamingMedia $media
* @param StreamingFormat $streamingFormat
*
* @return void
*/
protected function saveVideo(Streaming $video, string $format): void
protected function saveVideo(StreamingMedia $media, StreamingFormat $streamingFormat): void
{
$tempDerivativeFilePath = $this->getTempDerivativeFilePath($format);
$configuredMedia = $streamingFormat->configure($media, $this->encoder);
$tempDerivativeFilePath = $this->getTempDerivativeFilePath($streamingFormat->value);

\Log::info(sprintf('Generating %s for media %s and version %s. Using: %s -> %s', strtoupper($format), $this->version->Media->identifier, $this->version->getKey(), $this->decoder->name, $this->encoder->name));
\Log::info(sprintf('Generating %s for media %s and version %s. Using: %s -> %s', strtoupper($streamingFormat->value), $this->version->Media->identifier, $this->version->getKey(), $this->decoder->name, $this->encoder->name));
// Save to temporary folder first, to prevent race conditions when multiple versions are uploaded simultaneously.
if ($this->isLocalFilesystem($this->derivativesDisk)) {
$video->save($this->derivativesDisk->path($tempDerivativeFilePath));
$configuredMedia->save($this->derivativesDisk->path($tempDerivativeFilePath));
} else {
// When using cloud storage, we save to local storage first and then upload manually,
// because the php-ffmpeg-video-streaming package direct upload functionality led to S3 disconnects for large files.
$video->save($this->localDisk->path($tempDerivativeFilePath));
$configuredMedia->save($this->localDisk->path($tempDerivativeFilePath));

$tempDerivativesFormatDirectoryPath = $this->getTempDerivativesFormatDirectoryPath($format);
$tempDerivativesFormatDirectoryPath = $this->getTempDerivativesFormatDirectoryPath($streamingFormat->value);

\Log::info(sprintf('Writing %s to S3 for media %s and version %s.', $format, $this->version->Media->identifier, $this->version->getKey()));
\Log::info(sprintf('Writing %s to S3 for media %s and version %s.', $streamingFormat->value, $this->version->Media->identifier, $this->version->getKey()));
foreach ($this->localDisk->allFiles($tempDerivativesFormatDirectoryPath) as $filePath) {
$this->derivativesDisk->writeStream(
$filePath,
Expand Down
4 changes: 2 additions & 2 deletions compose-nvidia.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ./sail -f compose-nvidia.yml down && ./sail build && ./sail -f compose-nvidia.yml build && ./sail -f compose-nvidia.yml up -d && ./sail shell
services:
app:
extends:
file: compose.yml
service: app
build:
context: ./docker/${DOCKER_PHP_VERSION:-8.2}
dockerfile: DockerfileNvidia
dockerfile: Dockerfile
target: transmorpher_nvidia
args:
WWWGROUP: '${WWWGROUP}'
image: transmorpher-sail-${DOCKER_PHP_VERSION:-8.2}/app-nvidia
Expand Down
12 changes: 11 additions & 1 deletion docker/8.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04
FROM ubuntu:22.04 AS transmorpher_base

LABEL maintainer="Taylor Otwell"

Expand Down Expand Up @@ -71,3 +71,13 @@ RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000

ENTRYPOINT ["start-container"]

FROM transmorpher_base AS transmorpher_nvidia

RUN curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
tee /etc/apt/sources.list.d/nvidia-container-toolkit.list \
&& apt-get update \
&& apt-get install -y nvidia-container-toolkit \
&& apt-get install -y nvtop
11 changes: 0 additions & 11 deletions docker/8.2/DockerfileNvidia

This file was deleted.

13 changes: 12 additions & 1 deletion docker/8.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04
FROM ubuntu:22.04 AS transmorpher_base

LABEL maintainer="Taylor Otwell"

Expand Down Expand Up @@ -71,3 +71,14 @@ RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000

ENTRYPOINT ["start-container"]

FROM transmorpher_base AS transmorpher_nvidia

RUN curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
tee /etc/apt/sources.list.d/nvidia-container-toolkit.list \
&& apt-get update \
&& apt-get install -y nvidia-container-toolkit \
&& apt-get install -y nvtop

11 changes: 0 additions & 11 deletions docker/8.3/DockerfileNvidia

This file was deleted.

0 comments on commit ef3106d

Please sign in to comment.