Skip to content

Commit 7de0344

Browse files
authored
Merge pull request #143 from kube-logging/feat/metrics
feat: metrics
2 parents 3f7efea + 9d0f7be commit 7de0344

37 files changed

Lines changed: 995 additions & 169 deletions

.github/workflows/artifacts.yaml

Lines changed: 103 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,150 @@
11
name: Artifacts
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
tags:
8-
- v[0-9]+.[0-9]+.[0-9]+
9-
pull_request:
4+
workflow_call:
5+
inputs:
6+
publish:
7+
description: Publish artifacts to the artifact store
8+
default: false
9+
required: false
10+
type: boolean
11+
outputs:
12+
container-image-name:
13+
description: Container image name
14+
value: ${{ jobs.container-image.outputs.name }}
15+
container-image-digest:
16+
description: Container image digest
17+
value: ${{ jobs.container-image.outputs.digest }}
18+
container-image-tag:
19+
description: Container image tag
20+
value: ${{ jobs.container-image.outputs.tag }}
1021

1122
permissions:
1223
contents: read
13-
packages: write
14-
security-events: write
1524

1625
jobs:
1726
container-images:
18-
name: Container images
27+
name: Container image
1928
runs-on: ubuntu-latest
2029

30+
permissions:
31+
contents: read
32+
packages: write
33+
id-token: write
34+
security-events: write
35+
36+
outputs:
37+
name: ${{ steps.image-name.outputs.value }}
38+
digest: ${{ steps.build.outputs.digest }}
39+
tag: ${{ steps.meta.outputs.version }}
40+
2141
steps:
2242
- name: Checkout
2343
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2444

45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
47+
with:
48+
platforms: all
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
52+
53+
- name: Set up Cosign
54+
uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0
55+
if: ${{ inputs.publish }}
56+
57+
- name: Set image name
58+
id: image-name
59+
run: echo "value=ghcr.io/${{ github.repository }}" >> "$GITHUB_OUTPUT"
60+
2561
- name: Gather metadata
2662
id: meta
2763
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
2864
with:
29-
images: ghcr.io/${{ github.repository_owner }}/custom-runner
65+
images: ${{ steps.image-name.outputs.value }}
3066
flavor: |
3167
latest = false
3268
tags: |
3369
type=ref,event=branch
34-
type=ref,event=pr
70+
type=ref,event=pr,prefix=pr-
3571
type=semver,pattern={{raw}}
3672
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
37-
38-
- name: Set up QEMU
39-
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
40-
with:
41-
platforms: all
42-
43-
- name: Set up Docker Buildx
44-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
73+
labels: |
74+
org.opencontainers.image.description=Custom runner for Kubernetes
75+
org.opencontainers.image.title=custom-runner
76+
org.opencontainers.image.authors=Kube logging authors
77+
org.opencontainers.image.documentation=https://kube-logging.dev/docs/
4578
4679
- name: Login to GitHub Container Registry
4780
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
4881
with:
4982
registry: ghcr.io
5083
username: ${{ github.actor }}
5184
password: ${{ github.token }}
52-
if: github.event_name == 'push'
85+
if: ${{ inputs.publish }}
5386

5487
- name: Build and push
5588
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
5689
with:
5790
context: .
58-
platforms: linux/amd64,linux/arm64,linux/arm/v7
59-
cache-from: type=gha
60-
cache-to: type=gha,mode=max
61-
push: ${{ github.event_name == 'push' }}
91+
platforms: linux/amd64,linux/arm64
6292
tags: ${{ steps.meta.outputs.tags }}
6393
labels: ${{ steps.meta.outputs.labels }}
94+
cache-from: type=gha
95+
cache-to: type=gha,mode=max
96+
outputs: |
97+
type=image,push=${{ inputs.publish }},name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
98+
type=oci,dest=image.tar,name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
99+
100+
- name: Sign image with GitHub OIDC Token
101+
if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization
102+
env:
103+
DIGEST: ${{ steps.build.outputs.digest }}
104+
TAGS: ${{ steps.meta.outputs.tags }}
105+
run: |
106+
images=""
107+
for tag in ${TAGS[@]}; do
108+
images+="${tag}@${DIGEST} "
109+
done
110+
111+
cosign sign --yes --rekor-url "https://rekor.sigstore.dev/" ${images}
112+
113+
- name: Verify signed image with cosign
114+
if: ${{ inputs.publish && github.repository_owner == 'kube-logging' }} # Check if the workflow is called by the same GitHub organization
115+
env:
116+
DIGEST: ${{ steps.build.outputs.digest }}
117+
TAGS: ${{ steps.meta.outputs.tags }}
118+
run: |
119+
for tag in ${TAGS[@]}; do
120+
cosign verify "${tag}@${DIGEST}" \
121+
--rekor-url "https://rekor.sigstore.dev/" \
122+
--certificate-identity "https://github.com/${{ github.repository }}/.github/workflows/artifacts.yaml@${{ github.ref }}" \
123+
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" | jq
124+
125+
- name: Extract OCI tarball
126+
run: |
127+
mkdir -p image
128+
tar -xf image.tar -C image
64129
65130
- name: Run Trivy vulnerability scanner
66131
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # 0.35.0
67132
env:
68-
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2
69-
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1
133+
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2,ghcr.io/aquasecurity/trivy-db:2,mirror.gcr.io/aquasec/trivy-db:2
134+
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1,mirror.gcr.io/aquasec/trivy-java-db:1
135+
with:
136+
input: image
137+
format: sarif
138+
output: trivy-results.sarif
139+
140+
- name: Upload Trivy scan results as artifact
141+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
70142
with:
71-
image-ref: "ghcr.io/${{ github.repository_owner }}/custom-runner:${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}"
72-
format: "sarif"
73-
output: "trivy-results.sarif"
74-
if: github.event_name == 'push'
143+
name: "[${{ github.job }}] Trivy scan results"
144+
path: trivy-results.sarif
145+
retention-days: 5
75146

