Skip to content

Commit

Permalink
[TT-1842] [TT-1608] Parrot Server (#1595)
Browse files Browse the repository at this point in the history
Add Parrot Server
  • Loading branch information
kalverra authored Jan 24, 2025
1 parent 72387bd commit 221d260
Show file tree
Hide file tree
Showing 26 changed files with 2,543 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
go test -timeout 20m -json -parallel 2 -cover -covermode=atomic -coverprofile=unit-test-coverage.out $(go list ./... | grep /docker/test_env) -run '${{ matrix.test.tests }}' 2>&1 | tee /tmp/gotest.log | ../gotestloghelper -ci
- name: Publish Artifacts
if: failure()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@v4
with:
name: test-logs
path: ./lib/logs
8 changes: 4 additions & 4 deletions .github/workflows/framework-golden-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
config: smoke.toml
count: 1
timeout: 10m
- name: TestSmoke
- name: TestSmokeLimitedResources
config: smoke_limited_resources.toml
count: 1
timeout: 10m
Expand Down Expand Up @@ -81,9 +81,9 @@ jobs:
- 'framework/**'
- '.github/workflows/framework-golden-tests.yml'
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.22.8
go-version: 1.23
- name: Cache Go modules
uses: actions/cache@v3
with:
Expand All @@ -104,7 +104,7 @@ jobs:
go test -timeout ${{ matrix.test.timeout }} -v -count ${{ matrix.test.count }} -run ${{ matrix.test.name }}
- name: Upload Logs
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: container-logs-${{ matrix.test.name }}
path: framework/examples/myproject/logs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
src:
- 'framework/**'
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.22.8
go-version: 1.23
- name: Cache Go modules
uses: actions/cache@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate-go-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
rm filtered_folders.json
- name: Upload costs as artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@v4
with:
name: generation-costs
path: ./costs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/k8s-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
run_setup: false
- name: Upload test log
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-log
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
run_setup: false
- name: Upload test log
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@v4
if: failure()
with:
name: remote-runner-test-log
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jobs:
path: ./tools/asciitable/
- name: workflowresultparser
path: ./tools/workflowresultparser/
- name: parrot
path: ./parrot/
steps:
- name: Check out Code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
Expand All @@ -98,7 +100,7 @@ jobs:
run: test -f ${{ matrix.project.path }}golangci-lint-report.xml || true
- name: Store lint report artifact
if: always()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@v4
with:
name: golangci-lint-report-${{ matrix.project.name }}
path: ${{ matrix.project.path }}golangci-lint-report.xml
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/parrot-release.yml
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}}
4 changes: 2 additions & 2 deletions .github/workflows/rc-breaking-changes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Go 1.23.3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.3'
go-version: 1.23
- name: Install gorelease tool
run: |
go install golang.org/x/exp/cmd/gorelease@latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-go-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.3'
go-version: 1.23
- name: Install gorelease tool
run: |
go install golang.org/x/exp/cmd/gorelease@latest
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
path: ./tools/flakeguard/
- name: workflowresultparser
path: ./tools/workflowresultparser/
- name: parrot
path: ./parrot/
runs-on: ubuntu-latest
name: ${{ matrix.project.name }} unit tests
steps:
Expand All @@ -52,7 +54,7 @@ jobs:
make test_unit"
- name: Publish Artifacts
if: failure()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
uses: actions/upload-artifact@v4
with:
name: test-logs
path: /tmp/gotest.log
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ __debug*
.tool-versions

import_keys_test.go
tag.py
tag.py

parrot/*.json
parrot/*.log
# Executable
parrot/parrot
13 changes: 13 additions & 0 deletions parrot/.dockerignore
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
59 changes: 59 additions & 0 deletions parrot/.goreleaser.yaml
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
3 changes: 3 additions & 0 deletions parrot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY parrotserver /parrotserver
ENTRYPOINT [ "parrotserver" ]
37 changes: 37 additions & 0 deletions parrot/Makefile
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
35 changes: 35 additions & 0 deletions parrot/README.md
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
```
Loading

0 comments on commit 221d260

Please sign in to comment.