make file

This commit is contained in:
nicksherron 2020-02-07 11:45:22 -05:00
parent 5de60614a7
commit 06f64ace02
2 changed files with 35 additions and 28 deletions

View file

@ -1,40 +1,42 @@
# Build Stage
FROM nicksherron/bashhub-server-build:1.13 AS build-stage
# GitHub: https://github.com/nicksherron/bashhub-server
FROM golang:1.13-alpine AS build
LABEL app="build-bashhub-server"
LABEL REPO="https://github.com/nicksherron/bashhub-server"
ARG VERSION
ARG GIT_COMMIT
ARG BUILD_DATE
ENV PROJPATH=/go/src/github.com/nicksherron/bashhub-server
ARG CGO=1
ENV CGO_ENABLED=${CGO}
ENV GOOS=linux
ENV GO111MODULE=on
# Because of https://github.com/docker/docker/issues/14914
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
ADD . /go/src/github.com/nicksherron/bashhub-server
WORKDIR /go/src/github.com/nicksherron/bashhub-server
RUN make build-alpine
COPY . /go/src/github.com/nicksherron/bashhub-server/
# Final Stage
FROM nicksherron/bashhub-server
# gcc/g++ are required to build SASS libraries for extended version
RUN apk update && \
apk add --no-cache gcc g++ musl-dev
ARG GIT_COMMIT
ARG VERSION
LABEL REPO="https://github.com/nicksherron/bashhub-server"
LABEL GIT_COMMIT=$GIT_COMMIT
LABEL VERSION=$VERSION
# Because of https://github.com/docker/docker/issues/14914
ENV PATH=$PATH:/opt/bashhub-server/bin
RUN go build -ldflags '-w -linkmode external -extldflags "-static" -X github.com/nicksherron/bashhub-server/version.GitCommit=${GIT_COMMIT} -X github.com/nicksherron/bashhub-server/version.BuildDate=${BUILD_DATE}' -o bin/${BIN_NAME}
WORKDIR /opt/bashhub-server/bin
# ---
COPY --from=build-stage /go/src/github.com/nicksherron/bashhub-server/bin/bashhub-server /opt/bashhub-server/bin/
RUN chmod +x /opt/bashhub-server/bin/bashhub-server
FROM alpine:3.11
# Create appuser
RUN adduser -D -g '' bashhub-server
USER bashhub-server
COPY --from=build /go/bin/bashhub-server /usr/bin/bashhub-server
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# libc6-compat & libstdc++ are required for extended SASS libraries
# ca-certificates are required to fetch outside resources (like Twitter oEmbeds)
RUN apk update && \
apk add --no-cache ca-certificates libc6-compat libstdc++
CMD ["/opt/bashhub-server/bin/bashhub-server"]
VOLUME /data
WORKDIR /data
# Expose port for live server
EXPOSE 4444
ENTRYPOINT ["bashhub-server"]
CMD ["--help"]

View file

@ -1,4 +1,4 @@
.PHONY: build build-alpine clean test help default
.PHONY: build build-alpine clean test help default docker-build
BIN_NAME=bashhub-server
@ -32,6 +32,11 @@ build:
get-deps:
dep ensure
docker-build:
docker build --no-cache=true --build-arg VERSION=${VERSION} --build-arg BUILD_DATE=${BUILD_DATE} --build-arg GIT_COMMIT=${GIT_COMMIT} -t $(IMAGE_NAME) .
build-alpine:
@echo "building ${BIN_NAME} ${VERSION}"
@echo "GOPATH=${GOPATH}"