Consolidate Dockerfile into root and consolidate version into config (#1118)
* Consolidate Dockerfile into root and consolidate version into config * Correct the build args here
This commit is contained in:
parent
1e72fc8e93
commit
b502849184
40
Dockerfile
40
Dockerfile
@ -1,18 +1,28 @@
|
||||
# Perform a build
|
||||
FROM golang:alpine AS build
|
||||
RUN apk add --no-cache gcc build-base linux-headers
|
||||
|
||||
WORKDIR /build
|
||||
COPY . /build
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o owncast .
|
||||
|
||||
|
||||
FROM alpine
|
||||
RUN apk add --no-cache ffmpeg ffmpeg-libs
|
||||
|
||||
WORKDIR /app
|
||||
COPY webroot /app/webroot
|
||||
COPY static /app/static
|
||||
COPY --from=build /build/owncast /app/owncast
|
||||
|
||||
EXPOSE 8080 1935
|
||||
RUN mkdir /build
|
||||
ADD . /build
|
||||
WORKDIR /build
|
||||
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 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"]
|
||||
|
@ -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"]
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
|
21
main.go
21
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user