main.go 1.95 KB
Newer Older
Mustafa Gezen's avatar
Mustafa Gezen committed
1
2
3
package main

import (
4
5
6
7
	"cloud.google.com/go/storage"
	"context"
	"log"
	"strings"
Mustafa Gezen's avatar
Mustafa Gezen committed
8

9
10
	"github.com/mstg/srpmproc/internal"
	"github.com/spf13/cobra"
Mustafa Gezen's avatar
Mustafa Gezen committed
11
12
13
)

var (
14
15
16
17
18
19
20
	sourceRpm         string
	sshKeyLocation    string
	sshUser           string
	upstreamPrefix    string
	branch            string
	gcsBucket         string
	debrandedTarballs []string
Mustafa Gezen's avatar
Mustafa Gezen committed
21
22
23
)

var root = &cobra.Command{
24
25
	Use: "srpmproc",
	Run: mn,
Mustafa Gezen's avatar
Mustafa Gezen committed
26
27
28
}

func mn(_ *cobra.Command, _ []string) {
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		log.Fatalf("could not create gcloud client: %v", err)
	}

	sourceRpmLocation := ""
	if strings.HasPrefix(sourceRpm, "file://") {
		sourceRpmLocation = strings.TrimPrefix(sourceRpm, "file://")
	} else {
		log.Fatal("non-local SRPMs are currently not supported")
	}

	internal.ProcessRPM(&internal.ProcessData{
		RpmLocation:    sourceRpmLocation,
		UpstreamPrefix: upstreamPrefix,
		SshKeyLocation: sshKeyLocation,
		SshUser:        sshUser,
		Branch:         branch,
		Bucket:         client.Bucket(gcsBucket),
	})
Mustafa Gezen's avatar
Mustafa Gezen committed
50
51
52
}

func main() {
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
	root.Flags().StringVar(&sourceRpm, "source-rpm", "", "Location of RPM to process")
	_ = root.MarkFlagRequired("source-rpm")
	root.Flags().StringVar(&upstreamPrefix, "upstream-prefix", "", "Upstream git repository prefix")
	_ = root.MarkFlagRequired("upstream-prefix")
	root.Flags().StringVar(&branch, "branch", "", "Upstream branch")
	_ = root.MarkFlagRequired("branch")
	root.Flags().StringVar(&gcsBucket, "gcs-bucket", "", "Bucket to use as blob storage")
	_ = root.MarkFlagRequired("gcs-bucket")

	root.Flags().StringVar(&sshKeyLocation, "ssh-key-location", "", "Location of the SSH key to use to authenticate against upstream (Optional)")
	root.Flags().StringVar(&sshUser, "ssh-user", "git", "SSH User (Optional, default git)")
	root.Flags().StringArrayVar(&debrandedTarballs, "debranded-tarball", []string{}, "GCS urls to debranded tarballs (stage 2) (Optional)")

	if err := root.Execute(); err != nil {
		log.Fatal(err)
	}
Mustafa Gezen's avatar
Mustafa Gezen committed
69
}