Skip to content

Commit

Permalink
Merge pull request #28 from zapier/weird-port-parsing-issue
Browse files Browse the repository at this point in the history
Fix port in chart, skaffold, version, multitarget builds
  • Loading branch information
djeebus authored Dec 8, 2022
2 parents d3296c4 + c3ef464 commit 719d638
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 23 deletions.
1 change: 1 addition & 0 deletions .earthlyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Earthfile
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# asdf plugin add earthly https://github.com/YR-ZR0/asdf-earthly
earthly 0.6.30
golang 1.19.3
skaffold 2.0.3
56 changes: 38 additions & 18 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,29 @@ ci-helm:
BUILD +test-helm

build:
BUILD +build-binary
BUILD +build-docker
BUILD +build-helm

release:
BUILD +release-binary
BUILD +build-docker

go-deps:
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION}

WORKDIR /src
COPY go.mod go.sum /src
RUN go mod download

build-binary:
FROM +go-deps

WORKDIR /src
COPY . /src
RUN go build -o prom-aggregation-gateway .

SAVE ARTIFACT ./prom-aggregation-gateway

build-docker:
FROM alpine:${ALPINE_VERSION}
COPY +build-binary/prom-aggregation-gateway .
Expand All @@ -41,29 +56,35 @@ build-docker:
continuous-deploy:
BUILD +release-helm

go-deps:
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION}
build-binaries:
FROM golang:${GOLANG_VERSION}

WORKDIR /src
COPY go.mod go.sum /src
RUN go mod download

SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
RUN go install github.com/mitchellh/gox@latest

build-binary:
FROM +go-deps
COPY go.mod go.sum /src
RUN go mod download

WORKDIR /src
COPY . /src
RUN go build -o prom-aggregation-gateway .

SAVE ARTIFACT ./prom-aggregation-gateway AS LOCAL ./dist/
RUN \
GOFLAGS="-trimpath" \
GO111MODULE=on \
CGO_ENABLED=0 \
gox \
-parallel=3 \
-ldflags "-X main.version=${version}" \
-output="_dist/prom-aggregation-gateway-${version}-{{.OS}}-{{.Arch}}" \
-osarch='darwin/amd64 darwin/arm64 linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x windows/amd64' \
.

release-binary:
FROM +build-binary
SAVE ARTIFACT _dist AS LOCAL ./dist

COPY +build-binary/prom-aggregation-gateway .
release-binaries:
FROM alpine:${ALPINE_VERSION}

COPY +build-binaries/_dist .

# install github cli
RUN FILE=ghcli.tgz \
Expand All @@ -79,9 +100,9 @@ release-binary:
&& gh version

RUN apk add --no-cache git

ENV GH_TOKEN $token
RUN --push gh release create ${version} ./prom-aggregation-gateway
RUN --push gh release create ${version} ./dist/*

lint-golang:
FROM +go-deps
Expand Down Expand Up @@ -112,7 +133,6 @@ test-golang:
RUN go test .

test-helm:
ARG ct_args=''
FROM quay.io/helmpack/chart-testing:v${CHART_TESTING_VERSION}

# install kubeconform
Expand Down
2 changes: 1 addition & 1 deletion charts/prom-aggregation-gateway/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: prom-aggregation-gateway
version: 0.4.0
version: 0.4.1
home: https://github.com/zapier/prom-aggregation-gateway
maintainers:
- name: djeebus
Expand Down
10 changes: 6 additions & 4 deletions charts/prom-aggregation-gateway/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ spec:
- name: prom-aggregation-gateway
image: {{ .Values.controller.image.repository }}:{{ .Values.controller.image.tag }}
args:
- --listen=":8080"
- --metricsListen=":8888"
- --listen
- :8080
- --metricsListen
- :8888
ports:
- name: http
containerPort: 8080
- name: metrics
containerPort: 8888
livenessProbe:
httpGet:
path: /-/healthy
path: /healthy
port: http
readinessProbe:
httpGet:
path: /-/ready
path: /ready
port: http
{{- with .Values.controller.resources }}
resources: {{ . | toYaml | nindent 12 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/prom-aggregation-gateway/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.podMonitor.create }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
Expand All @@ -8,3 +9,4 @@ spec:
{{- include "prom-aggregation-gateway.selectorLabels" . | nindent 6 }}
podMetricsEndpoints:
- port: metrics
{{- end }}
2 changes: 2 additions & 0 deletions charts/prom-aggregation-gateway/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.serviceMonitor.create }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
Expand All @@ -8,3 +9,4 @@ spec:
{{- include "prom-aggregation-gateway.selectorLabels" . | nindent 6 }}
endpoints:
- port: http
{{- end }}
18 changes: 18 additions & 0 deletions charts/prom-aggregation-gateway/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@
"type": "integer"
}
}
},
"podMonitor": {
"type": "object",
"additionalProperties": false,
"properties": {
"create": {
"type": "boolean"
}
}
},
"serviceMonitor": {
"type": "object",
"additionalProperties": false,
"properties": {
"create": {
"type": "boolean"
}
}
}
}
}
6 changes: 6 additions & 0 deletions charts/prom-aggregation-gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ controller:

type: Deployment

podMonitor:
create: true

service:
create: true
annotations: {}
type: LoadBalancer
port: 8080
nodePort: 12345

serviceMonitor:
create: true
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"log"
"net/http"
"os"
Expand All @@ -12,17 +13,28 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var version = "0.0.0"

func handleHealthCheck(c *gin.Context) {
c.Header("Content-Type", "application/json")
c.JSON(http.StatusOK, `{"alive": true}`)
}

func main() {
var (
showVersion = false
)
listen := flag.String("listen", ":80", "Address and port to listen on.")
metricsListen := flag.String("metricsListen", ":8888", "Address and port serve the metrics endpoint on")
cors := flag.String("cors", "*", "The 'Access-Control-Allow-Origin' value to be returned.")
flag.BoolVar(&showVersion, "version", false, "Display the version")
flag.Parse()

if showVersion {
fmt.Printf("%s\n", version)
return
}

sigChannel := make(chan os.Signal, 1)
signal.Notify(sigChannel, syscall.SIGTERM, syscall.SIGINT)

Expand Down
23 changes: 23 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# nonk8s
apiVersion: skaffold/v4beta1
kind: Config
metadata:
name: prom-aggregation-gateway
build:
artifacts:
- image: ghcr.io/zapier/prom-aggregation-gateway
custom:
buildCommand: earthly +build-docker --version=dev
tagPolicy:
customTemplate:
template: dev
manifests:
helm:
releases:
- name: prom-aggregation-gateway
chartPath: ./charts/prom-aggregation-gateway
createNamespace: true
setValues:
image.tag: dev
podMonitor.create: false
serviceMonitor.create: false

0 comments on commit 719d638

Please sign in to comment.