Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Consolidate Dockerfile into root and consolidate version into config (#1118)

Aaron Ogle11e337180753
diff --git a/Dockerfile b/Dockerfile
index 635e09a25b..b9fcd6260d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,18 +1,28 @@
+# Perform a build
FROM golang:alpine AS build
-RUN apk add --no-cache gcc build-base linux-headers
-
+EXPOSE 8080 1935
+RUN mkdir /build
+ADD . /build
WORKDIR /build
-COPY . /build
-RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o owncast .
+RUN apk update && apk add --no-cache gcc build-base linux-headers
+
+ARG VERSION=dev
+ENV VERSION=${VERSION}
+ARG GIT_COMMIT
+ENV GIT_COMMIT=${GIT_COMMIT}
+ARG NAME=docker
+ENV NAME=${NAME}
+RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags "-extldflags \"-static\" -s -w -X github.com/owncast/owncast/config.GitCommit=$GIT_COMMIT -X github.com/owncast/owncast/config.BuildVersion=$VERSION -X github.com/owncast/owncast/config.BuildPlatform=$NAME" -o owncast .
+# Create the image by copying the result of the build into a new alpine image
FROM alpine
-RUN apk add --no-cache ffmpeg ffmpeg-libs
+RUN apk update && apk add --no-cache ffmpeg ffmpeg-libs ca-certificates && update-ca-certificates
+# Copy owncast assets
WORKDIR /app
-COPY webroot /app/webroot
-COPY static /app/static
COPY --from=build /build/owncast /app/owncast
-
-EXPOSE 8080 1935
+COPY --from=build /build/webroot /app/webroot
+COPY --from=build /build/static /app/static
+RUN mkdir /app/data
CMD ["/app/owncast"]
diff --git a/build/release/Dockerfile-build b/build/release/Dockerfile-build
deleted file mode 100644
index 6c6587e6a3..0000000000
--- a/build/release/Dockerfile-build
+++ /dev/null
@@ -1,28 +0,0 @@
-# Perform a build
-FROM golang:alpine AS build
-EXPOSE 8080 1935
-RUN mkdir /build
-ADD . /build
-WORKDIR /build
-RUN apk update && apk add --no-cache gcc build-base linux-headers
-
-ARG VERSION
-ENV VERSION=${VERSION}
-ARG GIT_COMMIT
-ENV GIT_COMMIT=${GIT_COMMIT}
-ARG NAME
-ENV NAME=${NAME}
-
-RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags "-extldflags \"-static\" -s -w -X main.GitCommit=$GIT_COMMIT -X main.BuildVersion=$VERSION -X main.BuildPlatform=$NAME" -o owncast .
-
-# Create the image by copying the result of the build into a new alpine image
-FROM alpine
-RUN apk update && apk add --no-cache ffmpeg ffmpeg-libs ca-certificates && update-ca-certificates
-
-# Copy owncast assets
-WORKDIR /app
-COPY --from=build /build/owncast /app/owncast
-COPY --from=build /build/webroot /app/webroot
-COPY --from=build /build/static /app/static
-RUN mkdir /app/data
-CMD ["/app/owncast"]
diff --git a/build/release/build.sh b/build/release/build.sh
index 15ad58e0c8..abec145862 100755
--- a/build/release/build.sh
+++ b/build/release/build.sh
@@ -72,7 +72,7 @@ build() {
pushd dist/${NAME} >> /dev/null
- CGO_ENABLED=1 ~/go/bin/xgo --branch ${GIT_BRANCH} -ldflags "-s -w -X main.GitCommit=${GIT_COMMIT} -X main.BuildVersion=${VERSION} -X main.BuildPlatform=${NAME}" -targets "${OS}/${ARCH}" github.com/owncast/owncast
+ CGO_ENABLED=1 ~/go/bin/xgo --branch ${GIT_BRANCH} -ldflags "-s -w -X github.com/owncast/owncast/config.GitCommit=${GIT_COMMIT} -X github.com/owncast/owncast/config.BuildVersion=${VERSION} -X github.com/owncast/owncast/config.BuildPlatform=${NAME}" -targets "${OS}/${ARCH}" github.com/owncast/owncast
mv owncast-*-${ARCH} owncast
zip -r -q -8 ../owncast-$VERSION-$NAME.zip .
@@ -112,7 +112,7 @@ echo "Building Docker image ${DOCKER_IMAGE}..."
cd $(git rev-parse --show-toplevel)
# Docker build
-docker build --build-arg NAME=docker --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=$GIT_COMMIT -t gabekangas/owncast:$VERSION -t gabekangas/owncast:latest -t owncast . -f build/release/Dockerfile-build
+docker build --build-arg NAME=docker --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=$GIT_COMMIT -t gabekangas/owncast:$VERSION -t gabekangas/owncast:latest -t owncast .
# Dockerhub
# You must be authenticated via `docker login` with your Dockerhub credentials first.
diff --git a/build/release/docker-nightly.sh b/build/release/docker-nightly.sh
index 49a299af2e..07a172fc56 100755
--- a/build/release/docker-nightly.sh
+++ b/build/release/docker-nightly.sh
@@ -11,7 +11,7 @@ echo "Building Docker image ${DOCKER_IMAGE}..."
cd $(git rev-parse --show-toplevel)
# Docker build
-docker build --build-arg NAME=docker --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=$GIT_COMMIT -t ghcr.io/owncast/${DOCKER_IMAGE}:nightly . -f build/release/Dockerfile-build
+docker build --build-arg NAME=docker --build-arg VERSION=${VERSION} --build-arg GIT_COMMIT=$GIT_COMMIT -t ghcr.io/owncast/${DOCKER_IMAGE}:nightly .
# Dockerhub
# You must be authenticated via `docker login` with your Dockerhub credentials first.
diff --git a/config/config.go b/config/config.go
index 20e05e8ff6..34c2c44275 100644
--- a/config/config.go
+++ b/config/config.go
@@ -2,6 +2,7 @@ package config
import (
"fmt"
+ "time"
)
// These are runtime-set values used for configuration.
@@ -33,11 +34,19 @@ var GitCommit = ""
// BuildPlatform is the optional platform this release was built for.
var BuildPlatform = "dev"
+func GetCommit() string {
+ if GitCommit == "" {
+ GitCommit = time.Now().Format("20060102")
+ }
+
+ return GitCommit
+}
+
// GetReleaseString gets the version string.
func GetReleaseString() string {
var versionNumber = VersionNumber
var buildPlatform = BuildPlatform
- var gitCommit = GitCommit
+ var gitCommit = GetCommit()
return fmt.Sprintf("Owncast v%s-%s (%s)", versionNumber, buildPlatform, gitCommit)
}
diff --git a/main.go b/main.go
index 40078bd1c4..b936353e75 100644
--- a/main.go
+++ b/main.go
@@ -4,7 +4,6 @@ import (
"flag"
"os"
"strconv"
- "time"
"github.com/markbates/pkger"
"github.com/owncast/owncast/logging"
@@ -18,16 +17,6 @@ import (
"github.com/owncast/owncast/utils"
)
-// the following are injected at build-time.
-var (
- // GitCommit is the commit which this version of owncast is running.
- GitCommit = ""
- // BuildVersion is the version.
- BuildVersion = config.StaticVersionNumber
- // BuildPlatform is the type of build.
- BuildPlatform = ""
-)
-
func main() {
// Enable bundling of admin assets
@@ -46,16 +35,6 @@ func main() {
flag.Parse()
- config.VersionNumber = BuildVersion
- if GitCommit != "" {
- config.GitCommit = GitCommit
- } else {
- config.GitCommit = time.Now().Format("20060102")
- }
- if BuildPlatform != "" {
- config.BuildPlatform = BuildPlatform
- }
-
if *logDirectory != "" {
config.LogDirectory = *logDirectory
}