Skip to content

Commit

Permalink
Merge branch 'main' into compress-archives
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiht authored Mar 15, 2024
2 parents a932d9f + a5eb31a commit 21c0924
Show file tree
Hide file tree
Showing 67 changed files with 1,489 additions and 9,387 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.cache/
.git/
.vscode/
docs/
node_modules/
tests/
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.parcel-cache/
.vscode/
build/
docs/.vuepress/dist/
node_modules/
61 changes: 30 additions & 31 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ name: CI
on:
push:
branches:
- master
- main
tags:
- '*.*.*' # semver, will override latest
- '*-preview' # preview, won't override latest
pull_request:
branches:
- master
- main
workflow_dispatch: # Allow manual trigger

permissions:
contents: write
packages: write

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4

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

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
node-version-file: .nvmrc
cache: yarn

- run: yarn install --frozen-lockfile
Expand All @@ -34,23 +36,22 @@ jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

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

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
node-version-file: .nvmrc
cache: yarn


- name: Setup Go environment
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '^1.21.1'
go-version: stable

- run: yarn install --frozen-lockfile

Expand All @@ -64,29 +65,27 @@ jobs:
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- 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@v3
- uses: actions/setup-node@v4
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
node-version-file: .nvmrc
cache: yarn

- name: Setup Go environment
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '^1.21.1'
go-version: stable

- run: yarn install --frozen-lockfile

Expand All @@ -97,7 +96,7 @@ jobs:
make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} start-docker
- if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: smocker-bin
path: ./build/smocker.tar.gz
Expand All @@ -106,13 +105,14 @@ jobs:
needs: [lint, test, build]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

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

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: smocker-bin
path: ./build
Expand All @@ -122,22 +122,21 @@ jobs:
- name: Docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- 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@v1
uses: softprops/action-gh-release@v2
with:
files: build/smocker.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
.vscode/
build/
coverage/
docs/.vuepress/dist/
node_modules/
sessions/
smocker
smocker.test
vendor/
yarn-error.log
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM golang:1.18-alpine AS build-backend
ARG GO_VERSION=1.22
FROM golang:${GO_VERSION}-alpine AS build-backend
RUN apk add --no-cache make
ARG VERSION=snapshot
ARG COMMIT
WORKDIR /go/src/github.com/Thiht/smocker
WORKDIR /go/src/smocker
COPY go.mod go.sum ./
RUN go mod download
COPY Makefile main.go ./
COPY server/ ./server/
RUN make VERSION=$VERSION COMMIT=$COMMIT RELEASE=1 build

