Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm support #282

Merged
merged 10 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.cache/
.git/
.vscode/
build/
docs/
node_modules/
tests/
59 changes: 24 additions & 35 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ 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)

- uses: actions/setup-node@v2.2.0
- uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
cache: yarn
Expand All @@ -35,22 +35,22 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- 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

- 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

Expand All @@ -70,26 +70,23 @@ 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##*/})

- 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

- name: Setup Go environment
uses: actions/setup-go@v2.1.3
uses: actions/setup-go@v4
with:
go-version: '^1.18.0'

- uses: satackey/[email protected]
continue-on-error: true
go-version: '^1.21.1'

- run: yarn install --frozen-lockfile

Expand All @@ -100,54 +97,46 @@ 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/[email protected]
uses: actions/upload-artifact@v3
with:
name: smocker-bin
path: ./build/smocker.tar.gz

- if: startsWith(github.ref, 'refs/tags/')
uses: actions/[email protected]
with:
name: smocker-docker
path: /tmp/smocker.tar

deploy:
needs: [lint, test, build]
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##*/})

- 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 }}
13 changes: 1 addition & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,9 @@ COPY Makefile main.go ./
COPY server/ ./server/
RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build

FROM node:16-alpine 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 ./
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"]
20 changes: 6 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -129,9 +129,9 @@ optimize:

build/smocker.tar.gz:
$(MAKE) build
yarn install --frozen-lockfile
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
Expand All @@ -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 .
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
},
"targets": {
"default": {
"distDir": "./build",
"distDir": "./build/client",
"publicUrl": "./assets"
}
},
"dependencies": {
"@ant-design/icons": "^4.1.0",
"@ant-design/icons": "^4.x",
"antd": "^4.16.9",
"classnames": "^2.2.6",
"codemirror": "^5.55.0",
Expand Down Expand Up @@ -110,4 +110,4 @@
"jest": {
"preset": "ts-jest"
}
}
}
25 changes: 15 additions & 10 deletions server/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"runtime"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = "/"
Expand All @@ -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,
})

Expand Down
1 change: 0 additions & 1 deletion server/services/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading
Loading