Skip to content

Commit

Permalink
Consolidate Dockerfiles into one parameterized by base image tag
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbenincasa committed Apr 25, 2024
1 parent 0c39052 commit 1256a6e
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/edge-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ on:

jobs:
build_and_push:
runs-on: ubuntu-latest # Replace with desired runner
runs-on: ubuntu-latest
strategy:
matrix:
builds:
- dockerfile: build.Dockerfile
- base_tag: 7.0
tag: edge
- dockerfile: nvidia.Dockerfile
tag: nvidia-edge
- base_tag: 7.0-nvidia
tag: edge-nvidia
- base_tag: 7.0-vaapi
tag: edge-vaapi

steps:
- uses: actions/checkout@v4 # Checkout code from repository
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -37,8 +39,8 @@ jobs:

- uses: actions/cache@v4 # Cache previous HEAD SHA
with:
path: previous_head_sha # Cache key
key: ${{ runner.os }}-edge-build-${{ github.sha }} # Unique cache key
path: previous_head_sha
key: ${{ runner.os }}-edge-build-${{ github.sha }}
restore-keys: | # Check for previous SHA in cache
${{ runner.os }}-edge-build-
Expand All @@ -62,7 +64,7 @@ jobs:
with:
context: .
push: true
file: ${{ matrix.builds.dockerfile }}
build-args: base_image_tag=${{ matrix.builds.base_tag }}
target: full-stack
tags: |
chrisbenincasa/tunarr:${{ matrix.builds.tag }}
Expand Down
93 changes: 93 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
ARG base_image=jasongdove/ersatztv-ffmpeg
ARG base_image_tag=7.0
# Setup a node + ffmpeg + nvidia base
FROM ${base_image}:${base_image_tag} AS ffmpeg-base
ENV NODE_MAJOR=20
ENV TUNARR_BIND_ADDR=0.0.0.0
EXPOSE 8000

# Install musl for native node bindings (sqlite)
RUN apt-get update --fix-missing
RUN apt-get install -y musl-dev
RUN ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1

# Install node
RUN <<EOF
apt-get update && apt-get install -y ca-certificates curl gnupg
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt-get update && apt-get install nodejs -y
EOF

# Install pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

EXPOSE 8000
RUN ln -s /usr/local/bin/ffmpeg /usr/bin/ffmpeg
ENTRYPOINT [ "node" ]

# Add Tunarr sources
FROM ffmpeg-base as sources
WORKDIR /tunarr
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./
COPY server/ ./server
COPY shared/ ./shared
COPY types ./types
COPY web ./web
COPY patches ./patches

FROM ffmpeg-base as dev
EXPOSE 5173
WORKDIR /tunarr
COPY . .
RUN pnpm install --frozen-lockfile
ENTRYPOINT [ "pnpm" ]
CMD [ "turbo", "dev" ]

FROM sources AS prod-deps
ARG NODE_ENVIRONMENT
ENV NODE_ENV=${NODE_ENVIRONMENT:-production}
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

### Begin server build ###
FROM sources AS build-server
# Install deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
# Build and bundle
RUN pnpm turbo --filter=@tunarr/server bundle
### End server build ###

### Begin server web ###
FROM sources AS build-web
# Install deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
# Build common modules
RUN pnpm turbo --filter=@tunarr/web bundle

FROM sources as build-full-stack
# Install deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
# Build common modules
RUN pnpm turbo bundle

### Begin server run ###
FROM ffmpeg-base AS server
COPY --from=prod-deps /tunarr/node_modules /tunarr/node_modules
COPY --from=prod-deps /tunarr/server/node_modules /tunarr/server/node_modules
COPY --from=build-server /tunarr/types /tunarr/types
COPY --from=build-server /tunarr/shared /tunarr/shared
COPY --from=build-server /tunarr/server/package.json /tunarr/server/package.json
COPY --from=build-server /tunarr/server/build /tunarr/server/build
# Create a symlink to the bundle at /tunarr. This simplifies things for the
# user, such as volume mapping their legacy DBs, while not interrupting the
# other assumptions that Tunarr makes about its working directory
RUN ln -s /tunarr/server/build/bundle.js /tunarr/bundle.js
CMD [ "/tunarr/bundle.js" ]
### Begin server run

### Full stack ###
FROM server AS full-stack
COPY --from=build-full-stack /tunarr/web/dist /tunarr/server/build/web

0 comments on commit 1256a6e

Please sign in to comment.