Ejemplo n.º 1
0
func (d Distribution) invalidate(m *Manifest) error {
	var items []*string
	for _, path := range invalidationPathsFromManifest(m) {
		items = append(items, aws.String(path))
	}
	invalidationID := fmt.Sprintf("static-%x", m.digest)
	input := &cloudfront.CreateInvalidationInput{
		DistributionID: aws.String(d.ID),
		InvalidationBatch: &cloudfront.InvalidationBatch{
			CallerReference: aws.String(invalidationID),
			Paths: &cloudfront.Paths{
				Quantity: aws.Long(int64(len(items))),
				Items:    items,
			},
		},
	}
	_, err := cfClient.CreateInvalidation(input)
	if err != nil {
		// printAWSError(err)
		return err
	}

	printer.Infof("Invalidated %d paths for %v\n", len(items), d.DomainName)
	for _, cname := range d.Aliases {
		printer.Infoln("  -> ", *cname)
	}
	return nil
}
Ejemplo n.º 2
0
func push(cmd *cobra.Command, args []string) {
	cfg := staticlib.NewConfig(configFilePath)
	staticlib.ConfigureAWS(cfg)

	source := staticlib.NewSource(cfg)
	defer source.Clean()
	fmt.Println(source)

	bucket := staticlib.NewBucket(cfg)
	fmt.Println(bucket)

	op := source.Capture()
	printOperationProgress("Scanning directory", op)
	if op.Err() != nil {
		os.Exit(70)
	}

	op = source.GenerateRedirects()
	printOperationProgress("Generating redirects", op)
	if op.Err() != nil {
		os.Exit(70)
	}

	op = source.CompressContents()
	printOperationProgress("Compressing", op)
	if op.Err() != nil {
		os.Exit(70)
	}

	op = source.DigestContents()
	printOperationProgress("Digesting", op)
	if op.Err() != nil {
		os.Exit(70)
	}

	op = bucket.Scan()
	printOperationProgress("Scanning target", op)
	if op.Err() != nil {
		os.Exit(70)
	}

	manifest := staticlib.NewManifest(&source, bucket, forceUpdate)

	printer.Debugln("Parallel uploads:", concurrency)
	if dryRun {
		printer.Infoln("*** Dry Run, operations are simulated ***")
	}

	pusher := staticlib.NewPusher(bucket, manifest)
	for result := range pusher.Push(concurrency, forceUpdate, dryRun) {
		printPushEntryRestult(result, verboseOutput)
	}

	if pusher.Err() != nil {
		fmt.Println("Encountered an error while pushing, abort")
		os.Exit(1)
	}

	printStats(pusher.Stats())
	pusher.Invalidate()
}