fix: pipeline_fixes (#18)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #18
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
parent
70f7492043
commit
ee89243b3a
6 changed files with 203 additions and 52 deletions
|
|
@ -8,11 +8,13 @@ import (
|
|||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
RootPath string
|
||||
Namespace string
|
||||
Provider string
|
||||
DistPath string
|
||||
|
|
@ -23,6 +25,17 @@ type Provider struct {
|
|||
Domain string
|
||||
}
|
||||
|
||||
func (p *Provider) GetRoot() error {
|
||||
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lines := strings.Split(string(out), "\n")
|
||||
p.RootPath = lines[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Provider) CreateV1Dir() error {
|
||||
// Path to semantic version dir
|
||||
versionPath := p.providerDirs()
|
||||
|
|
@ -127,11 +140,21 @@ func (p *Provider) createVersionsFile() error {
|
|||
}
|
||||
|
||||
// Build the versions file...
|
||||
version := Version{}
|
||||
version := Version{
|
||||
Version: p.Version,
|
||||
Protocols: []string{"5.1"},
|
||||
Platforms: nil,
|
||||
}
|
||||
for _, sum := range shasums {
|
||||
// get os and arch from filename
|
||||
removeFileExtension := strings.Split(sum.Path, ".zip")
|
||||
if len(removeFileExtension) < 1 {
|
||||
log.Fatalf("error: %s does not have .zip extension", sum.Path)
|
||||
}
|
||||
fileNameSplit := strings.Split(removeFileExtension[0], "_")
|
||||
if len(fileNameSplit) < 4 {
|
||||
log.Fatalf("filename does not match our regex: %s", removeFileExtension[0])
|
||||
}
|
||||
|
||||
// Get build target and architecture from the zip file name
|
||||
target := fileNameSplit[2]
|
||||
|
|
@ -165,9 +188,9 @@ func (p *Provider) createVersionsFile() error {
|
|||
}
|
||||
|
||||
func (p *Provider) providerDirs() string {
|
||||
log.Println("* Creating release/v1/providers/[namespace]/[repo]/[version] directories")
|
||||
log.Println("* Creating release/v1/providers/[namespace]/[provider]/[version] directories")
|
||||
|
||||
target := path.Join("release", "v1", "providers", p.Namespace, p.RepoName, p.Version)
|
||||
target := path.Join("release", "v1", "providers", p.Namespace, p.Provider, p.Version)
|
||||
|
||||
err := CreateDir(target)
|
||||
if err != nil {
|
||||
|
|
@ -176,6 +199,28 @@ func (p *Provider) providerDirs() string {
|
|||
return target
|
||||
}
|
||||
|
||||
func (p *Provider) CreateWellKnown() error {
|
||||
log.Println("* Creating .well-known directory")
|
||||
pathString := path.Join(p.RootPath, "release", ".well-known")
|
||||
|
||||
err := os.MkdirAll(pathString, os.ModePerm)
|
||||
if err != nil && !errors.Is(err, fs.ErrExist) {
|
||||
return fmt.Errorf("error creating '%s' dir: %w", pathString, err)
|
||||
}
|
||||
|
||||
log.Println(" - Writing to .well-known/terraform.json file")
|
||||
err = os.WriteFile(
|
||||
fmt.Sprintf("%s/terraform.json", pathString),
|
||||
[]byte(`{"providers.v1": "/v1/providers/"}`),
|
||||
0644,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateDir(path string) error {
|
||||
log.Printf("* Creating %s directory", path)
|
||||
err := os.MkdirAll(path, os.ModePerm)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func GetShaSumContents(distPath, repoName, version string) (ShaSums, error) {
|
|||
slog.Warn("unable to parse SHA sum line", "line", line)
|
||||
continue
|
||||
}
|
||||
shaSums = append(shaSums, ShaSum{Sum: matches[0][0], Path: matches[0][1]})
|
||||
shaSums = append(shaSums, ShaSum{Sum: matches[0][1], Path: matches[0][2]})
|
||||
}
|
||||
return shaSums, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
publish2 "github.com/mhenselin/terraform-provider-stackitprivatepreview/cmd/cmd/publish"
|
||||
|
|
@ -27,7 +28,7 @@ var publishCmd = &cobra.Command{
|
|||
Use: "publish",
|
||||
Short: "Publish terraform provider",
|
||||
Long: `...`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
RunE: func(_ *cobra.Command, args []string) error {
|
||||
return publish()
|
||||
},
|
||||
}
|
||||
|
|
@ -96,47 +97,29 @@ func publish() error {
|
|||
GpgPubKeyFile: gpgPubKeyFile,
|
||||
Domain: domain,
|
||||
}
|
||||
err := p.GetRoot()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create release dir - only the contents of this need to be uploaded to S3
|
||||
log.Printf("* Creating reelase directory")
|
||||
err := os.Mkdir("release", os.ModePerm)
|
||||
if !errors.Is(err, fs.ErrExist) {
|
||||
return fmt.Errorf("error creating 'release' dir: %w", err)
|
||||
log.Printf("* Creating release directory")
|
||||
err = os.MkdirAll(path.Join(p.RootPath, "release"), os.ModePerm)
|
||||
if err != nil && !errors.Is(err, fs.ErrExist) {
|
||||
return fmt.Errorf("error creating '%s' dir: %w", path.Join(p.RootPath, "release"), err)
|
||||
}
|
||||
|
||||
// Create .wellKnown directory and terraform.json file
|
||||
err = wellKnown()
|
||||
err = p.CreateWellKnown()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating '.wellKnown' dir: %s", err)
|
||||
return fmt.Errorf("error creating '.well-known' dir: %w", err)
|
||||
}
|
||||
|
||||
err = p.CreateV1Dir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating 'v1' dir: %s", err)
|
||||
return fmt.Errorf("error creating 'v1' dir: %w", err)
|
||||
}
|
||||
|
||||
log.Println("📦 Packaged Terraform Provider for private registry.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// This establishes the "API" as a TF provider by responding with the correct JSON payload, by using static files
|
||||
func wellKnown() error {
|
||||
log.Println("* Creating .well-known directory")
|
||||
|
||||
err := os.Mkdir("release/.well-known", os.ModePerm)
|
||||
if !errors.Is(err, fs.ErrExist) {
|
||||
return fmt.Errorf("error creating 'release' dir: %w", err)
|
||||
}
|
||||
|
||||
log.Println(" - Writing to .well-known/terraform.json file")
|
||||
err = os.WriteFile(
|
||||
"release/.well-known/terraform.json",
|
||||
[]byte(`{"providers.v1": "/v1/providers/"}`),
|
||||
0644,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue