From 3608934c58005914de4dce6180e4376323bdf15b Mon Sep 17 00:00:00 2001 From: lukyer Date: Fri, 31 Mar 2023 14:46:46 +0200 Subject: [PATCH 1/9] ARM docker build support --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c08e6fb..38f8e1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY Makefile main.go ./ COPY server/ ./server/ RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build -FROM node:16-alpine AS build-frontend +FROM node:16-bullseye AS build-frontend WORKDIR /wd ENV PARCEL_WORKERS 1 # node-gyp dependencies: https://github.com/nodejs/node-gyp#on-unix From 16e15b2fdf655e74d19b0279bf78bd68dcfd7386 Mon Sep 17 00:00:00 2001 From: lukyer Date: Fri, 31 Mar 2023 15:00:03 +0200 Subject: [PATCH 2/9] ARM support in CI build --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1346601..8fb0d07 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ clean: .PHONY: build-docker build-docker: - docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest . + docker buildx build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest --platform linux/arm/v7,linux/arm64,linux/amd64 . docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG) .PHONY: start-docker From 1829d841cb92bbf7b98ec9eacd927a6d7968c832 Mon Sep 17 00:00:00 2001 From: lukyer Date: Fri, 31 Mar 2023 16:50:56 +0200 Subject: [PATCH 3/9] Remove arm v7 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8fb0d07..dd24027 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ clean: .PHONY: build-docker build-docker: - docker buildx build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest --platform linux/arm/v7,linux/arm64,linux/amd64 . + docker buildx build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest --platform linux/arm64,linux/amd64 . docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG) .PHONY: start-docker From 453021d9ff40e03bcced6053e89ebe6c8338620d Mon Sep 17 00:00:00 2001 From: Gwendal Leclerc Date: Mon, 2 Oct 2023 20:26:23 +0200 Subject: [PATCH 4/9] fix: golang-ci-lint version + lint errors --- Makefile | 2 +- server/services/persistence.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dd24027..2704734 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ REFLEX=$(GOPATH)/bin/reflex $(REFLEX): go install github.com/cespare/reflex@latest -GOLANGCILINTVERSION:=1.32.0 +GOLANGCILINTVERSION:=1.54.2 GOLANGCILINT=$(GOPATH)/bin/golangci-lint $(GOLANGCILINT): curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v$(GOLANGCILINTVERSION) diff --git a/server/services/persistence.go b/server/services/persistence.go index e6c720f..bca829c 100644 --- a/server/services/persistence.go +++ b/server/services/persistence.go @@ -110,6 +110,7 @@ func (p *persistence) StoreSessions(sessions types.Sessions) { } var sessionsGroup errgroup.Group for _, session := range sessions { + session := session sessionsGroup.Go(func() error { if err := p.createSessionDirectory(session.ID); err != nil { return err @@ -161,6 +162,7 @@ func (p *persistence) LoadSessions() (types.Sessions, error) { var sessionsGroup errgroup.Group var sessionsLock sync.Mutex for _, session := range sessions { + session := session sessionsGroup.Go(func() error { historyFile, err := os.Open(filepath.Join(p.persistenceDirectory, session.ID, historyFileName)) if err != nil { @@ -235,7 +237,6 @@ func (p *persistence) persistHistory(sessionID string, h types.History) error { } func (p *persistence) persistMocks(sessionID string, m types.Mocks) error { - // we need to reverse mocks before storage in order to have a reusable mocks file as mocks are stored as a stack orderedMocks := make(types.Mocks, 0, len(m)) for i := len(m) - 1; i >= 0; i-- { From 62a205c5857a610eae902607666c05158905cbbd Mon Sep 17 00:00:00 2001 From: Gwendal Leclerc Date: Mon, 2 Oct 2023 20:34:24 +0200 Subject: [PATCH 5/9] fix: try to upgrade github actions --- .github/workflows/main.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8407929..2cf8957 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - id: nvm run: echo ::set-output name=NVMRC::$(cat .nvmrc) @@ -35,7 +35,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -48,9 +48,9 @@ jobs: cache: yarn - name: Setup Go environment - uses: actions/setup-go@v2.1.3 + uses: actions/setup-go@v4 with: - go-version: '^1.18.0' + go-version: '^1.21.1' - run: yarn install --frozen-lockfile @@ -70,7 +70,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - id: extract_ref run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/}) @@ -84,12 +84,16 @@ jobs: cache: yarn - name: Setup Go environment - uses: actions/setup-go@v2.1.3 + uses: actions/setup-go@v4 with: - go-version: '^1.18.0' + go-version: '^1.21.1' - - uses: satackey/action-docker-layer-caching@v0.0.11 - continue-on-error: true + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 - run: yarn install --frozen-lockfile @@ -119,7 +123,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - id: extract_ref run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/}) From 1122a6fc8e8d898de4a8309cb81654c28074f66b Mon Sep 17 00:00:00 2001 From: Gwendal Leclerc Date: Mon, 2 Oct 2023 20:41:25 +0200 Subject: [PATCH 6/9] fix: remove apk in dockerfile as we use debian instead of alpine --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 38f8e1d..5c6fb9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,8 +12,6 @@ RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build FROM node:16-bullseye AS build-frontend WORKDIR /wd ENV PARCEL_WORKERS 1 -# node-gyp dependencies: https://github.com/nodejs/node-gyp#on-unix -RUN apk add --no-cache g++ make python3 COPY package.json yarn.lock ./ RUN yarn install --frozen-lockfile COPY tsconfig.json ./ From bc141e1559926131ceffae91cc64dd2682b7c5f8 Mon Sep 17 00:00:00 2001 From: Gwendal Leclerc Date: Mon, 2 Oct 2023 22:44:05 +0200 Subject: [PATCH 7/9] fix: antd version + persisitance error --- package.json | 4 +- server/middlewares.go | 25 ++++++---- server/services/mocks.go | 1 - server/services/persistence.go | 86 +++++++++++++++++++++------------- tsconfig.json | 2 +- yarn.lock | 57 ++++++++-------------- 6 files changed, 91 insertions(+), 84 deletions(-) diff --git a/package.json b/package.json index 1ce8fd6..e22a598 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ } }, "dependencies": { - "@ant-design/icons": "^4.1.0", + "@ant-design/icons": "^4.x", "antd": "^4.16.9", "classnames": "^2.2.6", "codemirror": "^5.55.0", @@ -110,4 +110,4 @@ "jest": { "preset": "ts-jest" } -} +} \ No newline at end of file diff --git a/server/middlewares.go b/server/middlewares.go index 0671f45..af744ee 100644 --- a/server/middlewares.go +++ b/server/middlewares.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" "net/http" "runtime" @@ -66,7 +65,7 @@ func HistoryMiddleware(s services.Mocks) echo.MiddlewareFunc { if err != nil { log.WithError(err).Error("Unable to uncompress response body") } else { - responseBytes, err = ioutil.ReadAll(r) + responseBytes, err = io.ReadAll(r) if err != nil { log.WithError(err).Error("Unable to read uncompressed response body") responseBytes = responseBody.Bytes() @@ -104,14 +103,9 @@ func HistoryMiddleware(s services.Mocks) echo.MiddlewareFunc { func loggerMiddleware() echo.MiddlewareFunc { return func(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { - req, res := c.Request(), c.Response() + req := c.Request() start := time.Now() - if err := next(c); err != nil { - c.Error(err) - } - end := time.Now() - p := req.URL.Path if p == "" { p = "/" @@ -123,18 +117,29 @@ func loggerMiddleware() echo.MiddlewareFunc { } headers := fmt.Sprintf("%+v", req.Header) + entry := log.WithFields(log.Fields{ "start": start.Format(time.RFC3339), - "end": end.Format(time.RFC3339), "remote-ip": c.RealIP(), "host": req.Host, "uri": req.RequestURI, "method": req.Method, "path": p, "headers": headers, + "bytes-in": bytesIn, + }) + entry.Debug("Handling request...") + + if err := next(c); err != nil { + c.Error(err) + } + + res := c.Response() + end := time.Now() + entry = entry.WithFields(log.Fields{ + "end": end.Format(time.RFC3339), "status": res.Status, "latency": end.Sub(start).String(), - "bytes-in": bytesIn, "bytes-out": res.Size, }) diff --git a/server/services/mocks.go b/server/services/mocks.go index ef4e473..00436d2 100644 --- a/server/services/mocks.go +++ b/server/services/mocks.go @@ -183,7 +183,6 @@ func (s *mocks) GetHistoryByPath(sessionID, filterPath string) (types.History, e } func (s *mocks) NewSession(name string) *types.Session { - if strings.TrimSpace(name) == "" { name = fmt.Sprintf("Session #%d", len(s.sessions)+1) } diff --git a/server/services/persistence.go b/server/services/persistence.go index bca829c..7a5584c 100644 --- a/server/services/persistence.go +++ b/server/services/persistence.go @@ -1,7 +1,7 @@ package services import ( - "io/ioutil" + "io" "os" "path/filepath" "sync" @@ -26,8 +26,9 @@ type Persistence interface { StoreSessions(types.Sessions) } +var mu sync.Mutex + type persistence struct { - mu sync.Mutex persistenceDirectory string } @@ -39,8 +40,8 @@ func NewPersistence(persistenceDirectory string) Persistence { } func (p *persistence) StoreMocks(sessionID string, mocks types.Mocks) { - p.mu.Lock() - defer p.mu.Unlock() + mu.Lock() + defer mu.Unlock() if p.persistenceDirectory == "" { return } @@ -56,8 +57,8 @@ func (p *persistence) StoreMocks(sessionID string, mocks types.Mocks) { } func (p *persistence) StoreHistory(sessionID string, history types.History) { - p.mu.Lock() - defer p.mu.Unlock() + mu.Lock() + defer mu.Unlock() if p.persistenceDirectory == "" { return } @@ -73,8 +74,8 @@ func (p *persistence) StoreHistory(sessionID string, history types.History) { } func (p *persistence) StoreSession(summary []types.SessionSummary, session *types.Session) { - p.mu.Lock() - defer p.mu.Unlock() + mu.Lock() + defer mu.Unlock() if p.persistenceDirectory == "" { return } @@ -99,18 +100,14 @@ func (p *persistence) StoreSession(summary []types.SessionSummary, session *type } func (p *persistence) StoreSessions(sessions types.Sessions) { - p.mu.Lock() - defer p.mu.Unlock() + mu.Lock() + defer mu.Unlock() if p.persistenceDirectory == "" { return } - if err := p.cleanAll(); err != nil { - log.Error("unable to clean directory: ", err) - return - } var sessionsGroup errgroup.Group - for _, session := range sessions { - session := session + for _, ses := range sessions { + session := *ses sessionsGroup.Go(func() error { if err := p.createSessionDirectory(session.ID); err != nil { return err @@ -134,11 +131,14 @@ func (p *persistence) StoreSessions(sessions types.Sessions) { if err := sessionsGroup.Wait(); err != nil { log.Error("unable to store sessions: ", err) } + if err := p.cleanOutdatedSessions(sessions); err != nil { + log.Error("unable to clean outdated sessions: ", err) + } } func (p *persistence) LoadSessions() (types.Sessions, error) { - p.mu.Lock() - defer p.mu.Unlock() + mu.Lock() + defer mu.Unlock() if p.persistenceDirectory == "" { return nil, nil } @@ -147,10 +147,13 @@ func (p *persistence) LoadSessions() (types.Sessions, error) { } file, err := os.Open(filepath.Join(p.persistenceDirectory, sessionsFileName)) if err != nil { + if err == os.ErrNotExist { + return types.Sessions{}, nil + } return nil, err } defer file.Close() - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return nil, err } @@ -161,15 +164,16 @@ func (p *persistence) LoadSessions() (types.Sessions, error) { } var sessionsGroup errgroup.Group var sessionsLock sync.Mutex - for _, session := range sessions { - session := session + for _, ses := range sessions { + session := *ses sessionsGroup.Go(func() error { historyFile, err := os.Open(filepath.Join(p.persistenceDirectory, session.ID, historyFileName)) if err != nil { + log.WithError(err).Errorf("Unable to open history file for session %q", session.ID) return err } defer historyFile.Close() - bytes, err := ioutil.ReadAll(historyFile) + bytes, err := io.ReadAll(historyFile) if err != nil { return err } @@ -186,10 +190,11 @@ func (p *persistence) LoadSessions() (types.Sessions, error) { sessionsGroup.Go(func() error { mocksFile, err := os.Open(filepath.Join(p.persistenceDirectory, session.ID, mocksFileName)) if err != nil { + log.WithError(err).Errorf("Unable to open mocks file for session %q", session.ID) return err } defer mocksFile.Close() - bytes, err := ioutil.ReadAll(mocksFile) + bytes, err := io.ReadAll(mocksFile) if err != nil { return err } @@ -213,10 +218,15 @@ func (p *persistence) LoadSessions() (types.Sessions, error) { if err := sessionsGroup.Wait(); err != nil { return nil, err } + if err := p.cleanOutdatedSessions(sessions); err != nil { + return nil, err + } + return sessions, nil } func (p *persistence) createSessionDirectory(sessionID string) error { + log.Debugf("Create directory for session %q", sessionID) sessionDirectory := filepath.Join(p.persistenceDirectory, sessionID) if err := os.MkdirAll(sessionDirectory, os.ModePerm); err != nil && !os.IsExist(err) { return err @@ -225,11 +235,12 @@ func (p *persistence) createSessionDirectory(sessionID string) error { } func (p *persistence) persistHistory(sessionID string, h types.History) error { + log.Debugf("Persist history for session %q", sessionID) history, err := yaml.Marshal(h) if err != nil { return err } - err = ioutil.WriteFile(filepath.Join(p.persistenceDirectory, sessionID, historyFileName), history, os.ModePerm) + err = os.WriteFile(filepath.Join(p.persistenceDirectory, sessionID, historyFileName), history, os.ModePerm) if err != nil { return err } @@ -237,6 +248,7 @@ func (p *persistence) persistHistory(sessionID string, h types.History) error { } func (p *persistence) persistMocks(sessionID string, m types.Mocks) error { + log.Debugf("Persist mocks for session %q", sessionID) // we need to reverse mocks before storage in order to have a reusable mocks file as mocks are stored as a stack orderedMocks := make(types.Mocks, 0, len(m)) for i := len(m) - 1; i >= 0; i-- { @@ -246,7 +258,7 @@ func (p *persistence) persistMocks(sessionID string, m types.Mocks) error { if err != nil { return err } - err = ioutil.WriteFile(filepath.Join(p.persistenceDirectory, sessionID, mocksFileName), mocks, os.ModePerm) + err = os.WriteFile(filepath.Join(p.persistenceDirectory, sessionID, mocksFileName), mocks, os.ModePerm) if err != nil { return err } @@ -254,27 +266,35 @@ func (p *persistence) persistMocks(sessionID string, m types.Mocks) error { } func (p *persistence) persistSessionsSummary(summary []types.SessionSummary) error { + log.Debug("Persist sessions summary") sessions, err := yaml.Marshal(summary) if err != nil { return err } - err = ioutil.WriteFile(filepath.Join(p.persistenceDirectory, sessionsFileName), sessions, os.ModePerm) + err = os.WriteFile(filepath.Join(p.persistenceDirectory, sessionsFileName), sessions, os.ModePerm) if err != nil { return err } return nil } -func (p *persistence) cleanAll() error { - if err := os.MkdirAll(p.persistenceDirectory, os.ModePerm); err != nil && !os.IsExist(err) { - return err - } - files, err := ioutil.ReadDir(p.persistenceDirectory) +func (p *persistence) cleanOutdatedSessions(sessions types.Sessions) error { + sessionsIDs := make(map[string]bool, len(sessions)) + for _, ses := range sessions { + session := *ses + sessionsIDs[session.ID] = true + } + log.Debug("Clean old sessions") + entries, err := os.ReadDir(p.persistenceDirectory) if err != nil { return err } - for _, file := range files { - os.RemoveAll(filepath.Join(p.persistenceDirectory, file.Name())) + for _, entry := range entries { + if entry.IsDir() && !sessionsIDs[entry.Name()] { + path := filepath.Join(p.persistenceDirectory, entry.Name()) + log.Debugf("Removing directory: %q", path) + os.RemoveAll(path) + } } return nil } diff --git a/tsconfig.json b/tsconfig.json index 033b22d..98151e1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,5 +20,5 @@ "esModuleInterop": true }, "include": ["client/**/*"], - "exclude": ["node_modules", "build"] + "exclude": ["node_modules", "build", "client/coverage"] } diff --git a/yarn.lock b/yarn.lock index d52ccab..09628cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21,13 +21,6 @@ html-tags "^3.1.0" svg-tags "^1.0.0" -"@ant-design/colors@^3.1.0": - version "3.2.2" - resolved "https://registry.yarnpkg.com/@ant-design/colors/-/colors-3.2.2.tgz#5ad43d619e911f3488ebac303d606e66a8423903" - integrity sha512-YKgNbG2dlzqMhA9NtI3/pbY16m3Yl/EeWBRa+lB1X1YaYxHrxNexiQYCLTWO/uDvAjLFMEDU+zR901waBtMtjQ== - dependencies: - tinycolor2 "^1.4.1" - "@ant-design/colors@^6.0.0": version "6.0.0" resolved "https://registry.yarnpkg.com/@ant-design/colors/-/colors-6.0.0.tgz#9b9366257cffcc47db42b9d0203bb592c13c0298" @@ -40,17 +33,10 @@ resolved "https://registry.yarnpkg.com/@ant-design/icons-svg/-/icons-svg-4.1.0.tgz#480b025f4b20ef7fe8f47d4a4846e4fee84ea06c" integrity sha512-Fi03PfuUqRs76aI3UWYpP864lkrfPo0hluwGqh7NJdLhvH4iRDc3jbJqZIvRDLHKbXrvAfPPV3+zjUccfFvWOQ== -"@ant-design/icons@^4.1.0": - version "4.2.1" - resolved "https://registry.yarnpkg.com/@ant-design/icons/-/icons-4.2.1.tgz#6f3ea5d98ab782072e4e9cbb70f25e4403ae1a6b" - integrity sha512-245ZI40MOr5GGws+sNSiJIRRoEf/J2xvPSMgwRYf3bv8mVGQZ6XTQI/OMeV16KtiSZ3D+mBKXVYSBz2fhigOXQ== - dependencies: - "@ant-design/colors" "^3.1.0" - "@ant-design/icons-svg" "^4.0.0" - "@babel/runtime" "^7.10.1" - classnames "^2.2.6" - insert-css "^2.0.0" - rc-util "^5.0.1" +"@ant-design/icons-svg@^4.3.0": + version "4.3.1" + resolved "https://registry.yarnpkg.com/@ant-design/icons-svg/-/icons-svg-4.3.1.tgz#4b2f65a17d4d32b526baa6414aca2117382bf8da" + integrity sha512-4QBZg8ccyC6LPIRii7A0bZUk3+lEDCLnhB+FVsflGdcWPPmV+j3fire4AwwoqHV/BibgvBmR9ZIo4s867smv+g== "@ant-design/icons@^4.6.2": version "4.6.2" @@ -63,6 +49,18 @@ classnames "^2.2.6" rc-util "^5.9.4" +"@ant-design/icons@^4.x": + version "4.8.1" + resolved "https://registry.yarnpkg.com/@ant-design/icons/-/icons-4.8.1.tgz#44f6c81f609811d68d48a123eb5dcc477f8fbcb7" + integrity sha512-JRAuiqllnMsiZIO8OvBOeFconprC3cnMpJ9MvXrHh+H5co9rlg8/aSHQfLf5jKKe18lUgRaIwC2pz8YxH9VuCA== + dependencies: + "@ant-design/colors" "^6.0.0" + "@ant-design/icons-svg" "^4.3.0" + "@babel/runtime" "^7.11.2" + classnames "^2.2.6" + lodash "^4.17.15" + rc-util "^5.9.4" + "@ant-design/react-slick@~0.28.1": version "0.28.3" resolved "https://registry.yarnpkg.com/@ant-design/react-slick/-/react-slick-0.28.3.tgz#ad5cf1cf50363c1a3842874d69d0ce1f26696e71" @@ -4127,15 +4125,10 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001111: - version "1.0.30001271" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001271.tgz" - integrity sha512-BBruZFWmt3HFdVPS8kceTBIguKxu4f99n5JNp06OlPD/luoAMIaIK5ieV5YjnBLH3Nysai9sxj9rpJj4ZisXOA== - -caniuse-lite@^1.0.30001265: - version "1.0.30001269" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001269.tgz" - integrity sha512-UOy8okEVs48MyHYgV+RdW1Oiudl1H6KolybD6ZquD0VcrPSgj25omXO1S7rDydjpqaISCwA8Pyx+jUQKZwWO5w== +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001111, caniuse-lite@^1.0.30001265: + version "1.0.30001542" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001542.tgz" + integrity sha512-UrtAXVcj1mvPBFQ4sKd38daP8dEcXXr5sQe6QNNinaPd0iA/cxg9/l3VrSdL73jgw5sKyuQ6jNgiKO12W3SsVA== capture-exit@^2.0.0: version "2.0.0" @@ -7774,11 +7767,6 @@ ini@^1.3.5, ini@~1.3.0: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== -insert-css@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/insert-css/-/insert-css-2.0.0.tgz#eb5d1097b7542f4c79ea3060d3aee07d053880f4" - integrity sha1-610Ql7dUL0x56jBg067gfQU4gPQ= - internal-ip@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/internal-ip/-/internal-ip-4.3.0.tgz#845452baad9d2ca3b69c635a137acb9a0dad0907" @@ -13603,11 +13591,6 @@ tiny-warning@^1.0.0, tiny-warning@^1.0.3: resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754" integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA== -tinycolor2@^1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.1.tgz#f4fad333447bc0b07d4dc8e9209d8f39a8ac77e8" - integrity sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g= - tmpl@1.0.x: version "1.0.4" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" From 6887acf979046c5b1f7565ff01b0754e4f70c086 Mon Sep 17 00:00:00 2001 From: Gwendal Leclerc Date: Mon, 2 Oct 2023 23:08:35 +0200 Subject: [PATCH 8/9] fix: add timeout on yarn install + ignore script --- Dockerfile | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5c6fb9d..26d865a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ FROM node:16-bullseye AS build-frontend WORKDIR /wd ENV PARCEL_WORKERS 1 COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile +RUN yarn install --frozen-lockfile --ignore-scripts --network-timeout 300000 COPY tsconfig.json ./ COPY client/ ./client/ RUN yarn build diff --git a/Makefile b/Makefile index 2704734..dcf87db 100644 --- a/Makefile +++ b/Makefile @@ -129,7 +129,7 @@ optimize: build/smocker.tar.gz: $(MAKE) build - yarn install --frozen-lockfile + yarn install --frozen-lockfile --ignore-scripts --network-timeout 300000 yarn build cd build/; tar cvf smocker.tar.gz * From 5aa6d3bf26fa5f891353f20ba5905b431527e326 Mon Sep 17 00:00:00 2001 From: Gwendal Leclerc Date: Tue, 3 Oct 2023 01:12:38 +0200 Subject: [PATCH 9/9] feat: upgrade github actions + extract frontend build away from docker --- .dockerignore | 1 - .github/workflows/main.yml | 47 +++++++++++++------------------------- Dockerfile | 11 +-------- Makefile | 20 +++++----------- main.go | 6 ++--- package.json | 2 +- 6 files changed, 26 insertions(+), 61 deletions(-) diff --git a/.dockerignore b/.dockerignore index ae2c2b6..3ae0cfb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ .cache/ .git/ .vscode/ -build/ docs/ node_modules/ tests/ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2cf8957..8b3c360 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - id: nvm run: echo ::set-output name=NVMRC::$(cat .nvmrc) - - uses: actions/setup-node@v2.2.0 + - uses: actions/setup-node@v3 with: node-version: '${{ steps.nvm.outputs.NVMRC }}' cache: yarn @@ -42,7 +42,7 @@ jobs: - id: nvm run: echo ::set-output name=NVMRC::$(cat .nvmrc) - - uses: actions/setup-node@v2.2.0 + - uses: actions/setup-node@v3 with: node-version: '${{ steps.nvm.outputs.NVMRC }}' cache: yarn @@ -78,7 +78,7 @@ jobs: - id: nvm run: echo ::set-output name=NVMRC::$(cat .nvmrc) - - uses: actions/setup-node@v2.2.0 + - uses: actions/setup-node@v3 with: node-version: '${{ steps.nvm.outputs.NVMRC }}' cache: yarn @@ -88,13 +88,6 @@ jobs: with: go-version: '^1.21.1' - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - platforms: linux/amd64,linux/arm64 - - run: yarn install --frozen-lockfile - name: Build @@ -104,20 +97,11 @@ jobs: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} start-docker - if: startsWith(github.ref, 'refs/tags/') - run: make save-docker - - - if: startsWith(github.ref, 'refs/tags/') - uses: actions/upload-artifact@v2.2.4 + uses: actions/upload-artifact@v3 with: name: smocker-bin path: ./build/smocker.tar.gz - - if: startsWith(github.ref, 'refs/tags/') - uses: actions/upload-artifact@v2.2.4 - with: - name: smocker-docker - path: /tmp/smocker.tar - deploy: needs: [lint, test, build] if: startsWith(github.ref, 'refs/tags/') @@ -128,30 +112,31 @@ jobs: - id: extract_ref run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/}) - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: smocker-bin path: ./build - - uses: actions/download-artifact@v2 - with: - name: smocker-docker - path: /tmp - - - run: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} load-docker + - run: cd build && tar -xvf smocker.tar.gz - name: Docker login - uses: docker/login-action@v1.10.0 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 + - name: Deploy on Docker registry run: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} deploy-docker - name: Deploy on GitHub releases - uses: softprops/action-gh-release@v0.1.5 + uses: softprops/action-gh-release@v1 with: files: build/smocker.tar.gz - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + token: ${{ secrets.GH_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 26d865a..1fafbb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,18 +9,9 @@ COPY Makefile main.go ./ COPY server/ ./server/ RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build -FROM node:16-bullseye AS build-frontend -WORKDIR /wd -ENV PARCEL_WORKERS 1 -COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile --ignore-scripts --network-timeout 300000 -COPY tsconfig.json ./ -COPY client/ ./client/ -RUN yarn build - FROM alpine WORKDIR /opt EXPOSE 8080 8081 +COPY build/client client/ COPY --from=build-backend /go/src/github.com/Thiht/smocker/build/* /opt/ -COPY --from=build-frontend /wd/build/* /opt/ CMD ["/opt/smocker"] diff --git a/Makefile b/Makefile index dcf87db..a27bd53 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ clean: .PHONY: build-docker build-docker: - docker buildx build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest --platform linux/arm64,linux/amd64 . + docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest . docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG) .PHONY: start-docker @@ -129,9 +129,9 @@ optimize: build/smocker.tar.gz: $(MAKE) build - yarn install --frozen-lockfile --ignore-scripts --network-timeout 300000 + yarn install --frozen-lockfile --ignore-scripts yarn build - cd build/; tar cvf smocker.tar.gz * + cd build/; tar -cvf smocker.tar.gz * .PHONY: release release: build/smocker.tar.gz @@ -144,18 +144,10 @@ start-release: clean build/smocker.tar.gz start-caddy: $(CADDY) $(CADDY) run -.PHONY: save-docker -save-docker: - docker save --output /tmp/smocker.tar $(DOCKER_IMAGE):latest - -.PHONY: load-docker -load-docker: - docker load --input /tmp/smocker.tar - docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG) - .PHONY: deploy-docker deploy-docker: + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; docker buildx create --use ifdef IS_SEMVER - docker push $(DOCKER_IMAGE):latest + docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest --platform linux/arm/v7,linux/arm64/v8,linux/amd64 . endif - docker push $(DOCKER_IMAGE):$(DOCKER_TAG) + docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --platform linux/arm/v7,linux/arm64/v8,linux/amd64 . diff --git a/main.go b/main.go index bd61b78..e834bf6 100644 --- a/main.go +++ b/main.go @@ -9,9 +9,7 @@ import ( log "github.com/sirupsen/logrus" ) -var ( - appName, buildVersion, buildCommit, buildDate string // nolint -) +var appName, buildVersion, buildCommit, buildDate string // nolint func parseConfig() (c config.Config) { c.Build = config.Build{ @@ -28,7 +26,7 @@ func parseConfig() (c config.Config) { flag.StringVar(&c.ConfigBasePath, "config-base-path", "/", "Base path applied to Smocker UI") flag.IntVar(&c.ConfigListenPort, "config-listen-port", 8081, "Listening port of Smocker administration server") flag.IntVar(&c.MockServerListenPort, "mock-server-listen-port", 8080, "Listening port of Smocker mock server") - flag.StringVar(&c.StaticFiles, "static-files", ".", "Location of the static files to serve (index.html, etc.)") + flag.StringVar(&c.StaticFiles, "static-files", "client", "Location of the static files to serve (index.html, etc.)") flag.IntVar(&c.HistoryMaxRetention, "history-retention", 0, "Maximum number of calls to keep in the history per session (0 = no limit)") flag.StringVar(&c.PersistenceDirectory, "persistence-directory", "", "If defined, the directory where the sessions will be synchronized") flag.BoolVar(&c.TLSEnable, "tls-enable", false, "Enable TLS using the provided certificate") diff --git a/package.json b/package.json index e22a598..380bf8e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "targets": { "default": { - "distDir": "./build", + "distDir": "./build/client", "publicUrl": "./assets" } },