Skip to content

Commit 43e4591

Browse files
authored
Merge pull request #282 from Thiht/arm
Arm support
2 parents 32ddbd1 + 5aa6d3b commit 43e4591

File tree

11 files changed

+125
-150
lines changed

11 files changed

+125
-150
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.cache/
22
.git/
33
.vscode/
4-
build/
54
docs/
65
node_modules/
76
tests/

.github/workflows/main.yml

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
lint:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
1919

2020
- id: nvm
2121
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
2222

23-
- uses: actions/setup-node@v2.2.0
23+
- uses: actions/setup-node@v3
2424
with:
2525
node-version: '${{ steps.nvm.outputs.NVMRC }}'
2626
cache: yarn
@@ -35,22 +35,22 @@ jobs:
3535
test:
3636
runs-on: ubuntu-latest
3737
steps:
38-
- uses: actions/checkout@v2
38+
- uses: actions/checkout@v4
3939
with:
4040
fetch-depth: 0
4141

4242
- id: nvm
4343
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
4444

45-
- uses: actions/setup-node@v2.2.0
45+
- uses: actions/setup-node@v3
4646
with:
4747
node-version: '${{ steps.nvm.outputs.NVMRC }}'
4848
cache: yarn
4949

5050
- name: Setup Go environment
51-
uses: actions/setup-go@v2.1.3
51+
uses: actions/setup-go@v4
5252
with:
53-
go-version: '^1.18.0'
53+
go-version: '^1.21.1'
5454

5555
- run: yarn install --frozen-lockfile
5656

@@ -70,26 +70,23 @@ jobs:
7070
build:
7171
runs-on: ubuntu-latest
7272
steps:
73-
- uses: actions/checkout@v2
73+
- uses: actions/checkout@v4
7474

7575
- id: extract_ref
7676
run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/})
7777

7878
- id: nvm
7979
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
8080

81-
- uses: actions/setup-node@v2.2.0
81+
- uses: actions/setup-node@v3
8282
with:
8383
node-version: '${{ steps.nvm.outputs.NVMRC }}'
8484
cache: yarn
8585

8686
- name: Setup Go environment
87-
uses: actions/setup-go@v2.1.3
87+
uses: actions/setup-go@v4
8888
with:
89-
go-version: '^1.18.0'
90-
91-
- uses: satackey/[email protected]
92-
continue-on-error: true
89+
go-version: '^1.21.1'
9390

9491
- run: yarn install --frozen-lockfile
9592

@@ -100,54 +97,46 @@ jobs:
10097
make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} start-docker
10198
10299
- if: startsWith(github.ref, 'refs/tags/')
103-
run: make save-docker
104-
105-
- if: startsWith(github.ref, 'refs/tags/')
106-
uses: actions/[email protected]
100+
uses: actions/upload-artifact@v3
107101
with:
108102
name: smocker-bin
109103
path: ./build/smocker.tar.gz
110104

111-
- if: startsWith(github.ref, 'refs/tags/')
112-
uses: actions/[email protected]
113-
with:
114-
name: smocker-docker
115-
path: /tmp/smocker.tar
116-
117105
deploy:
118106
needs: [lint, test, build]
119107
if: startsWith(github.ref, 'refs/tags/')
120108
runs-on: ubuntu-latest
121109
steps:
122-
- uses: actions/checkout@v2
110+
- uses: actions/checkout@v4
123111

124112
- id: extract_ref
125113
run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/})
126114

127-
- uses: actions/download-artifact@v2
115+
- uses: actions/download-artifact@v3
128116
with:
129117
name: smocker-bin
130118
path: ./build
131119

132-
- uses: actions/download-artifact@v2
133-
with:
134-
name: smocker-docker
135-
path: /tmp
136-
137-
- run: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} load-docker
120+
- run: cd build && tar -xvf smocker.tar.gz
138121

139122
- name: Docker login
140-
uses: docker/login-action@v1.10.0
123+
uses: docker/login-action@v3
141124
with:
142125
username: ${{ secrets.DOCKER_USERNAME }}
143126
password: ${{ secrets.DOCKER_PASSWORD }}
144127