76147
- name: Upload Trivy scan results to GitHub Security tab
77-
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
148+
uses: github/codeql-action/upload-sarif@3c3833e0f8c1c83d449a7478aa59c036a9165498 # v3.29.11
78149
with:
79-
sarif_file: "trivy-results.sarif"
80-
if: github.event_name == 'push'
150+
sarif_file: trivy-results.sarif

.github/workflows/ci.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
20+
with:
21+
go-version-file: '.go-version'
22+
23+
- name: Test
24+
run: make test
25+
26+
lint:
27+
name: Lint
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
34+
- name: Set up Go
35+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
36+
with:
37+
go-version-file: '.go-version'
38+
39+
- name: Lint
40+
run: make lint
41+
env:
42+
LINTER_FLAGS: '--timeout 5m'
43+
44+
license-check:
45+
name: License check
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
51+
52+
- name: Set up Go
53+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
54+
with:
55+
go-version-file: '.go-version'
56+
57+
- name: Cache licenses
58+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
59+
with:
60+
key: licensei-v2-${{ hashFiles('go.sum') }}
61+
path: |
62+
.licensei.cache
63+
restore-keys: |
64+
licensei-v2
65+
66+
- name: Download license information for dependencies
67+
env:
68+
GITHUB_TOKEN: ${{ github.token }}
69+
run: make license-cache
70+
71+
- name: Check licenses
72+
env:
73+
GITHUB_TOKEN: ${{ github.token }}
74+
run: make license-check
75+
76+
artifacts:
77+
name: Artifacts
78+
uses: ./.github/workflows/artifacts.yaml
79+
with:
80+
publish: ${{ github.event_name == 'push' }}
81+
permissions:
82+
contents: read
83+
packages: write
84+
id-token: write
85+
security-events: write

.github/workflows/release.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ["v[0-9]+.[0-9]+.[0-9]+*"]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
artifacts:
12+
name: Artifacts
13+
uses: ./.github/workflows/artifacts.yaml
14+
with:
15+
publish: true
16+
permissions:
17+
contents: read
18+
packages: write
19+
id-token: write
20+
security-events: write

.go-version

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

.golangci.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: "2"
2+
run:
3+
timeout: 10m
4+
allow-parallel-runners: true
5+
6+
formatters:
7+
enable:
8+
- gci
9+
- gofmt
10+
- gofumpt
11+
- goimports
12+
settings:
13+
gci:
14+
sections:
15+
- standard
16+
- default
17+
- prefix(github.com/kube-logging/custom-runner)
18+
goimports:
19+
local-prefixes:
20+
- github.com/kube-logging/custom-runner
21+
gofmt:
22+
simplify: true
23+
gofumpt:
24+
extra-rules: false
25+
26+
linters:
27+
settings:
28+
misspell:
29+
locale: US
30+
revive:
31+
confidence: 0.9
32+
gocyclo:
33+
min-complexity: 40
34+
enable:
35+
- bodyclose
36+
- errcheck
37+
- ineffassign
38+
- misspell
39+
- nolintlint
40+
- revive
41+
- gocyclo
42+
- unconvert
43+
- unparam
44+
- unused
45+
- whitespace

.licensei.toml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ approved = [
77
]
88

99
ignored = [
10-
# Unsupported VCS
11-
"cloud.google.com/go",
12-
"cloud.google.com/go/storage",
13-
"google.golang.org/api",
14-
"google.golang.org/protobuf",
15-
"github.com/mitchellh/mapstructure",
16-
"gopkg.in/yaml.v3",
17-
"golang.org/x/sys",
18-
"github.com/fsnotify/fsnotify",
10+
"google.golang.org/protobuf", # BSD-3-Clause
1911
]
2012

2113
[header]
22-
ignorePaths = ["vendor", ".gen", "plz-out"]
23-
ignoreFiles = ["mock_*.go", "*_gen.go", "zz_generated.*.go", "generated.go"]
24-
template = """// Copyright (c) :YEAR: Cisco All Rights Reserved.
25-
"""
14+
ignorePaths = ["vendor"]
15+
ignoreFiles = []
16+
authors = ["Cisco Systems, Inc. and/or its affiliates", "Kube logging authors"]
17+
template = """// Copyright © :YEAR: :AUTHOR:
18+
//
19+
// Licensed under the Apache License, Version 2.0 (the "License");
20+
// you may not use this file except in compliance with the License.
21+
// You may obtain a copy of the License at
22+
//
23+
// http://www.apache.org/licenses/LICENSE-2.0
24+
//
25+
// Unless required by applicable law or agreed to in writing, software
26+
// distributed under the License is distributed on an "AS IS" BASIS,
27+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28+
// See the License for the specific language governing permissions and
29+
// limitations under the License."""

0 commit comments

Comments
 (0)