Skip to content

Commit

Permalink
Use multi-stage Dockerfile for examples/turn-server/simple
Browse files Browse the repository at this point in the history
  • Loading branch information
levaitamas committed Nov 18, 2023
1 parent 6a55914 commit 06b5adf
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions examples/turn-server/simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
# SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
# SPDX-License-Identifier: MIT

FROM golang:latest
##### builder
FROM golang:alpine as builder

ARG VERSION=master

RUN apk add --no-cache git

WORKDIR /build
# Clone Source using GIT
RUN git clone --branch=$VERSION --depth=1 https://github.com/pion/turn.git turn && rm -rf turn/.git

WORKDIR /build/turn/examples/turn-server/simple

# Download all the dependencies
RUN go get -d -v ./...

# Build static binary
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-w -s" -o turn-server main.go

##### main
FROM alpine

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION=master
Expand All @@ -16,38 +37,22 @@ LABEL org.label-schema.build-date="${BUILD_DATE}" \
org.label-schema.version="${VERSION}" \
maintainer="https://github.com/pion"

ENV GOPATH /usr/local
ENV REALM localhost
ENV USERS username=password
ENV UDP_PORT 3478
ENV PUBLIC_IP 127.0.0.1

# Use turn-server/simple by default
ENV EXAMPLE_DIR examples/turn-server
ENV EXAMPLE_BIN simple

WORKDIR /usr/local/src/github.com/pions

# Clone Source using GIT
RUN git clone --branch=$VERSION --depth=1 https://github.com/pion/turn.git turn && rm -rf turn/.git

WORKDIR /usr/local/src/github.com/pions/turn/$EXAMPLE_DIR

# Download all the dependencies
RUN go get -d -v ./...

# Install the package
RUN go install -v ./...

EXPOSE 3478
#EXPOSE 49152:65535/tcp
#EXPOSE 49152:65535/udp

RUN chown -R nobody:nogroup ./ && chmod -R a-w ./
USER nobody

# Copy the executable
COPY --from=builder /build/turn/examples/turn-server/simple/turn-server /usr/bin/

# Run the executable
CMD $EXAMPLE_BIN -public-ip $PUBLIC_IP -users $USERS -realm $REALM -port $UDP_PORT
CMD turn-server -public-ip $PUBLIC_IP -users $USERS -realm $REALM -port $UDP_PORT

# docker build -t pion-turn -f Dockerfile .
# docker run -e REALM="localhost" -e USERS="username=password" -e UDP_PORT="3478" -e PUBLIC_IP="127.0.0.1" -p 3478:3478 pion-turn
# docker run --rm -e REALM="localhost" -e USERS="username=password" -e UDP_PORT="3478" -e PUBLIC_IP="127.0.0.1" -p 3478:3478 pion-turn

0 comments on commit 06b5adf

Please sign in to comment.