128+
- name: Set up QEMU
129+
uses: docker/setup-qemu-action@v3
130+
- name: Set up Docker Buildx
131+
uses: docker/setup-buildx-action@v3
132+
with:
133+
platforms: linux/amd64,linux/arm64
134+
145135
- name: Deploy on Docker registry
146136
run: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} deploy-docker
147137

148138
- name: Deploy on GitHub releases
149-
uses: softprops/action-gh-release@v0.1.5
139+
uses: softprops/action-gh-release@v1
150140
with:
151141
files: build/smocker.tar.gz
152-
env:
153-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
142+
token: ${{ secrets.GH_TOKEN }}

Dockerfile

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,9 @@ COPY Makefile main.go ./
99
COPY server/ ./server/
1010
RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build
1111

12-
FROM node:16-alpine AS build-frontend
13-
WORKDIR /wd
14-
ENV PARCEL_WORKERS 1
15-
# node-gyp dependencies: https://github.com/nodejs/node-gyp#on-unix
16-
RUN apk add --no-cache g++ make python3
17-
COPY package.json yarn.lock ./
18-
RUN yarn install --frozen-lockfile
19-
COPY tsconfig.json ./
20-
COPY client/ ./client/
21-
RUN yarn build
22-
2312
FROM alpine
2413
WORKDIR /opt
2514
EXPOSE 8080 8081
15+
COPY build/client client/
2616
COPY --from=build-backend /go/src/github.com/Thiht/smocker/build/* /opt/
27-
COPY --from=build-frontend /wd/build/* /opt/
2817
CMD ["/opt/smocker"]

Makefile

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ REFLEX=$(GOPATH)/bin/reflex
3535
$(REFLEX):
3636
go install github.com/cespare/reflex@latest
3737

38-
GOLANGCILINTVERSION:=1.32.0
38+
GOLANGCILINTVERSION:=1.54.2
3939
GOLANGCILINT=$(GOPATH)/bin/golangci-lint
4040
$(GOLANGCILINT):
4141
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v$(GOLANGCILINTVERSION)
@@ -129,9 +129,9 @@ optimize:
129129

130130
build/smocker.tar.gz:
131131
$(MAKE) build
132-
yarn install --frozen-lockfile
132+
yarn install --frozen-lockfile --ignore-scripts
133133
yarn build
134-
cd build/; tar cvf smocker.tar.gz *
134+
cd build/; tar -cvf smocker.tar.gz *
135135

136136
.PHONY: release
137137
release: build/smocker.tar.gz
@@ -144,18 +144,10 @@ start-release: clean build/smocker.tar.gz
144144
start-caddy: $(CADDY)
145145
$(CADDY) run
146146

147-
.PHONY: save-docker
148-
save-docker:
149-
docker save --output /tmp/smocker.tar $(DOCKER_IMAGE):latest
150-
151-
.PHONY: load-docker
152-
load-docker:
153-
docker load --input /tmp/smocker.tar
154-
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG)
155-
156147
.PHONY: deploy-docker
157148
deploy-docker:
149+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; docker buildx create --use
158150
ifdef IS_SEMVER
159-
docker push $(DOCKER_IMAGE):latest
151+
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 .
160152
endif
161-
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
153+
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 .

main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import (
99
log "github.com/sirupsen/logrus"
1010
)
1111

12-
var (
13-
appName, buildVersion, buildCommit, buildDate string // nolint
14-
)
12+
var appName, buildVersion, buildCommit, buildDate string // nolint
1513

1614
func parseConfig() (c config.Config) {
1715
c.Build = config.Build{
@@ -28,7 +26,7 @@ func parseConfig() (c config.Config) {
2826
flag.StringVar(&c.ConfigBasePath, "config-base-path", "/", "Base path applied to Smocker UI")
2927
flag.IntVar(&c.ConfigListenPort, "config-listen-port", 8081, "Listening port of Smocker administration server")
3028
flag.IntVar(&c.MockServerListenPort, "mock-server-listen-port", 8080, "Listening port of Smocker mock server")
31-
flag.StringVar(&c.StaticFiles, "static-files", ".", "Location of the static files to serve (index.html, etc.)")
29+
flag.StringVar(&c.StaticFiles, "static-files", "client", "Location of the static files to serve (index.html, etc.)")
3230
flag.IntVar(&c.HistoryMaxRetention, "history-retention", 0, "Maximum number of calls to keep in the history per session (0 = no limit)")
3331
flag.StringVar(&c.PersistenceDirectory, "persistence-directory", "", "If defined, the directory where the sessions will be synchronized")
3432
flag.BoolVar(&c.TLSEnable, "tls-enable", false, "Enable TLS using the provided certificate")

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
},
1818
"targets": {
1919
"default": {
20-
"distDir": "./build",
20+
"distDir": "./build/client",
2121
"publicUrl": "./assets"
2222
}
2323
},
2424
"dependencies": {
25-
"@ant-design/icons": "^4.1.0",
25+
"@ant-design/icons": "^4.x",
2626
"antd": "^4.16.9",
2727
"classnames": "^2.2.6",
2828
"codemirror": "^5.55.0",
@@ -110,4 +110,4 @@
110110
"jest": {
111111
"preset": "ts-jest"
112112
}
113-
}
113+
}

server/middlewares.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/json"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net"
1211
"net/http"
1312
"runtime"
@@ -66,7 +65,7 @@ func HistoryMiddleware(s services.Mocks) echo.MiddlewareFunc {
6665
if err != nil {
6766
log.WithError(err).Error("Unable to uncompress response body")
6867
} else {
69-
responseBytes, err = ioutil.ReadAll(r)
68+
responseBytes, err = io.ReadAll(r)
7069
if err != nil {
7170
log.WithError(err).Error("Unable to read uncompressed response body")
7271
responseBytes = responseBody.Bytes()
@@ -104,14 +103,9 @@ func HistoryMiddleware(s services.Mocks) echo.MiddlewareFunc {
104103
func loggerMiddleware() echo.MiddlewareFunc {
105104
return func(next echo.HandlerFunc) echo.HandlerFunc {
106105
return func(c echo.Context) error {
107-
req, res := c.Request(), c.Response()
106+
req := c.Request()
108107

109108
start := time.Now()
110-
if err := next(c); err != nil {
111-
c.Error(err)
112-
}
113-
end := time.Now()
114-
115109
p := req.URL.Path
116110
if p == "" {
117111
p = "/"
@@ -123,18 +117,29 @@ func loggerMiddleware() echo.MiddlewareFunc {
123117
}
124118

125119
headers := fmt.Sprintf("%+v", req.Header)
120+
126121
entry := log.WithFields(log.Fields{
127122
"start": start.Format(time.RFC3339),
128-
"end": end.Format(time.RFC3339),
129123
"remote-ip": c.RealIP(),
130124
"host": req.Host,
131125
"uri": req.RequestURI,
132126
"method": req.Method,
133127
"path": p,
134128
"headers": headers,
129+
"bytes-in": bytesIn,
130+
})
131+
entry.Debug("Handling request...")
132+
133+
if err := next(c); err != nil {
134+
c.Error(err)
135+
}
136+
137+
res := c.Response()
138+
end := time.Now()
139+
entry = entry.WithFields(log.Fields{
140+
"end": end.Format(time.RFC3339),
135141
"status": res.Status,
136142
"latency": end.Sub(start).String(),
137-
"bytes-in": bytesIn,
138143
"bytes-out": res.Size,
139144
})
140145

server/services/mocks.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ func (s *mocks) GetHistoryByPath(sessionID, filterPath string) (types.History, e
183183
}
184184

185185
func (s *mocks) NewSession(name string) *types.Session {
186-
187186
if strings.TrimSpace(name) == "" {
188187
name = fmt.Sprintf("Session #%d", len(s.sessions)+1)
189188
}

0 commit comments

Comments
 (0)