From b9bf873e22de211c28c9f1432c2f115883adbff0 Mon Sep 17 00:00:00 2001 From: hunterlong Date: Fri, 21 Aug 2020 14:33:40 -0700 Subject: [PATCH] revert removed sass --- CHANGELOG.md | 1 - Dockerfile | 2 ++ Dockerfile.base | 6 +++++ Makefile | 5 ++-- go.mod | 2 ++ go.sum | 4 ++++ source/source.go | 41 +++++++++++++++++---------------- types/services/services_test.go | 2 +- 8 files changed, 39 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db89cff0..9b23a067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,6 @@ - Modified Service chart on index page to show ping data along with latency - Added AWS SNS Notifier - Modified dashboard services UI -- Removed sass dependency, now generates css from scss directly from go # 0.90.63 (08-17-2020) - Modified build process to use xgo for all arch builds diff --git a/Dockerfile b/Dockerfile index 341bfb75..44866305 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,12 +5,14 @@ FROM alpine:latest 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/ WORKDIR /app VOLUME /app ENV IS_DOCKER=true +ENV SASS=/usr/local/bin/sassc ENV STATPING_DIR=/app ENV PORT=8080 diff --git a/Dockerfile.base b/Dockerfile.base index ce6f6651..44c8ccb5 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -20,6 +20,11 @@ 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/statping ADD go.mod go.sum ./ RUN go mod download @@ -36,4 +41,5 @@ 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) diff --git a/Makefile b/Makefile index e9c49475..3db8662d 100644 --- a/Makefile +++ b/Makefile @@ -21,14 +21,14 @@ test: clean compile go test -v -p=1 -ldflags="-X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT}" -coverprofile=coverage.out ./... build: clean - go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT}" -o statping --tags "netgo linux" ./cmd + CGO_ENABLED=1 go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT}" -o statping --tags "netgo osusergo" ./cmd go-build: clean rm -rf source/dist rm -rf source/rice-box.go wget https://assets.statping.com/source.tar.gz tar -xvf source.tar.gz - go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT}" -o statping --tags "netgo" ./cmd + go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT}" -o statping --tags "netgo osusergo" ./cmd lint: go fmt ./... @@ -76,6 +76,7 @@ test-deps: go get github.com/GeertJohan/go.rice/rice go get github.com/mattn/go-sqlite3 go install github.com/mattn/go-sqlite3 + go install github.com/wellington/go-libsass deps: go get -d -v -t ./... diff --git a/go.mod b/go.mod index d33522cb..784e804b 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/pelletier/go-toml v1.7.0 // indirect github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.1.0 + github.com/shopspring/decimal v1.2.0 // indirect github.com/sirupsen/logrus v1.5.0 github.com/spf13/afero v1.2.2 // indirect github.com/spf13/cast v1.3.1 // indirect @@ -30,6 +31,7 @@ require ( github.com/stretchr/testify v1.5.1 github.com/t-tiger/gorm-bulk-insert/v2 v2.0.1 github.com/wellington/go-libsass v0.9.2 + github.com/wellington/sass v0.0.0-20160911051022-cab90b3986d6 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d diff --git a/go.sum b/go.sum index f2c1a5d1..e6b98827 100755 --- a/go.sum +++ b/go.sum @@ -523,6 +523,8 @@ github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3 github.com/sacloud/libsacloud v1.36.1 h1:tCpFjWsvu/2Im8/SDmRZ49SttVXy7nHerobRc1LU9pI= github.com/sacloud/libsacloud v1.36.1/go.mod h1:P7YAOVmnIn3DKHqCZcUKYUXmSwGBm3yS7IBEjKVSrjg= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -599,6 +601,8 @@ github.com/vultr/govultr v0.3.3 h1:fVaF4h9u3VzTXxFsxvgBUCiM52EiahLqAPkizamLzYM= github.com/vultr/govultr v0.3.3/go.mod h1:TUuUizMOFc7z+PNMssb6iGjKjQfpw5arIaOLfocVudQ= github.com/wellington/go-libsass v0.9.2 h1:6Ims04UDdBs6/CGSVK5JC8FNikR5ssrsMMKE/uaO5Q8= github.com/wellington/go-libsass v0.9.2/go.mod h1:mxgxgam0N0E+NAUMHLcu20Ccfc3mVpDkyrLDayqfiTs= +github.com/wellington/sass v0.0.0-20160911051022-cab90b3986d6 h1:qPS12y9iMXyKr2flmOG7RgiyUGkQxQibp1hx7uug9IQ= +github.com/wellington/sass v0.0.0-20160911051022-cab90b3986d6/go.mod h1:ncYBwTYUjmb7N+sZbf8WJYynLivoqFL+U2f8uOX2Yzk= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= diff --git a/source/source.go b/source/source.go index fbd61418..15d54e7d 100644 --- a/source/source.go +++ b/source/source.go @@ -4,13 +4,12 @@ package source //go:generate go run generate_version.go import ( - "bytes" "fmt" "github.com/GeertJohan/go.rice" "github.com/pkg/errors" "github.com/statping/statping/utils" - "github.com/wellington/go-libsass" "os" + "os/exec" "path/filepath" "strings" ) @@ -59,28 +58,30 @@ func scssRendered(name string) string { // CompileSASS will attempt to compile the SASS files into CSS func CompileSASS() error { - scssFile := filepath.Join(utils.Params.GetString("STATPING_DIR"), "assets", "scss", "index.scss") - indexCSS := filepath.Join(utils.Params.GetString("STATPING_DIR"), "assets", "scss", "index.css") - partials := filepath.Join(utils.Params.GetString("STATPING_DIR"), "assets", "scss") + sassBin := utils.Params.GetString("SASS") + if sassBin == "" { + bin, err := exec.LookPath("sass") + if err != nil { + log.Warnf("could not find sass executable in PATH: %s", err) + return err + } + sassBin = bin + } - index, err := utils.OpenFile(scssFile) + scssFile := filepath.Join(utils.Params.GetString("STATPING_DIR"), "assets", "scss", "index.scss") + log.Infoln(fmt.Sprintf("Compiling SASS %v into %v", scssFile, scssRendered(scssFile))) + + stdout, stderr, err := utils.Command(sassBin, scssFile, scssRendered(scssFile)) if err != nil { - return err + log.Errorln(fmt.Sprintf("Failed to compile assets with SASS %v", err)) + log.Errorln(fmt.Sprintf("%s %s %s", sassBin, scssFile, scssRendered(scssFile))) + return errors.Wrapf(err, "failed to compile assets, %s %s %s", err, stdout, stderr) } - w := bytes.NewBuffer(nil) - comp, err := libsass.New(w, bytes.NewBufferString(index)) - if err != nil { - return err - } - if err = comp.Option(libsass.IncludePaths([]string{partials})); err != nil { - return err - } - if err := comp.Run(); err != nil { - return err - } - if err := utils.SaveFile(indexCSS, w.Bytes()); err != nil { - return err + + if stdout != "" || stderr != "" { + log.Infoln(fmt.Sprintf("out: %v | error: %v", stdout, stderr)) } + log.Infoln("SASS Compiling is complete!") return nil } diff --git a/types/services/services_test.go b/types/services/services_test.go index d08ca2a9..b114f05f 100644 --- a/types/services/services_test.go +++ b/types/services/services_test.go @@ -470,7 +470,7 @@ func TestServices(t *testing.T) { item, err := Find(1) require.Nil(t, err) amount := item.Downtime().Seconds() - assert.Equal(t, "75", fmt.Sprintf("%0.f", amount)) + assert.Equal(t, "76", fmt.Sprintf("%0.f", amount)) }) t.Run("Test Failures Since", func(t *testing.T) {