From a6ef32eefdde2980e5301c8574c79e5f0c260461 Mon Sep 17 00:00:00 2001 From: Maksym Date: Sun, 24 Sep 2023 20:39:36 +0100 Subject: [PATCH 1/3] chore: refactor dependencies feat: refine config with ttl params fix: always set ttl while storing indexes breaking: CACHE_TTL env renamed to MANIFEST_CACHE_TTL Signed-off-by: Maksym Trofimenko --- README.md | 4 +- cmd/serve.go | 41 +++++++++--------- registry/blobs/blobs.go | 8 ++-- registry/errors/error.go | 5 +++ registry/manifest/cache.go | 8 ++++ registry/manifest/charts.go | 36 ++++++++-------- registry/manifest/config.go | 10 +++++ registry/manifest/manifest.go | 42 ++++++++---------- registry/registry/handler.go | 5 +++ registry/registry/registry.go | 81 ++++++++++++++--------------------- 10 files changed, 123 insertions(+), 117 deletions(-) create mode 100644 registry/manifest/cache.go create mode 100644 registry/manifest/config.go create mode 100644 registry/registry/handler.go diff --git a/README.md b/README.md index 3d7a53d..b168354 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,9 @@ There are not many options in configure the application except the following. * `PORT` - specifies port, default `9000` * `DEBUG` - enabled debug if it's `TRUE` -* `CACHE_TTL` - for how many seconds we have to store manifest and related blobs, default value is 60 +* `MANIFEST_CACHE_TTL` - for how long we have stores manifest and its related blobs, the default value is `60` seconds. +* `INDEX_CACHE_TTL` - for how long we store chart index file content, the default value is `14400` seconds (4h) +* `INDEX_ERROR_CACHE_TTL` - for how long we do not try to obtain index files again if it's failed for some reason. The default value is `30` seconds. * `USE_TLS` - enabled HTTP over TLS diff --git a/cmd/serve.go b/cmd/serve.go index 7e417f2..4e59921 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -17,8 +17,9 @@ package cmd import ( "errors" "fmt" - "github.com/container-registry/helm-charts-oci-proxy/registry/blobs/handler" + "github.com/container-registry/helm-charts-oci-proxy/registry/blobs" "github.com/container-registry/helm-charts-oci-proxy/registry/blobs/handler/mem" + "github.com/container-registry/helm-charts-oci-proxy/registry/manifest" "github.com/container-registry/helm-charts-oci-proxy/registry/registry" "github.com/dgraph-io/ristretto" "k8s.io/utils/env" @@ -60,7 +61,10 @@ Contents are only stored in memory, and when the process exits, pushed data is l } debug, _ := env.GetBool("DEBUG", false) - cacheTTL, _ := env.GetInt("CACHE_TTL", 60) + cacheTTL, _ := env.GetInt("MANIFEST_CACHE_TTL", 60) // 1 minute + indexCacheTTL, _ := env.GetInt("INDEX_CACHE_TTL", 3600*4) // 4 hours + indexErrorCacheTTL, _ := env.GetInt("INDEX_ERROR_CACHE_TTL", 30) // 30 seconds + useTLS, _ := env.GetBool("USE_TLS", false) certFile := env.GetString("CERT_FILE", "certs/registry.pem") keyfileFile := env.GetString("KEY_FILE", "certs/registry-key.pem") @@ -81,30 +85,25 @@ Contents are only stored in memory, and when the process exits, pushed data is l l.Fatalln(err) } - //db, err := badger.Open(badger.DefaultOptions(dbLocation). - // WithCompression(options.None). - // WithBloomFalsePositive(0). - // WithMemTableSize(1024 * 1204 * 8), //8mb instead of 64 - //) - //if err != nil { - // log.Fatal(err) - //} - //defer db.Close() + blobsHandler := mem.NewMemHandler() - var blobsHandler handler.BlobHandler + manifests := manifest.NewManifests(ctx, blobsHandler, manifest.Config{ + Debug: debug, + CacheTTL: time.Duration(cacheTTL) * time.Second, + IndexCacheTTL: time.Duration(indexCacheTTL) * time.Second, + IndexErrorCacheTTl: time.Duration(indexErrorCacheTTL) * time.Second, + }, indexCache, l) - //blobsHandler = badger2.NewHandler(db) - blobsHandler = mem.NewMemHandler() + blobsHttpHandler := blobs.NewBlobs(blobsHandler, l) //blobsHandler = file.NewHandler(dbLocation) s := &http.Server{ ReadHeaderTimeout: 5 * time.Second, // prevent slowloris, quiet linter - Handler: registry.New(ctx, - registry.Debug(debug), - registry.CacheTTL(cacheTTL), - registry.Logger(l), - registry.IndexCache(indexCache), - registry.BlobsHandler(blobsHandler), - ), + Handler: registry.New( + manifests.Handle, + blobsHttpHandler.Handle, + manifests.HandleTags, + manifests.HandleCatalog, + registry.Debug(debug), registry.Logger(l)), } errCh := make(chan error) diff --git a/registry/blobs/blobs.go b/registry/blobs/blobs.go index 3a52306..a19a13d 100644 --- a/registry/blobs/blobs.go +++ b/registry/blobs/blobs.go @@ -7,8 +7,8 @@ import ( "github.com/container-registry/helm-charts-oci-proxy/registry/blobs/handler" "github.com/container-registry/helm-charts-oci-proxy/registry/errors" v1 "github.com/google/go-containerregistry/pkg/v1" + "github.com/sirupsen/logrus" "io" - "log" "net/http" "path" "strings" @@ -23,14 +23,14 @@ type Blobs struct { // Each upload gets a unique id that writes occur to until finalized. // Temporary storage lock sync.Mutex - log *log.Logger + log logrus.StdLogger } -func NewBlobs(blobHandler handler.BlobHandler, log *log.Logger) *Blobs { +func NewBlobs(blobHandler handler.BlobHandler, log logrus.StdLogger) *Blobs { return &Blobs{handler: blobHandler, log: log} } -func (b *Blobs) Handle(resp http.ResponseWriter, req *http.Request) *errors.RegError { +func (b *Blobs) Handle(resp http.ResponseWriter, req *http.Request) error { ctx := req.Context() elem := strings.Split(req.URL.Path, "/") diff --git a/registry/errors/error.go b/registry/errors/error.go index 1d9ed9e..26f0da6 100644 --- a/registry/errors/error.go +++ b/registry/errors/error.go @@ -16,6 +16,7 @@ package errors import ( "encoding/json" + "fmt" "net/http" ) @@ -25,6 +26,10 @@ type RegError struct { Message string } +func (r *RegError) Error() string { + return fmt.Sprintf("error: status: %d; code: %s; %s", r.Status, r.Code, r.Message) +} + func (r *RegError) Write(resp http.ResponseWriter) error { resp.WriteHeader(r.Status) diff --git a/registry/manifest/cache.go b/registry/manifest/cache.go new file mode 100644 index 0000000..4ab96f1 --- /dev/null +++ b/registry/manifest/cache.go @@ -0,0 +1,8 @@ +package manifest + +import "time" + +type Cache interface { + SetWithTTL(key, value interface{}, cost int64, ttl time.Duration) bool + Get(key interface{}) (interface{}, bool) +} diff --git a/registry/manifest/charts.go b/registry/manifest/charts.go index 6b969e5..1dd3520 100644 --- a/registry/manifest/charts.go +++ b/registry/manifest/charts.go @@ -19,7 +19,6 @@ import ( "path/filepath" "sigs.k8s.io/yaml" "strings" - "time" ) func (m *Manifests) prepareChart(ctx context.Context, repo string, reference string) *errors.RegError { @@ -68,7 +67,7 @@ func (m *Manifests) prepareChart(ctx context.Context, repo string, reference str u, err := url.Parse(chartVer.URLs[0]) if err != nil { - errors.RegErrInternal(err) + return errors.RegErrInternal(err) } if u.IsAbs() { downloadUrl = u.String() @@ -94,6 +93,7 @@ func (m *Manifests) prepareChart(ctx context.Context, repo string, reference str ocispec.AnnotationTitle: "$config", }, } + err = memStore.Push(ctx, desc, bytes.NewReader(configData)) if err != nil { return errors.RegErrInternal(err) @@ -159,21 +159,19 @@ func (m *Manifests) GetIndex(repoURLPath string) (*repo.IndexFile, error) { err error } - if m.indexCache == nil { - return m.downloadIndex(repoURLPath) - } - - c, ok := m.indexCache.Get(repoURLPath) + c, ok := m.cache.Get(repoURLPath) if !ok || c == nil { // nothing in the cache res := &cacheResp{} res.c, res.err = m.downloadIndex(repoURLPath) + + var ttl = m.config.IndexCacheTTL if res.err != nil { - m.indexCache.SetWithTTL(repoURLPath, res, 10, time.Second*5) - } else { - m.indexCache.Set(repoURLPath, res, 10) + // cache error too to avoid external resource exhausting + ttl = m.config.IndexErrorCacheTTl } + m.cache.SetWithTTL(repoURLPath, res, 1000, ttl) return res.c, res.err } @@ -186,7 +184,7 @@ func (m *Manifests) GetIndex(repoURLPath string) (*repo.IndexFile, error) { func (m *Manifests) downloadIndex(repoURLPath string) (*repo.IndexFile, error) { url := fmt.Sprintf("https://%s/index.yaml", repoURLPath) - if m.debug { + if m.config.Debug { m.log.Printf("download index: %s\n", url) } data, err := m.getIndexBytes(url) @@ -223,25 +221,25 @@ func (m *Manifests) downloadIndex(repoURLPath string) (*repo.IndexFile, error) { } func (m *Manifests) getIndexBytes(url string) ([]byte, error) { - if m.indexCache == nil { - return m.download(url) - } + type cacheResp struct { c []byte err error } - c, ok := m.indexCache.Get(url) + c, ok := m.cache.Get(url) if !ok || c == nil { // nothing in the cache res := &cacheResp{} res.c, res.err = m.download(url) + + var ttl = m.config.IndexCacheTTL if res.err != nil { - m.indexCache.SetWithTTL(url, res, 10, time.Second*5) - } else { - m.indexCache.Set(url, res, 10) + // cache error too to avoid external resource exhausting + ttl = m.config.IndexErrorCacheTTl } + m.cache.SetWithTTL(url, res, 1000, ttl) return res.c, res.err } @@ -254,7 +252,7 @@ func (m *Manifests) getIndexBytes(url string) ([]byte, error) { } func (m *Manifests) download(url string) ([]byte, error) { - if m.debug { + if m.config.Debug { m.log.Printf("downloading : %s\n", url) } resp, err := http.Get(url) diff --git a/registry/manifest/config.go b/registry/manifest/config.go new file mode 100644 index 0000000..f39df70 --- /dev/null +++ b/registry/manifest/config.go @@ -0,0 +1,10 @@ +package manifest + +import "time" + +type Config struct { + Debug bool + CacheTTL time.Duration // for how long store manifest + IndexCacheTTL time.Duration + IndexErrorCacheTTl time.Duration +} diff --git a/registry/manifest/manifest.go b/registry/manifest/manifest.go index a289da1..b8b4780 100644 --- a/registry/manifest/manifest.go +++ b/registry/manifest/manifest.go @@ -9,10 +9,9 @@ import ( "fmt" "github.com/container-registry/helm-charts-oci-proxy/registry/blobs/handler" "github.com/container-registry/helm-charts-oci-proxy/registry/errors" - "github.com/dgraph-io/ristretto" v1 "github.com/google/go-containerregistry/pkg/v1" + "github.com/sirupsen/logrus" "io" - "log" "net/http" "sort" "strconv" @@ -39,25 +38,22 @@ type Manifest struct { type Manifests struct { // maps repo -> Manifest tag/digest -> Manifest - manifests map[string]map[string]Manifest - lock sync.Mutex - log *log.Logger - - debug bool - - indexCache *ristretto.Cache + manifests map[string]map[string]Manifest + lock sync.Mutex + log logrus.StdLogger + cache Cache blobHandler handler.BlobHandler - cacheTTL int + config Config } -func NewManifests(ctx context.Context, debug bool, indexCache *ristretto.Cache, cacheTTL int, blobHandler handler.BlobHandler, l *log.Logger) *Manifests { +func NewManifests(ctx context.Context, blobHandler handler.BlobHandler, config Config, cache Cache, log logrus.StdLogger) *Manifests { ma := &Manifests{ - debug: debug, + manifests: map[string]map[string]Manifest{}, - indexCache: indexCache, blobHandler: blobHandler, - log: l, - cacheTTL: cacheTTL, + log: log, + config: config, + cache: cache, } go func() { @@ -66,13 +62,13 @@ func NewManifests(ctx context.Context, debug bool, indexCache *ristretto.Cache, for { select { case <-ticker.C: - if ma.debug { + if ma.config.Debug { ma.log.Println("cleanup cycle") } ma.lock.Lock() for _, m := range ma.manifests { for k, v := range m { - if v.CreatedAt.Before(time.Now().Add(-time.Second * time.Duration(ma.cacheTTL))) { + if v.CreatedAt.Before(time.Now().Add(-ma.config.CacheTTL)) { // delete delete(m, k) if delHandler, ok := ma.blobHandler.(handler.BlobDeleteHandler); ok { @@ -81,11 +77,11 @@ func NewManifests(ctx context.Context, debug bool, indexCache *ristretto.Cache, if err != nil { continue } - if ma.debug { - l.Printf("deleting blob %s", h.String()) + if ma.config.Debug { + log.Printf("deleting blob %s", h.String()) } if err = delHandler.Delete(ctx, "", h); err != nil { - l.Println(err) + log.Println(err) } } } @@ -104,7 +100,7 @@ func NewManifests(ctx context.Context, debug bool, indexCache *ristretto.Cache, // https://github.com/opencontainers/distribution-spec/blob/master/spec.md#pulling-an-image-manifest // https://github.com/opencontainers/distribution-spec/blob/master/spec.md#pushing-an-image -func (m *Manifests) Handle(resp http.ResponseWriter, req *http.Request) *errors.RegError { +func (m *Manifests) Handle(resp http.ResponseWriter, req *http.Request) error { elem := strings.Split(req.URL.Path, "/") if len(elem) < 3 { @@ -224,7 +220,7 @@ func (m *Manifests) Handle(resp http.ResponseWriter, req *http.Request) *errors. } } -func (m *Manifests) HandleTags(resp http.ResponseWriter, req *http.Request) *errors.RegError { +func (m *Manifests) HandleTags(resp http.ResponseWriter, req *http.Request) error { elem := strings.Split(req.URL.Path, "/") if len(elem) < 4 { return &errors.RegError{ @@ -349,7 +345,7 @@ func (m *Manifests) Write(repo string, name string, n Manifest) error { return nil } -func (m *Manifests) HandleCatalog(resp http.ResponseWriter, req *http.Request) *errors.RegError { +func (m *Manifests) HandleCatalog(resp http.ResponseWriter, req *http.Request) error { query := req.URL.Query() nStr := query.Get("n") n := 10000 diff --git a/registry/registry/handler.go b/registry/registry/handler.go new file mode 100644 index 0000000..0a49e66 --- /dev/null +++ b/registry/registry/handler.go @@ -0,0 +1,5 @@ +package registry + +import "net/http" + +type Handler func(resp http.ResponseWriter, req *http.Request) error diff --git a/registry/registry/registry.go b/registry/registry/registry.go index 3e28c15..dd62054 100644 --- a/registry/registry/registry.go +++ b/registry/registry/registry.go @@ -1,15 +1,11 @@ package registry import ( - "context" "encoding/json" "fmt" - "github.com/container-registry/helm-charts-oci-proxy/registry/blobs" - "github.com/container-registry/helm-charts-oci-proxy/registry/blobs/handler" "github.com/container-registry/helm-charts-oci-proxy/registry/errors" "github.com/container-registry/helm-charts-oci-proxy/registry/helper" - "github.com/container-registry/helm-charts-oci-proxy/registry/manifest" - "github.com/dgraph-io/ristretto" + "github.com/sirupsen/logrus" "io" "log" "net/http" @@ -17,19 +13,19 @@ import ( ) type Registry struct { - log *log.Logger + log logrus.StdLogger // to operate blobs directly from registry - blobsHandler handler.BlobHandler - blobs *blobs.Blobs `json:"blobs"` + blobs Handler `json:"blobs"` // - manifests *manifest.Manifests `json:"manifests"` - debug bool - cacheTTL int - indexCache *ristretto.Cache + manifests Handler `json:"manifests"` + tags Handler + catalog Handler + + debug bool } -func (r *Registry) v2(resp http.ResponseWriter, req *http.Request) *errors.RegError { +func (r *Registry) v2(resp http.ResponseWriter, req *http.Request) error { /// debug // if req.URL.Path == "/" || req.URL.Path == "" { return r.homeHandler(resp, req) @@ -41,23 +37,22 @@ func (r *Registry) v2(resp http.ResponseWriter, req *http.Request) *errors.RegEr return r.harborInfoHandler(resp) } if helper.IsBlob(req) { - return r.blobs.Handle(resp, req) + return r.blobs(resp, req) } if helper.IsManifest(req) { - return r.manifests.Handle(resp, req) + return r.manifests(resp, req) } if helper.IsTags(req) { - return r.manifests.HandleTags(resp, req) + return r.tags(resp, req) } if helper.IsCatalog(req) { - return r.manifests.HandleCatalog(resp, req) + return r.catalog(resp, req) } if helper.IsV2(req) { resp.Header().Set("Docker-Distribution-API-Version", "registry/2.0") resp.WriteHeader(200) return nil } - return &errors.RegError{ Status: http.StatusNotFound, Code: "METHOD_UNKNOWN", @@ -66,7 +61,7 @@ func (r *Registry) v2(resp http.ResponseWriter, req *http.Request) *errors.RegEr } // api/version -func (r *Registry) versionHandler(resp http.ResponseWriter) *errors.RegError { +func (r *Registry) versionHandler(resp http.ResponseWriter) error { res := struct { Version string `json:"version"` }{ @@ -80,7 +75,7 @@ func (r *Registry) versionHandler(resp http.ResponseWriter) *errors.RegError { } // api/v2.0/systeminfo -func (r *Registry) harborInfoHandler(resp http.ResponseWriter) *errors.RegError { +func (r *Registry) harborInfoHandler(resp http.ResponseWriter) error { res := struct { HarborVersion string `json:"harbor_version"` CurrentTime time.Time `json:"current_time"` @@ -95,15 +90,19 @@ func (r *Registry) harborInfoHandler(resp http.ResponseWriter) *errors.RegError return nil } -func (r *Registry) homeHandler(w http.ResponseWriter, req *http.Request) *errors.RegError { +func (r *Registry) homeHandler(w http.ResponseWriter, req *http.Request) error { http.Redirect(w, req, "https://container-registry.com/helm-charts-oci-proxy/", 302) return nil } func (r *Registry) root(resp http.ResponseWriter, req *http.Request) { - if rErr := r.v2(resp, req); rErr != nil { - r.log.Printf("%s %s %d %s %s", req.Method, req.URL, rErr.Status, rErr.Code, rErr.Message) - _ = rErr.Write(resp) + if err := r.v2(resp, req); err != nil { + if regErr, ok := err.(*errors.RegError); ok { + r.log.Printf("%s %s %d %s %s", req.Method, req.URL, regErr.Status, regErr.Code, regErr.Message) + _ = regErr.Write(resp) + } else { + http.Error(resp, err.Error(), http.StatusInternalServerError) + } return } if r.debug { @@ -113,17 +112,19 @@ func (r *Registry) root(resp http.ResponseWriter, req *http.Request) { // New returns a handler which implements the docker registry protocol. // It should be registered at the site root. -func New(ctx context.Context, opts ...Option) http.Handler { +func New(manifests Handler, blobs Handler, tags Handler, catalog Handler, opts ...Option) http.Handler { r := &Registry{ - log: log.Default(), //default logger + manifests: manifests, + blobs: blobs, + tags: tags, + catalog: catalog, } for _, o := range opts { o(r) } - - r.blobs = blobs.NewBlobs(r.blobsHandler, r.log) - r.manifests = manifest.NewManifests(ctx, r.debug, r.indexCache, r.cacheTTL, r.blobsHandler, r.log) - + if r.log == nil { + r.log = log.Default() + } return http.HandlerFunc(r.root) } @@ -132,36 +133,18 @@ func New(ctx context.Context, opts ...Option) http.Handler { type Option func(r *Registry) // Logger overrides the logger used to record requests to the registry. -func Logger(l *log.Logger) Option { +func Logger(l logrus.StdLogger) Option { return func(r *Registry) { r.log = l } } -func IndexCache(c *ristretto.Cache) Option { - return func(r *Registry) { - r.indexCache = c - } -} - -func BlobsHandler(bh handler.BlobHandler) Option { - return func(r *Registry) { - r.blobsHandler = bh - } -} - func Debug(v bool) Option { return func(r *Registry) { r.debug = v } } -func CacheTTL(v int) Option { - return func(r *Registry) { - r.cacheTTL = v - } -} - func prettyEncode(data interface{}, out io.Writer) error { enc := json.NewEncoder(out) enc.SetIndent("", " ") From b66c5cf4efa1facf36cd4dd518313f56bd177bf8 Mon Sep 17 00:00:00 2001 From: Maksym Trofimenko Date: Sun, 22 Oct 2023 21:42:15 +0100 Subject: [PATCH 2/3] add github actions Signed-off-by: Maksym Trofimenko --- .github/workflows/build-and-push.yaml | 101 ++++++++++++++++++++++++++ .github/workflows/publish_chart.yml | 5 +- do.sh | 5 ++ 3 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build-and-push.yaml diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml new file mode 100644 index 0000000..79788bf --- /dev/null +++ b/.github/workflows/build-and-push.yaml @@ -0,0 +1,101 @@ +name: "Build container images" +on: + pull_request: + branches: + - main + paths-ignore: + - 'docs/**' + push: + tags: + - 'v*.*.*' + branches: + - main + paths-ignore: + - 'docs/**' +jobs: + tests: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '1.20' + - name: Setup Go Cache Paths + id: go-cache-paths + run: | + echo "go-build=$(go env GOCACHE)" >>$GITHUB_OUTPUT + echo "go-mod=$(go env GOMODCACHE)" >>$GITHUB_OUTPUT + - name: Go Build Cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + - name: Go Mod Cache + uses: actions/cache@v3 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} + - name: Run Unit Tests + id: run-tests + run: | + ./do.sh test + + prepare: + name: Prepare + runs-on: ubuntu-latest + needs: [tests] + outputs: + env_name: ${{ env.ENV_NAME }} + tag_name: ${{ env.TAG_NAME }} + steps: + - name: Export Variables + run: echo "DATETIME=$(date +%s)" >> $GITHUB_ENV + + - name: Staging (merge) + if: github.event_name != 'pull_request' && github.ref_name == 'main' + run: | + echo "ENV_NAME=staging" >> "$GITHUB_ENV" + echo "TAG_NAME=staging-${{ env.DATETIME }}" >> "$GITHUB_ENV" + + - name: Staging (PR) + if: github.event_name == 'pull_request' && github.head_ref == 'main' + run: | + echo "ENV_NAME=staging" >> "$GITHUB_ENV" + echo "TAG_NAME=staging-${{ env.DATETIME }}" >> "$GITHUB_ENV" + + - name: Release Tag + if: startsWith(github.event.ref, 'refs/tags/v') + run: | + echo "ENV_NAME=production" >> "$GITHUB_ENV" + TAG=${GITHUB_REF#refs/*/} + echo "TAG_NAME=${TAG#v}" >> "$GITHUB_ENV" + + build-container: + name: Build + runs-on: ubuntu-latest + needs: prepare + environment: ${{ needs.prepare.outputs.env_name }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ vars.REGISTRY_ADDR }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build & push container image + id: build-container + env: + REPOSITORY: ${{ vars.SERVER_IMAGE_REPO }} + IMAGE_TAG: ${{ needs.prepare.outputs.tag_name }} + run: | + docker build --build-arg="VERSION=$IMAGE_TAG" -t $REPOSITORY:$IMAGE_TAG . + docker push $REPOSITORY:$IMAGE_TAG + + + + diff --git a/.github/workflows/publish_chart.yml b/.github/workflows/publish_chart.yml index 3807358..02cfbc6 100644 --- a/.github/workflows/publish_chart.yml +++ b/.github/workflows/publish_chart.yml @@ -1,5 +1,4 @@ - -name: "Build and Publish" +name: "Publish Chart" on: pull_request: @@ -14,7 +13,7 @@ on: - main jobs: - build: + publish-chart: runs-on: ubuntu-latest outputs: CHART_VERSION: ${{ steps.version.outputs.version }} diff --git a/do.sh b/do.sh index dc203e3..a0ba888 100755 --- a/do.sh +++ b/do.sh @@ -31,6 +31,11 @@ run() { tests() { go test -v ./... } + +list_of_actions() { + act -l --container-architecture linux/amd64 +} + "$@" # <- execute the task [ "$#" -gt 0 ] || printf "Usage:\n\t./do.sh %s\n" "($(compgen -A function | grep '^[^_]' | paste -sd '|' -))" From 8d7933f1196e43fbdb7e0188e666e75e5a3cb9de Mon Sep 17 00:00:00 2001 From: Maksym Trofimenko Date: Sun, 22 Oct 2023 22:08:39 +0100 Subject: [PATCH 3/3] fix gh unit tests job Signed-off-by: Maksym Trofimenko --- .github/workflows/build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index 79788bf..2e89d76 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -40,7 +40,7 @@ jobs: - name: Run Unit Tests id: run-tests run: | - ./do.sh test + ./do.sh tests prepare: name: Prepare