Skip to content

Commit ae3e1e6

Browse files
committed
Merge branch 'main' into grafana-annotations
2 parents 84170b1 + c4931eb commit ae3e1e6

File tree

12 files changed

+108
-34
lines changed

12 files changed

+108
-34
lines changed

.github/workflows/parrot-release.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ jobs:
3131
mask-password: 'true'
3232
env:
3333
AWS_REGION: ${{ secrets.AWS_REGION }}
34+
- name: Login to Docker Hub
35+
uses: docker/login-action@v3
36+
with:
37+
username: kalverra
38+
password: ${{ secrets.KALVERRA_DOCKER_PASSWORD }}
3439
- name: Set up Go
3540
uses: actions/setup-go@v5
3641
with:
3742
go-version: stable
43+
cache-dependency-path: ./parrot/go.mod
3844
- name: Goreleaser Release
3945
uses: goreleaser/goreleaser-action@v6
4046
with:
@@ -45,4 +51,6 @@ jobs:
4551
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4652
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
4753
IMAGE_PREFIX: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
48-
IMAGE_TAG: ${{ github.ref_name}}
54+
IMAGE_TAG: ${{ github.ref_name }}
55+
DOCKER_USERNAME: kalverra
56+
DOCKER_PASSWORD: ${{ secrets.KALVERRA_DOCKER_PASSWORD }}

parrot/.changeset/v0.4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Public docker releases for parrot

parrot/.changeset/v0.4.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes release env vars

parrot/.changeset/v0.4.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updates parrot to Go 1.24.0

parrot/.changeset/v0.4.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes dockerhub versioning

parrot/.changeset/v0.5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Properly configures parrot's health check

parrot/.goreleaser.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ env:
1616
builds:
1717
- id: parrot
1818
main: ./cmd/main.go
19+
ldflags:
20+
- -s
21+
- -w
22+
- -X github.com/smartcontractkit/chainlink-testing-framework/parrot.version={{.Version}}
23+
- -X github.com/smartcontractkit/chainlink-testing-framework/parrot.commit={{.ShortCommit}}
24+
- -X github.com/smartcontractkit/chainlink-testing-framework/parrot.date={{.CommitDate}}
25+
- -X github.com/smartcontractkit/chainlink-testing-framework/parrot.builtBy=goreleaser
1926
goos:
2027
- linux
2128
- darwin
@@ -34,6 +41,8 @@ dockers:
3441
image_templates:
3542
- '{{ .Env.IMG_PRE }}/parrot:{{ .Tag }}-amd64'
3643
- '{{ .Env.IMG_PRE }}/parrot:latest-amd64'
44+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:{{ .Tag }}-amd64{{ end }}'
45+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:latest-amd64{{ end }}'
3746
build_flag_templates:
3847
- --platform=linux/amd64
3948
- --pull
@@ -47,6 +56,8 @@ dockers:
4756
image_templates:
4857
- '{{ .Env.IMG_PRE }}/parrot:{{ .Tag }}-arm64'
4958
- '{{ .Env.IMG_PRE }}/parrot:latest-arm64'
59+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:{{ .Tag }}-arm64{{ end }}'
60+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:latest-arm64{{ end }}'
5061
build_flag_templates:
5162
- --platform=linux/arm64
5263
- --pull
@@ -64,6 +75,14 @@ docker_manifests:
6475
image_templates:
6576
- '{{ .Env.IMG_PRE }}/parrot:latest-amd64'
6677
- '{{ .Env.IMG_PRE }}/parrot:latest-arm64'
78+
- name_template: '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:{{ .Tag }}{{ end }}'
79+
image_templates:
80+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:{{ .Tag }}-amd64{{ end }}'
81+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:{{ .Tag }}-arm64{{ end }}'
82+
- name_template: '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:latest{{ end }}'
83+
image_templates:
84+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:latest-amd64{{ end }}'
85+
- '{{ if ne .Env.IMG_PRE "local" }}{{ .Env.DOCKER_USERNAME }}/parrot:latest-arm64{{ end }}'
6786

6887
before:
6988
hooks:

parrot/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
FROM scratch
22

33
COPY parrot /parrot
4-
ENV PARROT_PORT 80
5-
ENV PARROT_TRACE true
4+
ENV PARROT_PORT=80
5+
ENV PARROT_TRACE=true
66
EXPOSE 80
7+
8+
HEALTHCHECK --timeout=3s --start-interval=10ms --start-period=5s CMD [ "/parrot", "health" ]
9+
710
ENTRYPOINT [ "/parrot" ]

parrot/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ fuzz:
3737
build:
3838
cd .. && goreleaser release --snapshot --clean -f ./parrot/.goreleaser.yaml
3939
echo "Build done, check in parrot/dist for binaries"
40-

