From 25a5aada2ce20acda59e90c16c75273d76af025a Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 28 Aug 2021 00:08:20 +0200 Subject: [PATCH] Dockerfile build local files not remote files --- Dockerfile | 55 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 05c090ed..aa448ba7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,53 @@ -FROM adamboutcher/statping-ng:base AS base +FROM node:12.18.2-alpine AS frontend +LABEL maintainer="Statping-ng (https://github.com/statping-ng)" ARG BUILDPLATFORM -# Statping main Docker image that contains all required libraries -FROM alpine:latest +WORKDIR /statping +COPY ./frontend/package.json . +COPY ./frontend/yarn.lock . +RUN yarn install --pure-lockfile --network-timeout 1000000 +COPY ./frontend . +RUN yarn build && yarn cache clean + +# Statping Golang BACKEND building from source +# Creates "/go/bin/statping" and "/usr/local/bin/sass" for copying +FROM golang:1.14-alpine AS backend +LABEL maintainer="Statping-NG (https://github.com/statping-ng)" +ARG VERSION +ARG COMMIT +ARG BUILDPLATFORM +ARG TARGETARCH +RUN apk add --update --no-cache libstdc++ gcc g++ make git autoconf \ + libtool ca-certificates linux-headers wget curl jq && \ + update-ca-certificates + +WORKDIR /root +RUN git clone https://github.com/sass/sassc.git +RUN . sassc/script/bootstrap && make -C sassc -j4 +# sassc binary: /root/sassc/bin/sassc + +WORKDIR /go/src/github.com/statping-ng/statping-ng +ADD go.mod go.sum ./ +RUN go mod download +ENV GO111MODULE on +ENV CGO_ENABLED 1 +RUN go get github.com/stretchr/testify/assert && \ + go get github.com/stretchr/testify/require && \ + go get github.com/GeertJohan/go.rice/rice && \ + go get github.com/cortesi/modd/cmd/modd && \ + go get github.com/crazy-max/xgo +COPY . . +COPY --from=frontend /statping/dist/ ./source/dist/ +RUN make clean generate embed +RUN go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT}" -o statping --tags "netgo linux" ./cmd +RUN chmod a+x statping && mv statping /go/bin/statping +# /go/bin/statping - statping binary +# /root/sassc/bin/sassc - sass binary +# /statping - Vue frontend (from frontend) + RUN apk --no-cache add libgcc libstdc++ ca-certificates curl jq && update-ca-certificates -COPY --from=base /go/bin/statping /usr/local/bin/ -COPY --from=base /root/sassc/bin/sassc /usr/local/bin/ -COPY --from=base /usr/local/share/ca-certificates /usr/local/share/ +RUN cp /go/bin/statping /usr/local/bin/ +RUN cp /root/sassc/bin/sassc /usr/local/bin/ WORKDIR /app VOLUME /app @@ -20,4 +61,4 @@ EXPOSE $PORT HEALTHCHECK --interval=60s --timeout=10s --retries=3 CMD curl -s "http://localhost:$PORT/health" | jq -r -e ".online==true" -CMD statping --port $PORT +CMD statping --port $PORT \ No newline at end of file