Skip to content

Commit 83aa24e

Browse files
authored
Add support for archived plugins (#1202)
1 parent 9d06277 commit 83aa24e

30 files changed

+413
-80
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Dump cluster state
2+
description: "Creates an artifacts with cluster dump"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- uses: azure/setup-kubectl@v3
8+
9+
- name: Dump cluster state
10+
shell: bash
11+
run: |
12+
LOGS_DIR=output/
13+
mkdir -p "${LOGS_DIR}"
14+
15+
echo "Dumping cluster info into ${LOGS_DIR}"
16+
kubectl cluster-info dump --all-namespaces --output-directory="${LOGS_DIR}"
17+
- name: Upload artifacts
18+
uses: actions/upload-artifact@v2
19+
with:
20+
name: cluster_dump_${{github.sha}}
21+
path: "output"
22+
retention-days: 5 # Default 90 days

.github/workflows/branch-build.yml

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ jobs:
175175
env:
176176
# we hardcode plugins version, so it's predictable in e2e tests
177177
GORELEASER_CURRENT_TAG: "v0.0.0-latest"
178+
OUTPUT_MODE: "archive"
178179
run: |
179180
make build-plugins
180181

.github/workflows/pr-build.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ jobs:
237237
env:
238238
# we hardcode plugins version, so it's predictable in e2e tests
239239
GORELEASER_CURRENT_TAG: "v0.0.0-latest"
240+
OUTPUT_MODE: "archive"
240241
run: |
241242
make build-plugins
242243
@@ -251,3 +252,7 @@ jobs:
251252
run: |
252253
KUBECONFIG=$(k3d kubeconfig write ${{ matrix.integration }}-test-cluster) \
253254
make test-integration-${{ matrix.integration }}
255+
256+
- name: Dump cluster
257+
if: ${{ failure() }}
258+
uses: ./.github/actions/dump-cluster

.github/workflows/release.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
- name: Build plugins and generate plugins index.yaml
6262
env:
6363
PLUGIN_DOWNLOAD_URL_BASE_PATH: "https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}"
64+
OUTPUT_MODE: "archive"
6465
run: |
6566
make gen-plugins-index
6667
@@ -79,4 +80,4 @@ jobs:
7980
IMAGE_TAG: ${{ github.ref_name }}
8081
ANALYTICS_API_KEY: ${{ secrets.ANALYTICS_API_KEY }}
8182
run: |
82-
goreleaser release --rm-dist --release-notes=CHANGELOG.md
83+
goreleaser release --clean --release-notes=CHANGELOG.md

.github/workflows/upload-plugins.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
env:
3636
GORELEASER_CURRENT_TAG: "v0.0.0-latest"
3737
PLUGIN_DOWNLOAD_URL_BASE_PATH: "https://storage.googleapis.com/botkube-plugins-latest"
38+
OUTPUT_MODE: "archive"
3839
run: |
3940
make gen-plugins-index
4041
- name: Upload plugins to GCS

.goreleaser.plugin.tpl.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,14 @@ builds:
2525
- 7
2626
<- end >
2727

28+
archives:
29+
<range .>
30+
- builds: [<.Name>]
31+
id: <.Name>
32+
files:
33+
- none*
34+
name_template: "{{ .Binary }}"
35+
<end>
36+
2837
snapshot:
2938
name_template: 'v{{ .Version }}'

.goreleaser.plugin.yaml

+75
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,80 @@ builds:
190190
goarm:
191191
- 7
192192

193+
archives:
194+
195+
- builds: [doctor]
196+
id: doctor
197+
files:
198+
- none*
199+
name_template: "{{ .Binary }}"
200+
201+
- builds: [echo]
202+
id: echo
203+
files:
204+
- none*
205+
name_template: "{{ .Binary }}"
206+
207+
- builds: [exec]
208+
id: exec
209+
files:
210+
- none*
211+
name_template: "{{ .Binary }}"
212+
213+
- builds: [flux]
214+
id: flux
215+
files:
216+
- none*
217+
name_template: "{{ .Binary }}"
218+
219+
- builds: [gh]
220+
id: gh
221+
files:
222+
- none*
223+
name_template: "{{ .Binary }}"
224+
225+
- builds: [helm]
226+
id: helm
227+
files:
228+
- none*
229+
name_template: "{{ .Binary }}"
230+
231+
- builds: [kubectl]
232+
id: kubectl
233+
files:
234+
- none*
235+
name_template: "{{ .Binary }}"
236+
237+
- builds: [cm-watcher]
238+
id: cm-watcher
239+
files:
240+
- none*
241+
name_template: "{{ .Binary }}"
242+
243+
- builds: [github-events]
244+
id: github-events
245+
files:
246+
- none*
247+
name_template: "{{ .Binary }}"
248+
249+
- builds: [keptn]
250+
id: keptn
251+
files:
252+
- none*
253+
name_template: "{{ .Binary }}"
254+
255+
- builds: [kubernetes]
256+
id: kubernetes
257+
files:
258+
- none*
259+
name_template: "{{ .Binary }}"
260+
261+
- builds: [prometheus]
262+
id: prometheus
263+
files:
264+
- none*
265+
name_template: "{{ .Binary }}"
266+
267+
193268
snapshot:
194269
name_template: 'v{{ .Version }}'

.goreleaser.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ release:
8080
# - build plugin binaries
8181
# - build plugin index.yaml
8282
extra_files:
83-
- glob: ./plugin-dist/executor_*
84-
- glob: ./plugin-dist/source_*
83+
- glob: ./plugin-dist/executor_*.tar.gz
84+
- glob: ./plugin-dist/source_*.tar.gz
8585
- glob: ./plugins-index.yaml
8686
- glob: ./plugins-dev-index.yaml
8787

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ build: pre-build
3434
# Build Botkube official plugins for all supported platforms.
3535
build-plugins: pre-build gen-plugins-goreleaser
3636
@echo "Building plugins binaries"
37-
@./hack/goreleaser.sh build_plugins
37+
go run ./hack/target/build-plugins/main.go
3838
@echo "Build completed successfully"
3939

4040
# Build Botkube official plugins only for current GOOS and GOARCH.
4141
build-plugins-single: pre-build gen-plugins-goreleaser
4242
@echo "Building single target plugins binaries"
43-
@./hack/goreleaser.sh build_plugins_single
43+
go run ./hack/target/build-plugins/main.go --single-platform
4444
@echo "Build completed successfully"
4545

4646
# Build the image

hack/gen-plugin-index.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func main() {
2020
binsDir = flag.String("binaries-path", "./plugin-dist", "Defines the local path to plugins binaries folder")
2121
output = flag.String("output-path", "./plugins-index.yaml", "Defines the local path where index YAML should be saved")
2222
pluginNameFilter = flag.String("plugin-name-filter", "", "Defines the plugin name regex for plugins which should be included in the index. Other plugins will be skipped.")
23+
useArchive = flag.Bool("use-archive", true, "If enabled, archives are used instead of binaries for constructing plugin download URLs.")
2324
)
2425

2526
flag.Parse()
@@ -37,7 +38,7 @@ func main() {
3738
})
3839

