Skip to content

Commit

Permalink
Add interfaces for Image Watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Oct 5, 2020
1 parent 8ff78b2 commit ca360fc
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["registry.go"],
importpath = "github.com/pipe-cd/pipe/pkg/app/piped/containerregistry",
srcs = ["gcs.go"],
importpath = "github.com/pipe-cd/pipe/pkg/app/piped/imageprovider/gcs",
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package containerregistry watches the configured container registry
// for the new images.
package containerregistry
package gcs
8 changes: 8 additions & 0 deletions pkg/app/piped/imagewatcher/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["watcher.go"],
importpath = "github.com/pipe-cd/pipe/pkg/app/piped/imagewatcher",
visibility = ["//visibility:public"],
)
76 changes: 76 additions & 0 deletions pkg/app/piped/imagewatcher/watcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2020 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package imagewatcher provides a piped component
// that periodically checks the image registry and updates
// the image if there are differences with Git.
package imagewatcher

import (
"context"
"time"
)

type Watcher interface {
Run(context.Context) error
}

type watcher struct {
timer *time.Timer
}

type imageRepos map[string]imageRepo
type imageRepo struct {
}

func NewWatcher(interval time.Duration) Watcher {
return &watcher{
timer: time.NewTimer(interval),
}
}

func (w *watcher) Run(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return nil
case <-w.timer.C:
reposInReg := w.fetchImageReposFromRegistry()
reposInGit := w.fetchImageReposFromGit()
outdated := calculateChanges(reposInReg, reposInGit)
if err := w.update(outdated); err != nil {
// FIXME: Emit log
}
}
}
return nil
}

func (w *watcher) fetchImageReposFromRegistry() imageRepos {
return nil
}

func (w *watcher) fetchImageReposFromGit() imageRepos {
return nil
}

func (w *watcher) update(targets imageRepos) error {
return nil
}

// calculateChanges compares between image repos in the image registry and
// image repos in git. And then gives back image repos to be updated.
func calculateChanges(x, y imageRepos) imageRepos {
return nil
}
1 change: 0 additions & 1 deletion pkg/model/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ go_test(
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//pkg/crypto:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@org_golang_x_crypto//bcrypt:go_default_library",
],
Expand Down

0 comments on commit ca360fc

Please sign in to comment.