parrot/cmd/main.go

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"context"
5+
"fmt"
6+
"net/http"
57
"os"
68
"os/signal"
79
"strconv"
@@ -25,34 +27,36 @@ func main() {
2527
recorders []string
2628
)
2729

28-
rootCmd := &cobra.Command{
29-
Use: "parrot",
30-
Short: "A server that can register and parrot back dynamic requests",
31-
PreRun: func(cmd *cobra.Command, args []string) {
32-
// Check environment variables if flags are not set
33-
if !cmd.Flags().Changed("port") {
34-
if envPort, err := strconv.Atoi(os.Getenv("PARROT_PORT")); err == nil {
35-
port = envPort
36-
}
37-
}
38-
if !cmd.Flags().Changed("debug") {
39-
debug = os.Getenv("PARROT_DEBUG") == "true"
40-
}
41-
if !cmd.Flags().Changed("trace") {
42-
trace = os.Getenv("PARROT_TRACE") == "true"
43-
}
44-
if !cmd.Flags().Changed("silent") {
45-
silent = os.Getenv("PARROT_SILENT") == "true"
30+
preRun := func(cmd *cobra.Command, args []string) {
31+
// Check environment variables if flags are not set
32+
if !cmd.Flags().Changed("port") {
33+
if envPort, err := strconv.Atoi(os.Getenv("PARROT_PORT")); err == nil {
34+
port = envPort
4635
}
47-
if !cmd.Flags().Changed("json") {
48-
json = os.Getenv("PARROT_JSON") == "true"
36+
}
37+
if !cmd.Flags().Changed("debug") {
38+
debug = os.Getenv("PARROT_DEBUG") == "true"
39+
}
40+
if !cmd.Flags().Changed("trace") {
41+
trace = os.Getenv("PARROT_TRACE") == "true"
42+
}
43+
if !cmd.Flags().Changed("silent") {
44+
silent = os.Getenv("PARROT_SILENT") == "true"
45+
}
46+
if !cmd.Flags().Changed("json") {
47+
json = os.Getenv("PARROT_JSON") == "true"
48+
}
49+
if !cmd.Flags().Changed("recorders") {
50+
if envRecorders := os.Getenv("PARROT_RECORDERS"); envRecorders != "" {
51+
recorders = strings.Split(envRecorders, ",")
4952
}
50-
if !cmd.Flags().Changed("recorders") {
51-
if envRecorders := os.Getenv("PARROT_RECORDERS"); envRecorders != "" {
52-
recorders = strings.Split(envRecorders, ",")
53-
}
54-
}
55-
},
53+
}
54+
}
55+
56+
rootCmd := &cobra.Command{
57+
Use: "parrot",
58+
Short: "A server that can register and parrot back dynamic requests",
59+
PreRun: preRun,
5660
RunE: func(cmd *cobra.Command, args []string) error {
5761
options := []parrot.ServerOption{parrot.WithPort(port)}
5862
logLevel := zerolog.InfoLevel
@@ -90,15 +94,36 @@ func main() {
9094
},
9195
}
9296

93-
rootCmd.Flags().IntVarP(&port, "port", "p", 0, "Port to run the parrot on (env: PARROT_PORT)")
97+
rootCmd.PersistentFlags().IntVarP(&port, "port", "p", 0, "Port to run the parrot on (env: PARROT_PORT)")
9498
rootCmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable debug output (env: PARROT_DEBUG)")
9599
rootCmd.Flags().BoolVarP(&trace, "trace", "t", false, "Enable trace and debug output (env: PARROT_TRACE)")
96100
rootCmd.Flags().BoolVarP(&silent, "silent", "s", false, "Disable all output (env: PARROT_SILENT)")
97101
rootCmd.Flags().BoolVarP(&json, "json", "j", false, "Output logs in JSON format (env: PARROT_JSON)")
98102
rootCmd.Flags().StringSliceVarP(&recorders, "recorders", "r", nil, "Existing recorders to use (env: PARROT_RECORDERS)")
99103

104+
healthCheckCmd := &cobra.Command{
105+
Use: "health",
106+
Short: "Check if the parrot server is healthy",
107+
PreRun: preRun,
108+
Run: func(cmd *cobra.Command, args []string) {
109+
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/health", port))
110+
if err != nil {
111+
fmt.Println(err)
112+
os.Exit(1)
113+
}
114+
if resp.StatusCode != 200 {
115+
fmt.Printf("Health check failed with status code %d\n", resp.StatusCode)
116+
os.Exit(1)
117+
}
118+
fmt.Println("Parrot is healthy!")
119+
},
120+
SilenceUsage: true,
121+
}
122+
123+
rootCmd.AddCommand(healthCheckCmd)
124+
100125
if err := rootCmd.Execute(); err != nil {
101-
log.Error().Err(err).Msg("error executing command")
126+
fmt.Printf("Error running parrot:\n%s\n", err)
102127
os.Exit(1)
103128
}
104129
}

0 commit comments

Comments
 (0)