Creating multi-arch building container and consolidated version to Dockerfiles.

This commit is contained in:
Jeromy Streets 2018-12-20 15:15:27 -08:00
parent b1b00805c3
commit ae0e44e9cc
4 changed files with 39 additions and 18 deletions

View File

@ -1,5 +1,6 @@
.git
.gitignore
Dockerfile
Dockerfile.all
LICENSE
README.md

View File

@ -1,7 +1,7 @@
FROM golang:1.11.3 as builder
EXPOSE 8080
ENV VERSION 1.5.1
ENV BUILD_DIR /build
RUN mkdir -p ${BUILD_DIR}
@ -12,9 +12,17 @@ RUN go mod download
COPY . .
RUN go test -cover ./...
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o /serve /build/bin/serve
RUN CGO_ENABLED=0 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o /serve /build/bin/serve
FROM scratch
COPY --from=builder /serve /
ENTRYPOINT ["/serve"]
CMD []
# Metadata
LABEL life.apets.vendor="Halverneus" \
life.apets.url="https://github.com/halverneus/static-file-server" \
life.apets.name="Static File Server" \
life.apets.description="A tiny static file server" \
life.apets.version="v1.5.1" \
life.apets.schema-version="1.0"

23
Dockerfile.all Normal file
View File

@ -0,0 +1,23 @@
FROM golang:1.11.3 as builder
EXPOSE 8080
ENV VERSION 1.5.1
ENV BUILD_DIR /build
RUN mkdir -p ${BUILD_DIR}
WORKDIR ${BUILD_DIR}
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-amd64/serve /build/bin/serve
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm6/serve /build/bin/serve
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm7/serve /build/bin/serve
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/linux-arm64/serve /build/bin/serve
RUN CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -tags netgo -installsuffix netgo -ldflags "-X github.com/halverneus/static-file-server/cli/version.version=${VERSION}" -o pkg/win-amd64/serve /build/bin/serve
# Metadata
LABEL life.apets.vendor="Halverneus" \
life.apets.url="https://github.com/halverneus/static-file-server" \
life.apets.name="Static File Server" \
life.apets.description="A tiny static file server" \
life.apets.version="v1.5.1" \
life.apets.schema-version="1.0"

View File

@ -7,27 +7,16 @@ import (
// Run print operation.
func Run() error {
fmt.Printf("%s\n%s\n", Text, GoVersionText)
fmt.Printf("%s\n%s\n", VersionText, GoVersionText)
return nil
}
var (
// MajorVersion of static-file-server.
MajorVersion = 1
// version is the application version set during build.
version string
// MinorVersion of static-file-server.
MinorVersion = 5
// FixVersion of static-file-server.
FixVersion = 1
// Text for directly accessing the static-file-server version.
Text = fmt.Sprintf(
"v%d.%d.%d",
MajorVersion,
MinorVersion,
FixVersion,
)
// VersionText for directly accessing the static-file-server version.
VersionText = fmt.Sprintf("v%s", version)
// GoVersionText for directly accessing the version of the Go runtime
// compiled with the static-file-server.