FROM alpine
LABEL org.opencontainers.image.source="https://github.com/smocker-dev/smocker"
WORKDIR /opt
EXPOSE 8080 8081
COPY build/client client/
COPY --from=build-backend /go/src/github.com/Thiht/smocker/build/* /opt/
COPY --from=build-backend /go/src/smocker/build/* /opt/
CMD ["/opt/smocker"]
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ ifeq ($(RELEASE), 1)
endif
GO_LDFLAGS:=-ldflags="$(GO_LDFLAGS)"

DOCKER_ACCOUNT?=thiht
DOCKER_IMAGE=$(DOCKER_ACCOUNT)/$(APPNAME)
DOCKER_IMAGE=ghcr.io/smocker-dev/smocker

# See: https://docs.docker.com/engine/reference/commandline/tag/#extended-description
# A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes.
Expand Down Expand Up @@ -63,7 +62,7 @@ start: $(REFLEX)

.PHONY: build
build:
go build $(GO_LDFLAGS) -o ./build/$(APPNAME)
go build -trimpath $(GO_LDFLAGS) -o ./build/$(APPNAME)

.PHONY: lint
lint: $(GOLANGCILINT)
Expand Down Expand Up @@ -146,8 +145,9 @@ start-caddy: $(CADDY)

.PHONY: deploy-docker
deploy-docker:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use
ifdef IS_SEMVER
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 .
docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag $(DOCKER_IMAGE):latest .
endif
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 .
docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag $(DOCKER_IMAGE):$(DOCKER_TAG) .
31 changes: 10 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<h1 align="center">
<img src="docs/.vuepress/public/logo/logo-horizontal.png" alt="Smocker" height="100" title="Smocker logo by mandyellow" />
<img src="./docs/logo-horizontal.png" alt="Smocker" height="100" title="Smocker logo by mandyellow" />
</h1>

[![CI](https://github.com/Thiht/smocker/actions/workflows/main.yml/badge.svg)](https://github.com/Thiht/smocker/actions/workflows/main.yml)
[![Netlify Status](https://img.shields.io/netlify/61d4e090-b242-419f-8d69-e9dee3d50a37?logo=netlify)](https://app.netlify.com/sites/smocker/deploys)
[![Docker Repository](https://img.shields.io/badge/docker-thiht%2Fsmocker-blue?logo=docker)](https://hub.docker.com/r/thiht/smocker)
[![Github Release](https://img.shields.io/github/v/release/Thiht/smocker.svg?logo=github)](https://github.com/Thiht/smocker/releases/latest)
[![Go Report Card](https://goreportcard.com/badge/github.com/Thiht/smocker)](https://goreportcard.com/report/github.com/Thiht/smocker)
[![License](https://img.shields.io/github/license/Thiht/smocker?logo=open-source-initiative)](https://github.com/Thiht/smocker/blob/master/LICENSE)
[![CI](https://github.com/smocker-dev/smocker/actions/workflows/main.yml/badge.svg)](https://github.com/smocker-dev/smocker/actions/workflows/main.yml)
[![Docker Repository](https://img.shields.io/badge/ghcr.io%2Fsmocker--dev%2Fsmocker-blue?logo=docker&label=docker)](https://github.com/smocker-dev/smocker/pkgs/container/smocker)
[![Github Release](https://img.shields.io/github/v/release/smocker-dev/smocker.svg?logo=github)](https://github.com/smocker-dev/smocker/releases/latest)
[![Go Report Card](https://goreportcard.com/badge/github.com/smocker-dev/smocker)](https://goreportcard.com/report/github.com/smocker-dev/smocker)
[![License](https://img.shields.io/github/license/smocker-dev/smocker?logo=open-source-initiative)](https://github.com/smocker-dev/smocker/blob/main/LICENSE)

**Smocker** (server mock) is a simple and efficient HTTP mock server.

Expand All @@ -25,7 +24,6 @@ The documentation is available on [smocker.dev](https://smocker.dev).
- [Development](#development)
- [Backend](#backend)
- [Frontend](#frontend)
- [Documentation](#documentation)
- [Docker](#docker)
- [Caddy](#caddy)
- [HTTPS](#https)
Expand All @@ -42,15 +40,15 @@ docker run -d \
-p 8080:8080 \
-p 8081:8081 \
--name smocker \
thiht/smocker
ghcr.io/smocker-dev/smocker
```

### Manual Deployment

```sh
# This will be the deployment folder for the Smocker instance
mkdir -p /opt/smocker && cd /opt/smocker
wget -P /tmp https://github.com/Thiht/smocker/releases/latest/download/smocker.tar.gz
wget -P /tmp https://github.com/smocker-dev/smocker/releases/latest/download/smocker.tar.gz
tar xf /tmp/smocker.tar.gz
nohup ./smocker -mock-server-listen-port=8080 -config-listen-port=8081 &
```
Expand All @@ -65,9 +63,9 @@ curl localhost:8081/version

Smocker exposes a configuration user interface. You can access it in your web browser on http://localhost:8081/.

![History](docs/.vuepress/public/screenshots/screenshot-history.png)
![History](docs/screenshots/screenshot-history.png)

![Mocks](docs/.vuepress/public/screenshots/screenshot-mocks.png)
![Mocks](docs/screenshots/screenshot-mocks.png)

## Usage

Expand Down Expand Up @@ -160,15 +158,6 @@ The frontend is written with TypeScript and React. You can use the following com
- `yarn test`: execute unit tests
- `yarn test:watch`: execute unit tests, with live reload

### Documentation

The documentation is written in Markdown using [Vuepress](https://vuepress.vuejs.org/). You can use the following commands to manage the documentation:

- `yarn install`: install the dependencies
- `yarn docs:generate`: regenerate documentation screenshots (require the whole application to be started on the default ports)
- `yarn docs:dev`: start the documentation in development mode, with live reload
- `yarn docs:build`: generate the static production documentation

### Docker

The application can be packaged as a standalone Docker image. You can use the following commands to manage the development lifecycle:
Expand Down
2 changes: 1 addition & 1 deletion client/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const App = () => (
Smocker version {window.version} &ndash; MIT Licensed
<br />
<a
href="https://github.com/Thiht/smocker"
href="https://github.com/smocker-dev/smocker"
title="Smocker on GitHub"
target="_blank"
rel="noreferrer"
Expand Down
Loading

0 comments on commit 21c0924

Please sign in to comment.