Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate plugin installation #420

Merged
merged 25 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a5bbec0
Add url parameter for Plugin
hamedsalim1999 Jan 1, 2024
2d422ac
Move plugin install logic to utils
mostafa Jan 1, 2024
093a3f9
Add url of the cache plugin
mostafa Jan 1, 2024
decddd0
Make plugin install work with CLI args and URLs in the gatewayd_plugi…
mostafa Jan 24, 2024
cac99a6
Fix linter errors
mostafa Jan 24, 2024
4348cf7
Use cast to refactor casts
mostafa Jan 24, 2024
aeb6d85
Test using the latest version of the plugin
mostafa Jan 24, 2024
28e0456
Check if the plugins are installed before updating or installing them
mostafa Jan 25, 2024
9016f36
Fix linter errors
mostafa Jan 25, 2024
d141804
Add overwrite-config flag to prevent updating config for automatic in…
mostafa Jan 25, 2024
9b311ce
Fix help for the plugin install command
mostafa Jan 26, 2024
45a6ce6
Fix variable reuse and naming
mostafa Jan 26, 2024
2561403
Add test for automated installation with no overwrite
mostafa Jan 26, 2024
38d9ecd
Generate and use separate plugins config file for each test
mostafa Jan 27, 2024
42d6a9a
Don't remove config files when running multiple goroutines
mostafa Jan 27, 2024
b47923a
Try to fix the race issue
mostafa Jan 27, 2024
60f810f
Check if the plugins config file exists
mostafa Jan 27, 2024
00423f8
Use an integration token to prevent GitHub API rate limits from block…
mostafa Jan 27, 2024
3e06f08
Pull plugin once and use the archive to install the plugin
mostafa Jan 28, 2024
cf990c2
Ignore linter error
mostafa Jan 28, 2024
842f360
Close reader
mostafa Jan 29, 2024
45c6d95
Reset global variable
mostafa Jan 29, 2024
618b231
Overwrite config
mostafa Jan 29, 2024
dfbfef0
Remove temp files
mostafa Jan 29, 2024
8d7c730
Clarify install flags
mostafa Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:

- name: Run Go tests 🔬
run: go test -p 1 -cover -covermode atomic -coverprofile=profile.cov -v ./...
env:
GITHUB_AUTH_TOKEN: ${{ secrets.INTEGRATION }}
Comment on lines +62 to +63
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to increase the rate limit of the GitHub API, so that consecutive CI runs don't hit the limit.


- name: Report coverage to coveralls 📈
uses: shogo82148/actions-goveralls@v1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ dist/
libtensorflow*

# Test generated files
cmd/test_plugins.yaml.bak
cmd/test_*.yaml.bak
cmd/test_*.yaml
8 changes: 8 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ linters-settings:
- "github.com/getsentry/sentry-go"
- "github.com/rs/zerolog"
- "github.com/grpc-ecosystem/grpc-gateway"
- "google.golang.org/grpc"
- "google.golang.org/protobuf"
- "github.com/knadh/koanf"
- "github.com/panjf2000/gnet/v2"
- "github.com/spf13/cobra"
- "github.com/spf13/cast"
- "github.com/invopop/jsonschema"
- "github.com/santhosh-tekuri/jsonschema/v5"
- "github.com/NYTimes/gziphandler"
Expand All @@ -60,6 +63,11 @@ linters-settings:
- "github.com/google/go-cmp"
- "github.com/google/go-github/v53/github"
- "github.com/codingsince1985/checksum"
- "golang.org/x/exp/maps"
- "golang.org/x/exp/slices"
- "gopkg.in/yaml.v3"
- "github.com/zenizh/go-capturer"
- "gopkg.in/natefinch/lumberjack.v2"
test:
files:
- $test
Expand Down
23 changes: 17 additions & 6 deletions cmd/cmd_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package cmd

import (
"bytes"
"os"
"path/filepath"

"github.com/spf13/cobra"
)

var (
globalTestConfigFile = "./test_global.yaml"
globalTLSTestConfigFile = "./testdata/gatewayd_tls.yaml"
pluginTestConfigFile = "./test_plugins.yaml"
)

// executeCommandC executes a cobra command and returns the command, output, and error.
// Taken from https://github.com/spf13/cobra/blob/0c72800b8dba637092b57a955ecee75949e79a73/command_test.go#L48.
func executeCommandC(root *cobra.Command, args ...string) (string, error) {
Expand All @@ -24,3 +20,18 @@ func executeCommandC(root *cobra.Command, args ...string) (string, error) {

return buf.String(), err
}

// mustPullPlugin pulls the gatewayd-plugin-cache plugin and returns the path to the archive.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to prevent GitHub API rate limit to be reached by pulling the plugin once and reusing it (almost) everywhere.

func mustPullPlugin() (string, error) {
pluginURL := "github.com/gatewayd-io/gatewayd-plugin-cache@v0.2.10"
fileName := "./gatewayd-plugin-cache-linux-amd64-v0.2.10.tar.gz"

if _, err := os.Stat(fileName); os.IsNotExist(err) {
_, err := executeCommandC(rootCmd, "plugin", "install", "--pull-only", pluginURL)
if err != nil {
return "", err
}
}

return filepath.Abs(fileName) //nolint:wrapcheck
}
3 changes: 2 additions & 1 deletion cmd/config_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func Test_configInitCmd(t *testing.T) {
globalTestConfigFile := "./test_global_configInitCmd.yaml"
// Test configInitCmd.
output, err := executeCommandC(rootCmd, "config", "init", "-c", globalTestConfigFile)
require.NoError(t, err, "configInitCmd should not return an error")
Expand All @@ -21,7 +22,7 @@ func Test_configInitCmd(t *testing.T) {
assert.FileExists(t, globalTestConfigFile, "configInitCmd should create a config file")

// Test configInitCmd with the --force flag to overwrite the config file.
output, err = executeCommandC(rootCmd, "config", "init", "--force")
output, err = executeCommandC(rootCmd, "config", "init", "--force", "-c", globalTestConfigFile)
require.NoError(t, err, "configInitCmd should not return an error")
assert.Equal(t,
fmt.Sprintf("Config file '%s' was overwritten successfully.", globalTestConfigFile),
Expand Down
1 change: 1 addition & 0 deletions cmd/config_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func Test_configLintCmd(t *testing.T) {
globalTestConfigFile := "./test_global_configLintCmd.yaml"
// Test configInitCmd.
output, err := executeCommandC(rootCmd, "config", "init", "-c", globalTestConfigFile)
require.NoError(t, err, "configInitCmd should not return an error")
Expand Down
1 change: 1 addition & 0 deletions cmd/plugin_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func Test_pluginInitCmd(t *testing.T) {
pluginTestConfigFile := "./test_plugins_pluginInitCmd.yaml"
// Test plugin init command.
output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile)
require.NoError(t, err, "plugin init command should not have returned an error")
Expand Down
Loading
Loading