Skip to content

Commit 8f323c7

Browse files
authored
Merge pull request opencloud-eu#2001 from fschade/release-channel-capability
enhancement: introduce release channel capability
2 parents 4c5d5fb + 40d8aac commit 8f323c7

13 files changed

Lines changed: 154 additions & 13 deletions

File tree

.make/go.mk

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@ ifndef DATE
3636
DATE := $(shell date -u '+%Y%m%d')
3737
endif
3838

39-
LDFLAGS += -X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn -s -w -X "$(OC_REPO)/pkg/version.String=$(STRING)" -X "$(OC_REPO)/pkg/version.Tag=$(VERSION)" -X "$(OC_REPO)/pkg/version.Date=$(DATE)"
40-
DEBUG_LDFLAGS += -X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn -X "$(OC_REPO)/pkg/version.String=$(STRING)" -X "$(OC_REPO)/pkg/version.Tag=$(VERSION)" -X "$(OC_REPO)/pkg/version.Date=$(DATE)"
39+
LDFLAGS += -X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn -s -w \
40+
-X "$(OC_REPO)/pkg/version.Edition=$(EDITION)" \
41+
-X "$(OC_REPO)/pkg/version.String=$(STRING)" \
42+
-X "$(OC_REPO)/pkg/version.Tag=$(VERSION)" \
43+
-X "$(OC_REPO)/pkg/version.Date=$(DATE)"
44+
45+
DEBUG_LDFLAGS += -X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn \
46+
-X "$(OC_REPO)/pkg/version.Edition=$(EDITION)" \
47+
-X "$(OC_REPO)/pkg/version.String=$(STRING)" \
48+
-X "$(OC_REPO)/pkg/version.Tag=$(VERSION)" \
49+
-X "$(OC_REPO)/pkg/version.Date=$(DATE)"
50+
4151
DOCKER_LDFLAGS += -X "$(OC_REPO)/pkg/config/defaults.BaseDataPathType=path" -X "$(OC_REPO)/pkg/config/defaults.BaseDataPathValue=/var/lib/opencloud"
4252
DOCKER_LDFLAGS += -X "$(OC_REPO)/pkg/config/defaults.BaseConfigPathType=path" -X "$(OC_REPO)/pkg/config/defaults.BaseConfigPathValue=/etc/opencloud"
4353

.woodpecker.star

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,7 @@ def dockerReleases(ctx):
16281628

16291629
if is_production:
16301630
docker_releases.append("production")
1631+
16311632
# a new production realease is also a rolling release
16321633
# unless skip_rolling is set in the config, i.e. for patch-releases on stable-branch
16331634
if not skip_rolling:
@@ -1636,7 +1637,7 @@ def dockerReleases(ctx):
16361637
else:
16371638
docker_releases.append("rolling")
16381639

1639-
# on non tag events, do daily build
1640+
# on non tag events, do daily build
16401641
else:
16411642
docker_releases.append("daily")
16421643

@@ -1662,6 +1663,7 @@ def dockerRelease(ctx, repo, build_type):
16621663
build_args = {
16631664
"REVISION": "%s" % ctx.build.commit,
16641665
"VERSION": "%s" % (ctx.build.ref.replace("refs/tags/", "") if ctx.build.event == "tag" else "daily"),
1666+
"EDITION": "stable" if build_type == "production" else "rolling",
16651667
}
16661668

16671669
# if no additional tag is given, the build-plugin adds latest
@@ -1825,6 +1827,7 @@ def binaryRelease(ctx, arch, depends_on = []):
18251827
"image": OC_CI_GOLANG,
18261828
"environment": {
18271829
"VERSION": (ctx.build.ref.replace("refs/tags/", "") if ctx.build.event == "tag" else "daily"),
1830+
"EDITION": "rolling",
18281831
"HTTP_PROXY": {
18291832
"from_secret": "ci_http_proxy",
18301833
},

opencloud/docker/Dockerfile.multiarch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARG TARGETOS
33
ARG TARGETARCH
44
ARG VERSION
55
ARG STRING
6+
ARG EDITION
67

78
RUN apk add bash make git curl gcc musl-dev libc-dev binutils-gold inotify-tools vips-dev
89

pkg/version/export_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package version
2+
3+
// InitEdition exports the private edition initialization func for testing
4+
var InitEdition = initEdition

pkg/version/version.go

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
package version
22

33
import (
4+
"fmt"
5+
"slices"
6+
"strings"
47
"time"
58

69
"github.com/Masterminds/semver"
10+
"github.com/opencloud-eu/reva/v2/pkg/logger"
11+
)
12+
13+
const (
14+
15+
// Dev is used as a placeholder.
16+
Dev = "dev"
17+
// EditionDev indicates the development build channel was used to build the binary.
18+
EditionDev = Dev
19+
// EditionRolling indicates the rolling release build channel was used to build the binary.
20+
EditionRolling = "rolling"
21+
// EditionStable indicates the stable release build channel was used to build the binary.
22+
EditionStable = "stable"
23+
// EditionLTS indicates the lts release build channel was used to build the binary.
24+
EditionLTS = "lts"
725
)
826

927
var (
@@ -21,17 +39,56 @@ var (
2139
// Date indicates the build date.
2240
// This has been removed, it looks like you can only replace static strings with recent go versions
2341
//Date = time.Now().Format("20060102")
24-
Date = "dev"
42+
Date = Dev
2543

2644
// Legacy defines the old long 4 number OpenCloud version needed for some clients
2745
Legacy = "0.1.0.0"
2846
// LegacyString defines the old OpenCloud version needed for some clients
2947
LegacyString = "0.1.0"
48+
49+
// Edition describes the build channel (stable, rolling, nightly, daily, dev)
50+
Edition = Dev // default for self-compiled builds
3051
)
3152

53+
func init() { //nolint:gochecknoinits
54+
if err := initEdition(); err != nil {
55+
logger.New().Error().Err(err).Msg("falling back to dev")
56+
}
57+
}
58+
59+
func initEdition() error {
60+
regularEditions := []string{EditionDev, EditionRolling, EditionStable}
61+
versionedEditions := []string{EditionLTS}
62+
if !slices.ContainsFunc(slices.Concat(regularEditions, versionedEditions), func(s string) bool {
63+
isRegularEdition := slices.Contains(regularEditions, Edition)
64+
if isRegularEdition && s == Edition {
65+
return true
66+
}
67+
68+
// handle editions with a version
69+
editionParts := strings.Split(Edition, "-")
70+
if len(editionParts) != 2 { // a versioned edition channel must consist of exactly 2 parts.
71+
return false
72+
}
73+
74+
isVersionedEdition := slices.Contains(versionedEditions, editionParts[0])
75+
if !isVersionedEdition { // not all channels can contain version information
76+
return false
77+
}
78+
79+
_, err := semver.NewVersion(editionParts[1])
80+
return err == nil
81+
}) {
82+
Edition = Dev
83+
return fmt.Errorf(`unknown edition channel "%s"`, Edition)
84+
}
85+
86+
return nil
87+
}
88+
3289
// Compiled returns the compile time of this service.
3390
func Compiled() time.Time {
34-
if Date == "dev" {
91+
if Date == Dev {
3592
return time.Now()
3693
}
3794
t, _ := time.Parse("20060102", Date)

pkg/version/version_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package version_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/opencloud-eu/opencloud/pkg/version"
8+
)
9+
10+
func TestChannel(t *testing.T) {
11+
tests := map[string]struct {
12+
got string
13+
valid bool
14+
}{
15+
"no channel, defaults to dev": {
16+
got: "",
17+
valid: false,
18+
},
19+
"dev channel": {
20+
got: version.EditionDev,
21+
valid: true,
22+
},
23+
"rolling channel": {
24+
got: version.EditionRolling,
25+
valid: true,
26+
},
27+
"stable channel": {
28+
got: version.EditionStable,
29+
valid: true,
30+
},
31+
"lts channel without version": {
32+
got: version.EditionLTS,
33+
valid: false,
34+
},
35+
"lts-1.0.0 channel": {
36+
got: fmt.Sprintf("%s-1", version.EditionLTS),
37+
valid: true,
38+
},
39+
"lts-one invalid version": {
40+
got: fmt.Sprintf("%s-one", version.EditionLTS),
41+
valid: false,
42+
},
43+
"known channel with version": {
44+
got: fmt.Sprintf("%s-1", version.EditionStable),
45+
valid: false,
46+
},
47+
"unknown channel": {
48+
got: "foo",
49+
valid: false,
50+
},
51+
}
52+
53+
for name, test := range tests {
54+
t.Run(name, func(t *testing.T) {
55+
version.Edition = test.got
56+
57+
switch err := version.InitEdition(); {
58+
case err != nil && !test.valid && version.Edition != version.Dev: // if a given edition is unknown, the value is always dev
59+
fallthrough
60+
case test.valid != (err == nil):
61+
t.Fatalf("invalid edition: %s", version.Edition)
62+
}
63+
})
64+
}
65+
}

services/frontend/pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Config struct {
3333
EnableFederatedSharingIncoming bool `yaml:"enable_federated_sharing_incoming" env:"OC_ENABLE_OCM;FRONTEND_ENABLE_FEDERATED_SHARING_INCOMING" desc:"Changing this value is NOT supported. Enables support for incoming federated sharing for clients. The backend behaviour is not changed." introductionVersion:"1.0.0"`
3434
EnableFederatedSharingOutgoing bool `yaml:"enable_federated_sharing_outgoing" env:"OC_ENABLE_OCM;FRONTEND_ENABLE_FEDERATED_SHARING_OUTGOING" desc:"Changing this value is NOT supported. Enables support for outgoing federated sharing for clients. The backend behaviour is not changed." introductionVersion:"1.0.0"`
3535
SearchMinLength int `yaml:"search_min_length" env:"FRONTEND_SEARCH_MIN_LENGTH" desc:"Minimum number of characters to enter before a client should start a search for Share receivers. This setting can be used to customize the user experience if e.g too many results are displayed." introductionVersion:"1.0.0"`
36-
Edition string `yaml:"edition" env:"OC_EDITION;FRONTEND_EDITION" desc:"Edition of OpenCloud. Used for branding purposes." introductionVersion:"1.0.0"`
36+
Edition string `desc:"Edition of OpenCloud. Used for branding purposes." introductionVersion:"1.0.0"`
3737
DisableSSE bool `yaml:"disable_sse" env:"OC_DISABLE_SSE;FRONTEND_DISABLE_SSE" desc:"When set to true, clients are informed that the Server-Sent Events endpoint is not accessible." introductionVersion:"1.0.0"`
3838
DisableRadicale bool `yaml:"disable_radicale" env:"FRONTEND_DISABLE_RADICALE" desc:"When set to true, clients are informed that the Radicale (CalDAV/CardDAV) is not accessible." introductionVersion:"4.0.0"`
3939
DefaultLinkPermissions int `yaml:"default_link_permissions" env:"FRONTEND_DEFAULT_LINK_PERMISSIONS" desc:"Defines the default permissions a link is being created with. Possible values are 0 (= internal link, for instance members only) and 1 (= public link with viewer permissions). Defaults to 1." introductionVersion:"1.0.0"`

services/frontend/pkg/config/defaults/defaultconfig.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/opencloud-eu/opencloud/pkg/shared"
77
"github.com/opencloud-eu/opencloud/pkg/structs"
8+
"github.com/opencloud-eu/opencloud/pkg/version"
89
"github.com/opencloud-eu/opencloud/services/frontend/pkg/config"
910
)
1011

@@ -87,7 +88,7 @@ func DefaultConfig() *config.Config {
8788
DefaultUploadProtocol: "tus",
8889
DefaultLinkPermissions: 1,
8990
SearchMinLength: 3,
90-
Edition: "",
91+
Edition: version.Edition,
9192
CheckForUpdates: true,
9293
Checksums: config.Checksums{
9394
SupportedTypes: []string{"sha1", "md5", "adler32"},

services/frontend/pkg/revaconfig/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func FrontendConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string
346346
},
347347
"version": map[string]interface{}{
348348
"product": "OpenCloud",
349-
"edition": "",
349+
"edition": version.Edition,
350350
"major": version.ParsedLegacy().Major(),
351351
"minor": version.ParsedLegacy().Minor(),
352352
"micro": version.ParsedLegacy().Patch(),

services/ocdav/pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ type Status struct {
8080
Product string
8181
ProductName string
8282
ProductVersion string
83-
Edition string `yaml:"edition" env:"OC_EDITION;OCDAV_EDITION" desc:"Edition of OpenCloud. Used for branding purposes." introductionVersion:"1.0.0"`
83+
Edition string `desc:"Edition of OpenCloud. Used for branding purposes." introductionVersion:"1.0.0"`
8484
}

0 commit comments

Comments
 (0)