-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TT-1842] [TT-1608] Parrot Server (#1595)
Add Parrot Server
- Loading branch information
Showing
26 changed files
with
2,543 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Parrotserver Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- parrot/v* | ||
|
||
jobs: | ||
release: | ||
name: Build and Release | ||
runs-on: ubuntu-latest | ||
environment: integration | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 | ||
with: | ||
fetch-depth: 0 | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 | ||
with: | ||
aws-region: ${{ secrets.QA_AWS_REGION }} | ||
role-to-assume: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }} | ||
role-duration-seconds: 600 | ||
- name: Login to Amazon ECR | ||
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1 | ||
with: | ||
mask-password: 'true' | ||
env: | ||
AWS_REGION: ${{ secrets.QA_AWS_REGION }} | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- name: Goreleaser Release | ||
uses: goreleaser/goreleaser-action@v6 | ||
with: | ||
distribution: goreleaser-pro | ||
version: "~> v2" | ||
args: release --clean -f ./parrot/.goreleaser.yml | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} | ||
IMAGE_PREFIX: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/parrot | ||
IMAGE_TAG: ${{ github.ref_name}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,4 +77,9 @@ __debug* | |
.tool-versions | ||
|
||
import_keys_test.go | ||
tag.py | ||
tag.py | ||
|
||
parrot/*.json | ||
parrot/*.log | ||
# Executable | ||
parrot/parrot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Dockerfile | ||
*.md | ||
*.log | ||
.gitignore | ||
.golangci-lint.yml | ||
.goreleaser.yml | ||
.pre-commit-config.yaml | ||
*_test.go | ||
LICENSE | ||
.vscode/ | ||
dist/ | ||
.github/ | ||
save.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json | ||
version: 2 | ||
project_name: parrot | ||
|
||
monorepo: | ||
tag_prefix: parrot/ | ||
dir: parrot | ||
|
||
env: | ||
- IMG_PRE={{ if index .Env "IMAGE_PREFIX" }}{{ .Env.IMAGE_PREFIX }}{{ else }}local{{ end }} | ||
- TAG={{ if index .Env "IMAGE_TAG" }}{{ .Env.IMAGE_TAG }}{{ else }}latest{{ end }} | ||
|
||
# Build settings for binaries | ||
builds: | ||
- id: parrot | ||
main: ./cmd/main.go | ||
goos: | ||
- linux | ||
- darwin | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
ldflags: | ||
- '-s -w' | ||
|
||
archives: | ||
- formats: ['binary'] | ||
|
||
dockers: | ||
- id: linux-amd64-parrot | ||
goos: linux | ||
goarch: amd64 | ||
image_templates: | ||
- '{{ .Env.IMG_PRE }}/parrot:{{ .Tag }}' | ||
- '{{ .Env.IMG_PRE }}/parrot:latest' | ||
build_flag_templates: | ||
- --platform=linux/amd64 | ||
- --pull | ||
- --label=org.opencontainers.image.created={{.Date}} | ||
- --label=org.opencontainers.image.title={{.ProjectName}} | ||
- --label=org.opencontainers.image.revision={{.FullCommit}} | ||
- --label=org.opencontainers.image.version={{.Version}} | ||
- id: linux-arm64-parrot | ||
goos: linux | ||
goarch: arm64 | ||
image_templates: | ||
- '{{ .Env.IMG_PRE }}/parrot:{{ .Tag }}-arm64' | ||
- '{{ .Env.IMG_PRE }}/parrot:latest-arm64' | ||
build_flag_templates: | ||
- --platform=linux/arm64 | ||
- --pull | ||
- --label=org.opencontainers.image.created={{.Date}} | ||
- --label=org.opencontainers.image.title={{.ProjectName}} | ||
- --label=org.opencontainers.image.revision={{.FullCommit}} | ||
- --label=org.opencontainers.image.version={{.Version}} | ||
|
||
before: | ||
hooks: | ||
- cd parrot && go mod tidy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM scratch | ||
COPY parrotserver /parrotserver | ||
ENTRYPOINT [ "parrotserver" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Default test log level (can be overridden) | ||
PARROT_TEST_LOG_LEVEL ?= "" | ||
|
||
# Pass TEST_LOG_LEVEL as a flag to go test | ||
TEST_ARGS ?= -testLogLevel=$(PARROT_TEST_LOG_LEVEL) | ||
|
||
.PHONY: lint | ||
lint: | ||
golangci-lint --color=always run ./... --fix -v | ||
|
||
.PHONY: test | ||
test: | ||
go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest | ||
set -euo pipefail | ||
go test $(TEST_ARGS) -json -cover -coverprofile cover.out -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt | ||
|
||
.PHONY: test_race | ||
test_race: | ||
go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest | ||
set -euo pipefail | ||
go test $(TEST_ARGS) -json -cover -count=1 -race -coverprofile cover.out -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt | ||
|
||
.PHONY: test_unit | ||
test_unit: | ||
go test $(TEST_ARGS) -coverprofile cover.out ./... | ||
|
||
.PHONY: bench | ||
bench: | ||
go test $(TEST_ARGS) -bench=. -run=^$$ ./... | ||
|
||
.PHONY: build | ||
build: | ||
go build -o ./parrot ./cmd | ||
|
||
.PHONY: goreleaser | ||
goreleaser: | ||
cd .. && goreleaser build --snapshot --clean -f ./parrot/.goreleaser.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Parrot Server | ||
|
||
A simple, high-performing mockserver that can dynamically build new routes with customized responses, parroting back whatever you tell it to. | ||
|
||
## Features | ||
|
||
* Simplistic and fast design | ||
* Run within your Go code, through a small binary, or in a minimal Docker container | ||
* Easily record all incoming requests to the server to programmatically react to | ||
|
||
## Use | ||
|
||
See our runnable examples in [examples_test.go](./examples_test.go) to see how to use Parrot programmatically. | ||
|
||
## Run | ||
|
||
```sh | ||
go run ./cmd | ||
go run ./cmd -h # See all config options | ||
``` | ||
|
||
## Test | ||
|
||
```sh | ||
make test | ||
make test PARROT_TEST_LOG_LEVEL=trace # Set log level for tests | ||
make test_race # Test with -race flag enabled | ||
make bench # Benchmark | ||
``` | ||
|
||
## Build | ||
|
||
```sh | ||
make goreleaser # Uses goreleaser to build binaries and docker containers | ||
``` |
Oops, something went wrong.