Skip to content

Commit 995f5fc

Browse files
committed
feat: Add configuration for image registries
1 parent 6caf8f3 commit 995f5fc

File tree

11 files changed

+161
-55
lines changed

11 files changed

+161
-55
lines changed

deployments/pulumi/pkg/api/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func createDeployment(ctx *pulumi.Context, args createDeploymentArgs, resourceOp
167167
Containers: corev1.ContainerArray{
168168
corev1.ContainerArgs{
169169
Name: pulumi.String("ledger-api"),
170-
Image: utils.GetMainImage(args.Tag),
170+
Image: utils.GetMainImage(args.ImageConfiguration),
171171
ImagePullPolicy: args.ImagePullPolicy.ToOutput(ctx.Context()).Untyped().(pulumi.StringOutput),
172172
Args: pulumi.StringArray{
173173
pulumi.String("serve"),

deployments/pulumi/pkg/common/common.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package common
22

33
import (
44
"github.com/formancehq/ledger/deployments/pulumi/pkg/monitoring"
5+
"github.com/formancehq/ledger/deployments/pulumi/pkg/utils"
56
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
67
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
78
)
89

910
type CommonArgs struct {
11+
utils.ImageConfiguration
1012
Namespace pulumix.Input[string]
1113
Monitoring *monitoring.Args
12-
Tag pulumix.Input[string]
1314
ImagePullPolicy pulumix.Input[string]
1415
Debug pulumix.Input[bool]
1516
}
@@ -37,4 +38,5 @@ func (args *CommonArgs) SetDefaults() {
3738
if args.Monitoring != nil {
3839
args.Monitoring.SetDefaults()
3940
}
41+
args.ImageConfiguration.SetDefaults()
4042
}

deployments/pulumi/pkg/config/config.go

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"reflect"
8+
"time"
9+
10+
"github.com/formancehq/ledger/deployments/pulumi/pkg/utils"
11+
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/rds"
12+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
13+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
14+
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
15+
"gopkg.in/yaml.v3"
16+
717
. "github.com/formancehq/go-libs/v3/collectionutils"
818
pulumi_ledger "github.com/formancehq/ledger/deployments/pulumi/pkg"
919
"github.com/formancehq/ledger/deployments/pulumi/pkg/api"
@@ -14,13 +24,6 @@ import (
1424
"github.com/formancehq/ledger/deployments/pulumi/pkg/provision"
1525
"github.com/formancehq/ledger/deployments/pulumi/pkg/storage"
1626
"github.com/formancehq/ledger/deployments/pulumi/pkg/worker"
17-
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/rds"
18-
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
19-
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
20-
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
21-
"gopkg.in/yaml.v3"
22-
"reflect"
23-
"time"
2427
)
2528

2629
type Ingress struct {
@@ -183,8 +186,8 @@ func (a *PostgresDatabase) toInput() *storage.PostgresDatabaseArgs {
183186

184187
return &storage.PostgresDatabaseArgs{
185188
Install: &storage.PostgresInstallArgs{
186-
Username: pulumix.Val(a.Install.Username),
187-
Password: pulumix.Val(a.Install.Password),
189+
Username: pulumix.Val(a.Install.Username),
190+
Password: pulumix.Val(a.Install.Password),
188191
ChartVersion: pulumix.Val(a.Install.ChartVersion),
189192
},
190193
}
@@ -572,8 +575,12 @@ type Common struct {
572575
Monitoring *Monitoring `json:"monitoring,omitempty" yaml:"monitoring,omitempty"`
573576

574577
// Tag is the version tag for the ledger
578+
// deprecated
575579
Tag string `json:"version,omitempty" yaml:"version,omitempty"`
576580

581+
// Image configuration
582+
Image *ImageConfiguration `json:"image"`
583+
577584
// ImagePullPolicy is the image pull policy for the ledger
578585
ImagePullPolicy string `json:"image-pull-policy,omitempty" yaml:"image-pull-policy,omitempty"`
579586

@@ -583,11 +590,11 @@ type Common struct {
583590

584591
func (c Common) toInput() common.CommonArgs {
585592
return common.CommonArgs{
586-
Namespace: pulumix.Val(c.Namespace),
587-
Monitoring: c.Monitoring.ToInput(),
588-
Tag: pulumix.Val(c.Tag),
589-
ImagePullPolicy: pulumix.Val(c.ImagePullPolicy),
590-
Debug: pulumix.Val(c.Debug),
593+
Namespace: pulumix.Val(c.Namespace),
594+
Monitoring: c.Monitoring.ToInput(),
595+
ImageConfiguration: imageConfigurationOrTag(c.Image, c.Tag),
596+
ImagePullPolicy: pulumix.Val(c.ImagePullPolicy),
597+
Debug: pulumix.Val(c.Debug),
591598
}
592599
}
593600

@@ -662,6 +669,7 @@ func (g GeneratorLedgerConfiguration) toInput() generator.LedgerConfiguration {
662669

663670
type Generator struct {
664671
// GeneratorVersion is the version of the generator
672+
// deprecated
665673
GeneratorVersion string `json:"generator-version" yaml:"generator-version"`
666674

667675
// Ledgers are the ledgers to run the generator against
@@ -725,6 +733,12 @@ func (cfg Config) ToInput() pulumi_ledger.ComponentArgs {
725733
}
726734
}
727735

736+
type ImageConfiguration struct {
737+
Registry string `json:"registry" yaml:"registry"`
738+
Repository string `json:"repository" yaml:"repository"`
739+
Tag string `json:"version" yaml:"version"`
740+
}
741+
728742
func Load(ctx *pulumi.Context) (*Config, error) {
729743
cfg := config.New(ctx, "")
730744

@@ -795,6 +809,13 @@ func Load(ctx *pulumi.Context) (*Config, error) {
795809
generator = nil
796810
}
797811

812+
image := &ImageConfiguration{}
813+
if err := cfg.TryObject("image", image); err != nil {
814+
if !errors.Is(err, config.ErrMissingVar) {
815+
return nil, fmt.Errorf("error reading generator config: %w", err)
816+
}
817+
}
818+
798819
namespace := cfg.Get("namespace")
799820
if namespace == "" {
800821
namespace = ctx.Stack()
@@ -807,6 +828,7 @@ func Load(ctx *pulumi.Context) (*Config, error) {
807828
Namespace: namespace,
808829
Tag: cfg.Get("version"),
809830
Monitoring: monitoring,
831+
Image: image,
810832
ImagePullPolicy: cfg.Get("image-pull-policy"),
811833
},
812834
InstallDevBox: cfg.GetBool("install-dev-box"),
@@ -819,3 +841,21 @@ func Load(ctx *pulumi.Context) (*Config, error) {
819841
Generator: generator,
820842
}, nil
821843
}
844+
845+
func imageConfigurationOrTag(configuration *ImageConfiguration, tag string) utils.ImageConfiguration {
846+
if configuration == nil {
847+
return utils.ImageConfiguration{
848+
Tag: pulumix.Val(tag),
849+
}
850+
}
851+
852+
if configuration.Tag != "" {
853+
tag = configuration.Tag
854+
}
855+
856+
return utils.ImageConfiguration{
857+
Registry: pulumix.Val(configuration.Registry),
858+
Repository: pulumix.Val(configuration.Repository),
859+
Tag: pulumix.Val(tag),
860+
}
861+
}

deployments/pulumi/pkg/generator/component.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package generator
33
import (
44
"errors"
55
"fmt"
6+
"os"
7+
"path/filepath"
8+
"time"
9+
610
"github.com/formancehq/ledger/deployments/pulumi/pkg/api"
711
"github.com/formancehq/ledger/deployments/pulumi/pkg/common"
812
"github.com/formancehq/ledger/deployments/pulumi/pkg/utils"
@@ -12,9 +16,6 @@ import (
1216
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
1317
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
1418
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
15-
"os"
16-
"path/filepath"
17-
"time"
1819
)
1920

2021
type Component struct {
@@ -48,15 +49,6 @@ type Args struct {
4849
}
4950

5051
func (a *Args) SetDefaults() {
51-
if a.GeneratorVersion == nil {
52-
a.GeneratorVersion = pulumix.Val("")
53-
}
54-
a.GeneratorVersion = pulumix.Apply(a.GeneratorVersion, func(generatorVersion string) string {
55-
if generatorVersion == "" {
56-
return "latest"
57-
}
58-
return generatorVersion
59-
})
6052
if a.Ledgers == nil {
6153
a.Ledgers = make(map[string]LedgerConfiguration)
6254
}
@@ -149,12 +141,10 @@ func NewComponent(ctx *pulumi.Context, name string, args ComponentArgs, opts ...
149141
corev1.ContainerArgs{
150142
Name: pulumi.String("generator"),
151143
Args: generatorArgs.ToOutput(ctx.Context()).Untyped().(pulumi.StringArrayOutput),
152-
Image: utils.GetImage(pulumi.String("ledger-generator"), pulumix.Apply2(args.GeneratorVersion, args.Tag, func(generatorVersion string, ledgerVersion string) string {
153-
if generatorVersion == "" {
154-
return ledgerVersion
155-
}
156-
return generatorVersion
157-
})),
144+
Image: utils.GetImage(
145+
args.ImageConfiguration.WithFallbackTag(args.GeneratorVersion),
146+
pulumi.String("ledger-generator"),
147+
),
158148
ImagePullPolicy: pulumi.String("Always"),
159149
VolumeMounts: corev1.VolumeMountArray{
160150
corev1.VolumeMountArgs{

deployments/pulumi/pkg/provision/component.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provision
22

33
import (
44
"fmt"
5+
56
"github.com/formancehq/ledger/deployments/pulumi/pkg/api"
67
"github.com/formancehq/ledger/deployments/pulumi/pkg/common"
78
"github.com/formancehq/ledger/deployments/pulumi/pkg/exporters"
@@ -26,7 +27,7 @@ type LedgerConfigArgs struct {
2627
}
2728

2829
type Args struct {
29-
ProvisionerVersion pulumi.String
30+
ProvisionerVersion pulumix.Input[string]
3031
Ledgers map[string]LedgerConfigArgs `json:"ledgers"`
3132
}
3233

@@ -129,12 +130,10 @@ func NewComponent(ctx *pulumi.Context, name string, args ComponentArgs, opts ...
129130
pulumi.String("--state-store"),
130131
pulumi.Sprintf("k8s:///%s/provisioner", args.Namespace),
131132
},
132-
Image: utils.GetImage(pulumi.String("ledger-provisioner"), pulumix.Apply2(args.Tag, args.ProvisionerVersion, func(ledgerVersion, provisionerVersion string) string {
133-
if provisionerVersion != "" {
134-
return provisionerVersion
135-
}
136-
return ledgerVersion
137-
})),
133+
Image: utils.GetImage(
134+
args.ImageConfiguration.WithFallbackTag(args.ProvisionerVersion),
135+
pulumi.String("ledger-provisioner"),
136+
),
138137
VolumeMounts: corev1.VolumeMountArray{
139138
corev1.VolumeMountArgs{
140139
Name: pulumi.String("config"),

deployments/pulumi/pkg/storage/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func runMigrateJob(ctx *pulumi.Context, args migrationArgs, opts ...pulumi.Resou
3838
Args: pulumi.StringArray{
3939
pulumi.String("migrate"),
4040
},
41-
Image: utils.GetMainImage(args.Tag),
41+
Image: utils.GetMainImage(args.ImageConfiguration),
4242
ImagePullPolicy: args.ImagePullPolicy.ToOutput(ctx.Context()).Untyped().(pulumi.StringOutput),
4343
Env: envVars,
4444
},

deployments/pulumi/pkg/utils/convert.go

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,33 @@ import (
55
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
66
)
77

8-
func GetMainImage(tag pulumix.Input[string]) pulumi.StringOutput {
9-
return GetImage(pulumi.String("ledger"), tag)
8+
func GetMainImage(imageConfiguration ImageConfiguration) pulumi.StringOutput {
9+
return GetImage(imageConfiguration, pulumi.String("ledger"))
1010
}
1111

12-
func GetImage(component, tag pulumix.Input[string]) pulumi.StringOutput {
13-
return pulumi.Sprintf("ghcr.io/formancehq/%s:%s", component, pulumix.Apply(tag, func(version string) string {
14-
if version == "" {
15-
return "latest"
16-
}
17-
return version
18-
}))
12+
func GetImage(imageConfiguration ImageConfiguration, component pulumix.Input[string]) pulumi.StringOutput {
13+
return pulumi.Sprintf(
14+
"%s/%s/%s:%s",
15+
pulumix.Apply(imageConfiguration.Registry, func(registry string) string {
16+
if registry == "" {
17+
return "ghcr.io"
18+
}
19+
return registry
20+
}),
21+
pulumix.Apply(imageConfiguration.Repository, func(repository string) string {
22+
if repository == "" {
23+
return "formancehq"
24+
}
25+
return repository
26+
}),
27+
component,
28+
pulumix.Apply(imageConfiguration.Tag, func(version string) string {
29+
if version == "" {
30+
return "latest"
31+
}
32+
return version
33+
}),
34+
)
1935
}
2036

2137
func BoolToString(output pulumix.Input[bool]) pulumix.Output[string] {
@@ -26,3 +42,54 @@ func BoolToString(output pulumix.Input[bool]) pulumix.Output[string] {
2642
return "false"
2743
})
2844
}
45+
46+
type ImageConfiguration struct {
47+
Registry pulumix.Input[string]
48+
Repository pulumix.Input[string]
49+
Tag pulumix.Input[string]
50+
}
51+
52+
func (args ImageConfiguration) WithFallbackTag(input pulumix.Input[string]) ImageConfiguration {
53+
args.Tag = pulumix.Apply2(args.Tag, input, func(providedVersion, fallbackVersion string) string {
54+
if providedVersion == "" {
55+
return fallbackVersion
56+
}
57+
return providedVersion
58+
})
59+
return args
60+
}
61+
62+
func (args *ImageConfiguration) SetDefaults() {
63+
if args.Registry == nil {
64+
args.Registry = pulumi.String("ghcr.io")
65+
} else {
66+
args.Registry = pulumix.Apply(args.Registry, func(registry string) string {
67+
if registry == "" {
68+
return "ghcr.io"
69+
}
70+
return registry
71+
})
72+
}
73+
74+
if args.Repository == nil {
75+
args.Repository = pulumi.String("formancehq")
76+
} else {
77+
args.Repository = pulumix.Apply(args.Repository, func(repository string) string {
78+
if repository == "" {
79+
return "formancehq"
80+
}
81+
return repository
82+
})
83+
}
84+
85+
if args.Tag == nil {
86+
args.Tag = pulumi.String("latest")
87+
} else {
88+
args.Tag = pulumix.Apply(args.Tag, func(tag string) string {
89+
if tag == "" {
90+
return "latest"
91+
}
92+
return tag
93+
})
94+
}
95+
}

deployments/pulumi/pkg/worker/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func createDeployment(ctx *pulumi.Context, args ComponentArgs, resourceOptions .
4545
Containers: corev1.ContainerArray{
4646
corev1.ContainerArgs{
4747
Name: pulumi.String("worker"),
48-
Image: utils.GetMainImage(args.Tag),
48+
Image: utils.GetMainImage(args.ImageConfiguration),
4949
ImagePullPolicy: args.ImagePullPolicy.ToOutput(ctx.Context()).Untyped().(pulumi.StringOutput),
5050
Args: pulumi.StringArray{
5151
pulumi.String("worker"),

internal/replication/manager.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ func (m *Manager) synchronizePipelines(ctx context.Context) error {
215215
for _, pipeline := range pipelines {
216216
m.logger.Debugf("restoring pipeline %s", pipeline.ID)
217217
if _, err := m.startPipeline(ctx, pipeline); err != nil {
218-
return err
218+
switch {
219+
case errors.Is(err, ledger.ErrAlreadyStarted("")):
220+
default:
221+
return err
222+
}
219223
}
220224
}
221225

0 commit comments

Comments
 (0)