From 25a5aada2ce20acda59e90c16c75273d76af025a Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 28 Aug 2021 00:08:20 +0200 Subject: [PATCH 1/9] 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 From 6a0250b0ea7fc64d017b8f9338e3b29fd523618f Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 28 Aug 2021 00:18:56 +0200 Subject: [PATCH 2/9] reduce size of Image --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index aa448ba7..3f7b4407 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,10 +44,12 @@ RUN chmod a+x statping && mv statping /go/bin/statping # /root/sassc/bin/sassc - sass binary # /statping - Vue frontend (from frontend) +FROM alpine:latest + RUN apk --no-cache add libgcc libstdc++ ca-certificates curl jq && update-ca-certificates -RUN cp /go/bin/statping /usr/local/bin/ -RUN cp /root/sassc/bin/sassc /usr/local/bin/ +COPY --from=backend /go/bin/statping /usr/local/bin/ +COPY --from=backend /root/sassc/bin/sassc /usr/local/bin/ WORKDIR /app VOLUME /app From e36323c2476ba12e5d9efe444b613f5f261d437b Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 28 Aug 2021 00:47:35 +0200 Subject: [PATCH 3/9] remove base-image --- Makefile | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index c701900f..e3af0ecc 100644 --- a/Makefile +++ b/Makefile @@ -111,13 +111,10 @@ db-down: console: docker exec -t -i statping /bin/sh -compose-build-full: docker-base +compose-build-full: docker-compose -f docker-compose.yml -f dev/docker-compose.full.yml build --parallel --build-arg VERSION=${VERSION} -docker-base: - docker build -t statping-ng/statping-ng:base -f Dockerfile.base --build-arg VERSION=${VERSION} . - -docker-latest: docker-base +docker-latest: docker build -t statping-ng/statping-ng:latest --build-arg VERSION=${VERSION} . docker-vue: @@ -126,13 +123,6 @@ docker-vue: docker-test: docker-compose -f docker-compose.test.yml up --remove-orphans -push-base: clean compile docker-base - docker push statping-ng/statping-ng:base - -push-vue: clean compile docker-base docker-vue - docker push statping-ng/statping-ng:base - docker push statping-ng/statping-ng:vue - modd: modd -f ./dev/modd.conf @@ -285,16 +275,9 @@ download-key: wget -O statping.gpg $(SIGN_URL) gpg --import statping.gpg -# push the :dev docker tag using curl -dockerhub-dev: - docker build --build-arg VERSION=${VERSION} -t statping-ng/statping-ng:dev --no-cache -f Dockerfile.base . - docker push statping-ng/statping-ng:dev - dockerhub: - docker build --build-arg VERSION=${VERSION} -t statping-ng/statping-ng:base --no-cache -f Dockerfile.base . docker build --build-arg VERSION=${VERSION} -t statping-ng/statping-ng:latest --no-cache -f Dockerfile . docker tag statping-ng/statping-ng statping-ng/statping-ng:v${VERSION} - docker push statping-ng/statping-ng:base docker push statping-ng/statping-ng:v${VERSION} docker push statping-ng/statping-ng @@ -392,12 +375,6 @@ buildx-dev: multiarch docker buildx build --builder statping-dev --cache-from "type=local,src=/tmp/.buildx-cache" --cache-to "type=local,dest=/tmp/.buildx-cache,mode=max" --push --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -f Dockerfile -t adamboutcher/statping-ng:dev --build-arg=VERSION=${VERSION} --build-arg=COMMIT=${COMMIT} . docker buildx rm statping-dev -buildx-base: multiarch - docker buildx create --name statping-base --driver-opt image=moby/buildkit:master - docker buildx inspect --builder statping-base --bootstrap - docker buildx build --builder statping-base --cache-from "type=local,src=/tmp/.buildx-cache" --cache-to "type=local,dest=/tmp/.buildx-cache,mode=max" --push --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 -f Dockerfile.base -t adamboutcher/statping-ng:base --build-arg=VERSION=${VERSION} --build-arg=COMMIT=${COMMIT} . - docker buildx rm statping-base - multiarch: mkdir /tmp/.buildx-cache || true docker run --rm --privileged multiarch/qemu-user-static --reset -p yes @@ -426,5 +403,5 @@ gen_help: marked -o html/$file.html $file --gfm done -.PHONY: all check build certs multiarch install-darwin go-build build-all buildx-base buildx-dev buildx-latest build-alpine test-all test test-api docker frontend up down print_details lite sentry-release snapcraft build-linux build-mac build-win build-all postman +.PHONY: all check build certs multiarch install-darwin go-build build-all buildx-dev buildx-latest build-alpine test-all test test-api docker frontend up down print_details lite sentry-release snapcraft build-linux build-mac build-win build-all postman .SILENT: travis_s3_creds From ccbf9baaf03de4a9213dd9e43c3d68dc8cbf409f Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 28 Aug 2021 00:48:22 +0200 Subject: [PATCH 4/9] adjust image names to be statping-ng/statping-ng --- dev/docker-compose.lite.yml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/docker-compose.lite.yml b/dev/docker-compose.lite.yml index 78f7dd2d..66b9c85e 100644 --- a/dev/docker-compose.lite.yml +++ b/dev/docker-compose.lite.yml @@ -4,7 +4,7 @@ services: statping_dev: container_name: statping_dev - image: statping/statping:dev + image: statping-ng/statping-ng:dev restart: on-failure volumes: - ./cmd:/go/src/github.com/statping-ng/statping-ng/cmd/ diff --git a/docker-compose.yml b/docker-compose.yml index 38533e5a..c5f45948 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '2.3' services: statping: container_name: statping - image: aboutcher/statping-ng:dev + image: statping-ng/statping-ng:dev restart: always volumes: - statping_data:/app From e5c7c4541d2099824882e3f86540071b7d1adfec Mon Sep 17 00:00:00 2001 From: nils1323 Date: Sat, 28 Aug 2021 02:00:50 +0200 Subject: [PATCH 5/9] add description for Image with binary Co-authored-by: Willy --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 3f7b4407..fbe6d76b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,6 +44,7 @@ RUN chmod a+x statping && mv statping /go/bin/statping # /root/sassc/bin/sassc - sass binary # /statping - Vue frontend (from frontend) +# Statping main Docker image that contains all required libraries FROM alpine:latest RUN apk --no-cache add libgcc libstdc++ ca-certificates curl jq && update-ca-certificates From 9327dbbf52c2f0692b88319dab9ee46b44e38bd1 Mon Sep 17 00:00:00 2001 From: nils1323 Date: Sat, 28 Aug 2021 02:10:54 +0200 Subject: [PATCH 6/9] Apply suggestions from code review Co-authored-by: Willy --- Dockerfile | 3 ++- docker-compose.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fbe6d76b..ca503f78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,7 @@ RUN apk --no-cache add libgcc libstdc++ ca-certificates curl jq && update-ca-cer COPY --from=backend /go/bin/statping /usr/local/bin/ COPY --from=backend /root/sassc/bin/sassc /usr/local/bin/ +COPY --from=backend /usr/local/share/ca-certificates /usr/local/share/ WORKDIR /app VOLUME /app @@ -64,4 +65,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 \ No newline at end of file +CMD statping --port $PORT diff --git a/docker-compose.yml b/docker-compose.yml index c5f45948..38533e5a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '2.3' services: statping: container_name: statping - image: statping-ng/statping-ng:dev + image: aboutcher/statping-ng:dev restart: always volumes: - statping_data:/app From ad416c9499b4f6ed64f53927da9cb3762c3eb46b Mon Sep 17 00:00:00 2001 From: nils1323 Date: Sat, 28 Aug 2021 02:13:22 +0200 Subject: [PATCH 7/9] remove docker-vue --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index e3af0ecc..5d484547 100644 --- a/Makefile +++ b/Makefile @@ -117,9 +117,6 @@ compose-build-full: docker-latest: docker build -t statping-ng/statping-ng:latest --build-arg VERSION=${VERSION} . -docker-vue: - docker build -t statping-ng/statping-ng:vue --build-arg VERSION=${VERSION} . - docker-test: docker-compose -f docker-compose.test.yml up --remove-orphans From a222b0148a00ebe8b69dc30fb0b94e90ad9310ea Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 28 Aug 2021 20:42:12 +0200 Subject: [PATCH 8/9] fixed naming for dockerhub --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5d484547..04ae8c6f 100644 --- a/Makefile +++ b/Makefile @@ -273,10 +273,10 @@ download-key: gpg --import statping.gpg dockerhub: - docker build --build-arg VERSION=${VERSION} -t statping-ng/statping-ng:latest --no-cache -f Dockerfile . - docker tag statping-ng/statping-ng statping-ng/statping-ng:v${VERSION} - docker push statping-ng/statping-ng:v${VERSION} - docker push statping-ng/statping-ng + docker build --build-arg VERSION=${VERSION} -t adamboutcher/statping-ng:latest --no-cache -f Dockerfile . + docker tag adamboutcher/statping-ng adamboutcher/statping-ng:v${VERSION} + docker push adamboutcher/statping-ng:v${VERSION} + docker push adamboutcher/statping-ng docker-build-dev: docker build --build-arg VERSION=${VERSION} -t statping-ng/statping-ng:latest --no-cache -f Dockerfile . From 57e594823a7ace7a74540bdbb013a769fa23173a Mon Sep 17 00:00:00 2001 From: Nils Date: Sat, 28 Aug 2021 20:50:11 +0200 Subject: [PATCH 9/9] fix naming in docker-compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 38533e5a..395b773e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '2.3' services: statping: container_name: statping - image: aboutcher/statping-ng:dev + image: adamboutcher/statping-ng:latest restart: always volumes: - statping_data:/app