Skip to content

Commit 133e266

Browse files
committed
docker multi stage build.
1 parent 1755893 commit 133e266

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

Dockerfile

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
FROM golang:1.17-bullseye
2-
3-
WORKDIR /app
4-
51
#
6-
# install dependencies
7-
ENV DEBIAN_FRONTEND=noninteractive
8-
RUN set -eux; apt update; \
9-
apt install -y --no-install-recommends ffmpeg; \
10-
#
11-
# clean up
12-
apt clean -y; \
13-
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
2+
# STAGE 1: build executable binary
3+
#
4+
FROM golang:1.17-alpine as builder
5+
WORKDIR /app
146

157
#
168
# build server
179
COPY . .
18-
1910
RUN go get -v -t -d .; \
20-
go build -o bin/go-transcode
11+
CGO_ENABLED=0 go build -o go-transcode
12+
13+
#
14+
# STAGE 2: build a small image
15+
#
16+
FROM alpine
17+
WORKDIR /app
18+
19+
#
20+
# install dependencies
21+
RUN apk add --no-cache bash ffmpeg
22+
23+
COPY --from=builder /app/go-transcode go-transcode
24+
COPY profiles profiles
2125

26+
EXPOSE 8080
2227
ENV TRANSCODE_BIND=:8080
2328

24-
ENTRYPOINT [ "bin/go-transcode" ]
29+
ENTRYPOINT [ "./go-transcode" ]
2530
CMD [ "serve" ]

Dockerfile.nvidia

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
ARG GO_TRANSCODE_IMAGE=go-transcode:latest
22
ARG BASE_IMAGE=willprice/nvidia-ffmpeg
33

4+
#
5+
# STAGE 1: build executable binary
6+
#
47
FROM $GO_TRANSCODE_IMAGE as build
5-
FROM $BASE_IMAGE as base
68

9+
#
10+
# STAGE 2: build a small image
11+
#
12+
FROM $BASE_IMAGE as base
713
WORKDIR /app
814

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

16-
COPY --from=build /app/bin bin
22+
COPY --from=build /app/go-transcode go-transcode
1723
COPY profiles profiles
18-
COPY data data
1924

2025
ENV USER=$USERNAME
2126
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
2227

28+
EXPOSE 8080
2329
ENV TRANSCODE_BIND=:8080
24-
ENTRYPOINT [ "bin/transcode" ]
30+
31+
ENTRYPOINT [ "./go-transcode" ]
2532
CMD [ "serve" ]

0 commit comments

Comments
 (0)