3940
log.Info("Building index..")
40-
idx, err := idxBuilder.Build(absBinsDir, *urlBasePath, *pluginNameFilter, false)
41+
idx, err := idxBuilder.Build(absBinsDir, *urlBasePath, *pluginNameFilter, false, *useArchive)
4142
loggerx.ExitOnError(err, "while building plugin index")
4243

4344
raw, err := yaml.Marshal(idx)

hack/goreleaser.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ prepare() {
1717
release_snapshot() {
1818
prepare
1919
export GORELEASER_CURRENT_TAG=v9.99.9-dev
20-
goreleaser release --rm-dist --snapshot --skip-publish
20+
goreleaser release --clean --snapshot --skip-publish
2121

2222
# Push images
2323
docker push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64
@@ -46,7 +46,7 @@ release_snapshot() {
4646
release_snapshot_cli() {
4747
prepare
4848
export GORELEASER_CURRENT_TAG=v9.99.9-dev
49-
goreleaser build --rm-dist --snapshot --id botkube-cli
49+
goreleaser build --clean --snapshot --id botkube-cli
5050
}
5151

5252
save_images() {
@@ -58,7 +58,7 @@ save_images() {
5858
fi
5959

6060
export GORELEASER_CURRENT_TAG=${IMAGE_TAG}
61-
goreleaser release --rm-dist --snapshot --skip-publish
61+
goreleaser release --clean --snapshot --skip-publish
6262

6363
mkdir -p "${IMAGE_SAVE_LOAD_DIR}"
6464

@@ -125,11 +125,11 @@ build() {
125125
-w /go/src/github.com/kubeshop/botkube \
126126
-e GORELEASER_CURRENT_TAG=v9.99.9-dev \
127127
-e ANALYTICS_API_KEY="${ANALYTICS_API_KEY}" \
128-
goreleaser/goreleaser release --rm-dist --snapshot --skip-publish
128+
goreleaser/goreleaser release --clean --snapshot --skip-publish
129129
}
130130

131131
build_plugins_command() {
132-
local command="goreleaser build -f .goreleaser.plugin.yaml --rm-dist --snapshot"
132+
local command="goreleaser build -f .goreleaser.plugin.yaml --clean --snapshot"
133133

134134
local targets=()
135135
if [ -n "$PLUGIN_TARGETS" ]; then
@@ -160,7 +160,7 @@ build_single() {
160160
-w /go/src/github.com/kubeshop/botkube \
161161
-e IMAGE_TAG=${IMAGE_TAG} \
162162
-e ANALYTICS_API_KEY="${ANALYTICS_API_KEY}" \
163-
goreleaser/goreleaser build --single-target --rm-dist --snapshot --id botkube-agent -o "./botkube-agent"
163+
goreleaser/goreleaser build --single-target --clean --snapshot --id botkube-agent -o "./botkube-agent"
164164
docker build -f "$PWD/build/Dockerfile" --platform "${IMAGE_PLATFORM}" -t "${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${IMAGE_TAG}" .
165165
rm "$PWD/botkube-agent"
166166
}

hack/target/build-plugins/main.go

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
"os/exec"
9+
"strings"
10+
11+
"github.com/mattn/go-shellwords"
12+
13+
"github.com/kubeshop/botkube/internal/loggerx"
14+
)
15+
16+
func main() {
17+
pluginTargets := flag.String("plugin-targets", getEnv("PLUGIN_TARGETS", ""), "Comma separated list of specific targets to build. If empty, all targets are built.")
18+
outputMode := flag.String("output-mode", getEnv("OUTPUT_MODE", "archive"), "Output format. Allowed values: binary or archive.")
19+
buildSingle := flag.Bool("single-platform", os.Getenv("SINGLE_PLATFORM") != "", "If specified, builds only for current GOOS and GOARCH.")
20+
21+
flag.Parse()
22+
23+
switch *outputMode {
24+
case "archive":
25+
if *pluginTargets != "" {
26+
log.Fatal("Cannot build specific targets in archive mode")
27+
}
28+
// to produce archives, we need to run release instead of build
29+
releaseWithoutPublishing()
30+
case "binary":
31+
buildPlugins(*pluginTargets, *buildSingle)
32+
}
33+
}
34+
35+
func getEnv(key, defaultValue string) string {
36+
value, exists := os.LookupEnv(key)
37+
if !exists {
38+
return defaultValue
39+
}
40+
return value
41+
}
42+
43+
func buildPlugins(pluginTargets string, single bool) {
44+
command := "goreleaser build -f .goreleaser.plugin.yaml --clean --snapshot"
45+
for _, target := range strings.Split(pluginTargets, ",") {
46+
if strings.TrimSpace(target) == "" {
47+
continue
48+
}
49+
command += fmt.Sprintf(" --id %s", target)
50+
}
51+
52+
if single {
53+
command += "--single-target"
54+
}
55+
56+
runCommand(command)
57+
}
58+
59+
func runCommand(command string) {
60+
log.Printf("Running: %s", command)
61+
args, err := shellwords.Parse(command)
62+
loggerx.ExitOnError(err, "while parsing command")
63+
64+
bin, binArgs := args[0], args[1:]
65+
66+
//nolint:gosec
67+
cmd := exec.Command(bin, binArgs...)
68+
cmd.Stdout = os.Stdout
69+
cmd.Stderr = os.Stderr
70+
71+
loggerx.ExitOnError(cmd.Run(), "while running command")
72+
}
73+
74+
func releaseWithoutPublishing() {
75+
runCommand("goreleaser release -f .goreleaser.plugin.yaml --clean --snapshot")
76+
}

0 commit comments

Comments
 (0)