fix: builder and sdk changes (#81)
## 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)
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-authored-by: marcel.henselin <marcel.henselin@stackit.cloud>
Reviewed-on: #81
This commit is contained in:
parent
635a9abf20
commit
1033d7e034
145 changed files with 5944 additions and 5298 deletions
139
generator/cmd/publishCmd.go
Normal file
139
generator/cmd/publishCmd.go
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
publish2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/generator/cmd/publish"
|
||||
)
|
||||
|
||||
var (
|
||||
namespace string
|
||||
domain string
|
||||
providerName string
|
||||
distPath string
|
||||
repoName string
|
||||
version string
|
||||
gpgFingerprint string
|
||||
gpgPubKeyFile string
|
||||
)
|
||||
|
||||
var publishCmd = &cobra.Command{
|
||||
Use: "publish",
|
||||
Short: "Publish terraform provider",
|
||||
Long: `...`,
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
return publish()
|
||||
},
|
||||
}
|
||||
|
||||
func init() { //nolint:gochecknoinits //this is the standard way to set up cobra commands
|
||||
publishCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace for the Terraform registry.")
|
||||
publishCmd.Flags().StringVarP(&domain, "domain", "d", "", "Domain for the Terraform registry.")
|
||||
publishCmd.Flags().StringVarP(&providerName, "providerName", "p", "", "ProviderName for the Terraform registry.")
|
||||
publishCmd.Flags().StringVarP(&distPath, "distPath", "x", "dist", "Dist Path for the Terraform registry.")
|
||||
publishCmd.Flags().StringVarP(&repoName, "repoName", "r", "", "RepoName for the Terraform registry.")
|
||||
publishCmd.Flags().StringVarP(&version, "version", "v", "", "Version for the Terraform registry.")
|
||||
publishCmd.Flags().StringVarP(
|
||||
&gpgFingerprint,
|
||||
"gpgFingerprint",
|
||||
"f",
|
||||
"",
|
||||
"GPG Fingerprint for the Terraform registry.",
|
||||
)
|
||||
publishCmd.Flags().StringVarP(
|
||||
&gpgPubKeyFile,
|
||||
"gpgPubKeyFile",
|
||||
"k",
|
||||
"",
|
||||
"GPG PubKey file name for the Terraform registry.",
|
||||
)
|
||||
|
||||
err := publishCmd.MarkFlagRequired("namespace")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("domain")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("providerName")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("gpgFingerprint")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("gpgPubKeyFile")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("repoName")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("version")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("gpgFingerprint")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = publishCmd.MarkFlagRequired("gpgPubKeyFile")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func NewPublishCmd() *cobra.Command {
|
||||
return publishCmd
|
||||
}
|
||||
|
||||
func publish() error {
|
||||
log.Println("📦 Packaging Terraform Provider for private registry...")
|
||||
p := publish2.Provider{
|
||||
Namespace: namespace,
|
||||
Provider: providerName,
|
||||
DistPath: filepath.Clean(distPath) + "/",
|
||||
RepoName: repoName,
|
||||
Version: version,
|
||||
GpgFingerprint: gpgFingerprint,
|
||||
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 release directory")
|
||||
//nolint:gosec // this directory is not sensitive, so we can use 0750
|
||||
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 = p.CreateWellKnown()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating '.well-known' dir: %w", err)
|
||||
}
|
||||
|
||||
err = p.CreateV1Dir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating 'v1' dir: %w", err)
|
||||
}
|
||||
|
||||
log.Println("📦 Packaged Terraform Provider for private registry.")
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue