Skip to content

Commit

Permalink
docker multi stage build.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Sep 27, 2021
1 parent 1755893 commit 133e266
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
35 changes: 20 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
FROM golang:1.17-bullseye

WORKDIR /app

#
# install dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN set -eux; apt update; \
apt install -y --no-install-recommends ffmpeg; \
#
# clean up
apt clean -y; \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
# STAGE 1: build executable binary
#
FROM golang:1.17-alpine as builder
WORKDIR /app

#
# build server
COPY . .

RUN go get -v -t -d .; \
go build -o bin/go-transcode
CGO_ENABLED=0 go build -o go-transcode

#
# STAGE 2: build a small image
#
FROM alpine
WORKDIR /app

#
# install dependencies
RUN apk add --no-cache bash ffmpeg

COPY --from=builder /app/go-transcode go-transcode
COPY profiles profiles

EXPOSE 8080
ENV TRANSCODE_BIND=:8080

ENTRYPOINT [ "bin/go-transcode" ]
ENTRYPOINT [ "./go-transcode" ]
CMD [ "serve" ]
15 changes: 11 additions & 4 deletions Dockerfile.nvidia
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
ARG GO_TRANSCODE_IMAGE=go-transcode:latest
ARG BASE_IMAGE=willprice/nvidia-ffmpeg

#
# STAGE 1: build executable binary
#
FROM $GO_TRANSCODE_IMAGE as build
FROM $BASE_IMAGE as base

#
# STAGE 2: build a small image
#
FROM $BASE_IMAGE as base
WORKDIR /app

ARG USERNAME=user
Expand All @@ -13,13 +19,14 @@ ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME; \
useradd --uid $USER_UID --gid $USERNAME --shell /bin/bash --create-home $USERNAME;

COPY --from=build /app/bin bin
COPY --from=build /app/go-transcode go-transcode
COPY profiles profiles
COPY data data

ENV USER=$USERNAME
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video

EXPOSE 8080
ENV TRANSCODE_BIND=:8080
ENTRYPOINT [ "bin/transcode" ]

ENTRYPOINT [ "./go-transcode" ]
CMD [ "serve" ]

0 comments on commit 133e266

Please sign in to comment.