From 76bd9d000e509a643c9f87cbd49315ed3b169ca9 Mon Sep 17 00:00:00 2001 From: Markus Wennrich Date: Wed, 29 Mar 2023 14:33:41 +0200 Subject: [PATCH 1/2] build ghcr image --- .github/workflows/ghcr.yaml | 55 +++++++++++++++++++++++++++++ .github/workflows/latest.yaml | 5 ++- .github/workflows/pull_request.yaml | 5 ++- .github/workflows/release.yaml | 5 ++- samples/alertloggerStatefulSet.yaml | 2 +- 5 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/ghcr.yaml diff --git a/.github/workflows/ghcr.yaml b/.github/workflows/ghcr.yaml new file mode 100644 index 0000000..d8de352 --- /dev/null +++ b/.github/workflows/ghcr.yaml @@ -0,0 +1,55 @@ +--- +name: Docker Build Action +on: + pull_request: + branches: + - main + release: + types: + - published + push: + branches: + - main + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: Docker Build + runs-on: ubuntu-latest + + steps: + - name: Log in to the container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20.x' + + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + args: -p bugs -p unused --timeout=3m + + - name: Make tag + run: | + [ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true + [ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true + [ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true + + - name: Build and push image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.tag }} diff --git a/.github/workflows/latest.yaml b/.github/workflows/latest.yaml index 19ad83e..1dc8c10 100644 --- a/.github/workflows/latest.yaml +++ b/.github/workflows/latest.yaml @@ -19,14 +19,13 @@ jobs: password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - name: Setup go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 1.20.1 + go-version: '1.20.x' - name: Lint uses: golangci/golangci-lint-action@v3 with: - version: v1.51.1 args: --timeout=3m -p bugs -p unused - name: Build the Docker images diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index f274324..bf46843 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -24,14 +24,13 @@ jobs: if: steps.fork.outputs.is_fork_pr == 'false' - name: Setup go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 1.20.1 + go-version: '1.20.x' - name: Lint uses: golangci/golangci-lint-action@v3 with: - version: v1.51.1 args: --timeout=3m -p bugs -p unused - name: Build diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cc76555..e884119 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,14 +19,13 @@ jobs: password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - name: Setup go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 1.20.1 + go-version: '1.20.x' - name: Lint uses: golangci/golangci-lint-action@v2 with: - version: v1.51.1 args: --timeout=3m -p bugs -p unused - name: Build the Docker images diff --git a/samples/alertloggerStatefulSet.yaml b/samples/alertloggerStatefulSet.yaml index 4115cc7..d6acf0f 100644 --- a/samples/alertloggerStatefulSet.yaml +++ b/samples/alertloggerStatefulSet.yaml @@ -19,7 +19,7 @@ spec: spec: containers: - name: alertlogger - image: docker.io/mwennrich/alertlogger:latest + image: ghcr.io/mwennrich/alertlogger:latest env: - name: JSON_OUTPUT value: "true" From 934151e2f0b1e7080bf5bcda52c35ce39e62b4bc Mon Sep 17 00:00:00 2001 From: Markus Wennrich Date: Wed, 29 Mar 2023 14:33:58 +0200 Subject: [PATCH 2/2] cosmetic --- alertlogger.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/alertlogger.go b/alertlogger.go index ce28ced..4be5029 100644 --- a/alertlogger.go +++ b/alertlogger.go @@ -51,9 +51,8 @@ func parse(payload []byte) (*alertGroup, error) { return &d, nil } -// print itearates over the alertgroup and prints all alerts in json format +// printJson prints all alerts in json format func printJson(ag *alertGroup, m *sync.Mutex) { - m.Lock() for _, alert := range ag.Alerts { out := map[string]string{"status": alert.Status} @@ -76,7 +75,7 @@ func printJson(ag *alertGroup, m *sync.Mutex) { m.Unlock() } -// print iterates over the alertgroup and prints all alerts as key value pairs +// printKV iterates over the alertgroup and prints all alerts as key value pairs func printKV(ag *alertGroup, m *sync.Mutex) { m.Lock() for _, alert := range ag.Alerts { @@ -104,14 +103,17 @@ func main() { http.HandleFunc("/",func(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() + b, err := io.ReadAll(r.Body) if err != nil { panic(err) } + ag, err := parse(b) if err != nil { panic(err) } + if jsonOutput { printJson(ag, &m) } else {