tyk icon indicating copy to clipboard operation
tyk copied to clipboard

Fix plugin build script

Open asutosh opened this issue 2 years ago • 7 comments

Description

Update plugin compiler smoke tests to align with the new changes in plugin compiler build where the plugin name has version and platform info in the name, Also fix the plugin compiler build script - there seems to be an issue when there's an internal dependency in the go.mod file(eg: github.com/TykTechnologies/tyk/certs) - it causes the build to fail as it causes the the source tree to be deleted while building the plugin.

asutosh avatar Apr 07 '22 16:04 asutosh

API tests result: success :white_check_mark: Branch used: refs/pull/3998/merge Commit:
Triggered by: pull_request (@asutosh) Execution page

Tyk-ITS avatar Apr 07 '22 16:04 Tyk-ITS

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

sonarqubecloud[bot] avatar Apr 07 '22 16:04 sonarqubecloud[bot]

Needs a rebase.

alephnull avatar Apr 11 '22 09:04 alephnull

We've used a different approach than the proposed go mod vendor solution:

cd $TYK_SOURCE_PATH
go list -m -f '{{ if not .Main }}{{ .Path }} {{ .Version }}{{ end }}' all > dependencies.txt

# for any dependency also present in Tyk, change the module version to Tyk's version
cd $PLUGIN_SOURCE_PATH

# remove go module information
rm -rf go.mod go.sum

# initialize fresh module
go mod init mymodule

# add graphql-go-tools pinned version
go mod edit -replace github.com/jensneuse/graphql-go-tools=github.com/TykTechnologies/graphql-go-tools@$GOTOOLS_REF

# add Tyk version
go get github.com/TykTechnologies/tyk@$TYK_REF

# scan and update go dependencies
go mod tidy

# collect all plugin dependencies
go list -m -f '{{ if not .Main }}{{ .Path }} {{ .Version }}{{ end }}' all > dependencies.txt

# for any shared dependency, pin the version to Tyk gateway version
awk 'NR==FNR{seen[$1]=$2; next} seen[$1] && seen[$1] != $2' $PLUGIN_SOURCE_PATH/dependencies.txt $TYK_SOURCE_PATH/dependencies.txt | while read PKG VER; do
  go mod edit -replace=$PKG=$PKG@$VER
done

This uses Go modules 'replace' behaviour to fix versions for any dependency which is shared with Tyk gateway.

By tweaking the Docker images for plugin-compiler a bit, we can ensure that listing all dependencies for Tyk gateway is done ahead of time (during the creation of the Docker image), since these dependencies are fixed for a specific version of Tyk

blagerweij avatar Aug 31 '22 23:08 blagerweij

Hey @asutosh would you follow up on this?

alephnull avatar Sep 01 '22 01:09 alephnull

https://tyktech.atlassian.net/browse/TT-6402 seems to indicate that GOOS and GOARCH cannot be overridden on the command line.

alephnull avatar Sep 01 '22 01:09 alephnull

Thanks @blagerweij ! Will follow up on your suggested changes.

asutosh avatar Sep 01 '22 06:09 asutosh