Skip to content

Commit

Permalink
Update handling of all-in-one Docker images (#4608)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Oct 9, 2024
1 parent 7b0c691 commit e090e53
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 39 deletions.
17 changes: 14 additions & 3 deletions tools/definedockertag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

// Package main contains tool for defining Docker image tags on CI.
//
//nolint:goconst // "ferretdb" means different things
package main

import (
Expand Down Expand Up @@ -164,6 +166,15 @@ func define(getenv githubactions.GetenvFunc) (*result, error) {
return res, nil
}

// allInOneRepo returns a part of Docker repository name for the given GitHub repository name.
func allInOneRepo(repo string) string {
if repo == "ferretdb" {
return "all-in-one"
}

return repo + "-all-in-one"
}

// defineForPR defines Docker image names and tags for pull requests.
func defineForPR(owner, repo, branch string) *result {
// for branches like "dependabot/submodules/XXX"
Expand All @@ -172,7 +183,7 @@ func defineForPR(owner, repo, branch string) *result {

res := &result{
allInOneImages: []string{
fmt.Sprintf("ghcr.io/%s/all-in-one:pr-%s", owner, branch),
fmt.Sprintf("ghcr.io/%s/%s:pr-%s", owner, allInOneRepo(repo), branch),
},
developmentImages: []string{
fmt.Sprintf("ghcr.io/%s/%s-dev:pr-%s", owner, repo, branch),
Expand Down Expand Up @@ -201,7 +212,7 @@ func defineForBranch(owner, repo, branch string) (*result, error) {

res := &result{
allInOneImages: []string{
fmt.Sprintf("ghcr.io/%s/all-in-one:%s", owner, branch),
fmt.Sprintf("ghcr.io/%s/%s:%s", owner, allInOneRepo(repo), branch),
},
developmentImages: []string{
fmt.Sprintf("ghcr.io/%s/%s-dev:%s", owner, repo, branch),
Expand Down Expand Up @@ -232,7 +243,7 @@ func defineForTag(owner, repo string, tags []string) *result {
res := new(result)

for _, t := range tags {
res.allInOneImages = append(res.allInOneImages, fmt.Sprintf("ghcr.io/%s/all-in-one:%s", owner, t))
res.allInOneImages = append(res.allInOneImages, fmt.Sprintf("ghcr.io/%s/%s:%s", owner, allInOneRepo(repo), t))
res.developmentImages = append(res.developmentImages, fmt.Sprintf("ghcr.io/%s/%s-dev:%s", owner, repo, t))
res.productionImages = append(res.productionImages, fmt.Sprintf("ghcr.io/%s/%s:%s", owner, repo, t))
}
Expand Down
72 changes: 36 additions & 36 deletions tools/definedockertag/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:pr-define-docker-tag",
"ghcr.io/otherorg/otherrepo-all-in-one:pr-define-docker-tag",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:pr-define-docker-tag",
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:pr-mongo-go-driver-29d768e",
"ghcr.io/otherorg/otherrepo-all-in-one:pr-mongo-go-driver-29d768e",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:pr-mongo-go-driver-29d768e",
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:pr-define-docker-tag",
"ghcr.io/otherorg/otherrepo-all-in-one:pr-define-docker-tag",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:pr-define-docker-tag",
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:main",
"ghcr.io/otherorg/otherrepo-all-in-one:main",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:main",
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:main-v1",
"ghcr.io/otherorg/otherrepo-all-in-one:main-v1",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:main-v1",
Expand Down Expand Up @@ -271,7 +271,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:releases-2.1",
"ghcr.io/otherorg/otherrepo-all-in-one:releases-2.1",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:releases-2.1",
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:1.26.0-beta",
"ghcr.io/otherorg/otherrepo-all-in-one:1.26.0-beta",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:1.26.0-beta",
Expand Down Expand Up @@ -395,10 +395,10 @@ func TestDefine(t *testing.T) {
expected: &result{
// add all tags except latest while v2 is not GA
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:2",
"ghcr.io/otherorg/all-in-one:2.1",
"ghcr.io/otherorg/all-in-one:2.1.0",
"ghcr.io/otherorg/all-in-one:2.1.0-beta",
"ghcr.io/otherorg/otherrepo-all-in-one:2",
"ghcr.io/otherorg/otherrepo-all-in-one:2.1",
"ghcr.io/otherorg/otherrepo-all-in-one:2.1.0",
"ghcr.io/otherorg/otherrepo-all-in-one:2.1.0-beta",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:2",
Expand Down Expand Up @@ -477,27 +477,27 @@ func TestDefine(t *testing.T) {
"GITHUB_HEAD_REF": "",
"GITHUB_REF_NAME": "v1.26.0",
"GITHUB_REF_TYPE": "tag",
"GITHUB_REPOSITORY": "OtherOrg/FerretDB",
"GITHUB_REPOSITORY": "OtherOrg/OtherRepo",
},
expected: &result{
// latest is v1 for now
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:1",
"ghcr.io/otherorg/all-in-one:1.26",
"ghcr.io/otherorg/all-in-one:1.26.0",
"ghcr.io/otherorg/all-in-one:latest",
"ghcr.io/otherorg/otherrepo-all-in-one:1",
"ghcr.io/otherorg/otherrepo-all-in-one:1.26",
"ghcr.io/otherorg/otherrepo-all-in-one:1.26.0",
"ghcr.io/otherorg/otherrepo-all-in-one:latest",
},
developmentImages: []string{
"ghcr.io/otherorg/ferretdb-dev:1",
"ghcr.io/otherorg/ferretdb-dev:1.26",
"ghcr.io/otherorg/ferretdb-dev:1.26.0",
"ghcr.io/otherorg/ferretdb-dev:latest",
"ghcr.io/otherorg/otherrepo-dev:1",
"ghcr.io/otherorg/otherrepo-dev:1.26",
"ghcr.io/otherorg/otherrepo-dev:1.26.0",
"ghcr.io/otherorg/otherrepo-dev:latest",
},
productionImages: []string{
"ghcr.io/otherorg/ferretdb:1",
"ghcr.io/otherorg/ferretdb:1.26",
"ghcr.io/otherorg/ferretdb:1.26.0",
"ghcr.io/otherorg/ferretdb:latest",
"ghcr.io/otherorg/otherrepo:1",
"ghcr.io/otherorg/otherrepo:1.26",
"ghcr.io/otherorg/otherrepo:1.26.0",
"ghcr.io/otherorg/otherrepo:latest",
},
},
},
Expand Down Expand Up @@ -555,24 +555,24 @@ func TestDefine(t *testing.T) {
"GITHUB_HEAD_REF": "",
"GITHUB_REF_NAME": "v2.1.0",
"GITHUB_REF_TYPE": "tag",
"GITHUB_REPOSITORY": "OtherOrg/FerretDB",
"GITHUB_REPOSITORY": "OtherOrg/OtherRepo",
},
expected: &result{
// latest is v1, not v2, for now
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:2",
"ghcr.io/otherorg/all-in-one:2.1",
"ghcr.io/otherorg/all-in-one:2.1.0",
"ghcr.io/otherorg/otherrepo-all-in-one:2",
"ghcr.io/otherorg/otherrepo-all-in-one:2.1",
"ghcr.io/otherorg/otherrepo-all-in-one:2.1.0",
},
developmentImages: []string{
"ghcr.io/otherorg/ferretdb-dev:2",
"ghcr.io/otherorg/ferretdb-dev:2.1",
"ghcr.io/otherorg/ferretdb-dev:2.1.0",
"ghcr.io/otherorg/otherrepo-dev:2",
"ghcr.io/otherorg/otherrepo-dev:2.1",
"ghcr.io/otherorg/otherrepo-dev:2.1.0",
},
productionImages: []string{
"ghcr.io/otherorg/ferretdb:2",
"ghcr.io/otherorg/ferretdb:2.1",
"ghcr.io/otherorg/ferretdb:2.1.0",
"ghcr.io/otherorg/otherrepo:2",
"ghcr.io/otherorg/otherrepo:2.1",
"ghcr.io/otherorg/otherrepo:2.1.0",
},
},
},
Expand Down Expand Up @@ -631,7 +631,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:main",
"ghcr.io/otherorg/otherrepo-all-in-one:main",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:main",
Expand Down Expand Up @@ -672,7 +672,7 @@ func TestDefine(t *testing.T) {
},
expected: &result{
allInOneImages: []string{
"ghcr.io/otherorg/all-in-one:main",
"ghcr.io/otherorg/otherrepo-all-in-one:main",
},
developmentImages: []string{
"ghcr.io/otherorg/otherrepo-dev:main",
Expand Down

0 comments on commit e090e53

Please sign in to comment.