kraken

Форк
0
67 строк · 2.0 Кб
1
// Copyright (c) 2016-2019 Uber Technologies, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
package main
15

16
import (
17
	"flag"
18
	"net/http"
19
	"strings"
20

21
	"github.com/gorilla/mux"
22
	"github.com/uber/kraken/utils/log"
23
)
24

25
const listenAddr = "0.0.0.0:5055"
26

27
// mini service that receives docker push notifications and pull from local registry
28
func main() {
29
	var docker bool
30
	var source string
31
	var image string
32
	flag.StringVar(&source, "source", "", "source registry")
33
	flag.StringVar(&image, "image", "", "<repo>:<tag>")
34
	flag.BoolVar(&docker, "docker", false, "if to use docker")
35
	flag.Parse()
36

37
	// If source and image are specified, puller exits after pulling one image.
38
	if source != "" && image != "" {
39
		log.Infof("pulling image from %s/%s", source, image)
40
		str := strings.Split(image, ":")
41
		if len(str) != 2 {
42
			log.Fatalf("invalid image: %s", image)
43
		}
44
		if err := PullImage(source, str[0], str[1], docker); err != nil {
45
			log.Fatal(err)
46
		}
47
		return
48
	}
49

50
	// NotificationHandler pulls image once it receives notification from docker registry.
51
	// It is a long running process.
52
	notification, err := NewNotificationHandler(200, docker)
53
	if err != nil {
54
		log.Fatal(err)
55
	}
56

57
	router := mux.NewRouter()
58
	router.HandleFunc("/", HealthHandler).
59
		Methods("GET")
60
	router.HandleFunc("/notifications", notification.Handler).
61
		Methods("POST")
62
	router.HandleFunc("/notifications", HealthHandler).
63
		Methods("GET")
64

65
	log.Infof("listening on %s", listenAddr)
66
	log.Fatal(http.ListenAndServe(listenAddr, router))
67
}
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.