Skip to content

Commit d88e549

Browse files
authored
use pre-release cdn and image repo for aws integration flows (#47474)
1 parent 597bd46 commit d88e549

File tree

7 files changed

+193
-23
lines changed

7 files changed

+193
-23
lines changed

lib/integrations/awsoidc/deployservice.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ import (
2929
"github.com/aws/aws-sdk-go-v2/aws/retry"
3030
"github.com/aws/aws-sdk-go-v2/service/ecs"
3131
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
32+
"github.com/coreos/go-semver/semver"
3233
"github.com/gravitational/trace"
3334

3435
"github.com/gravitational/teleport"
3536
"github.com/gravitational/teleport/api/types"
3637
"github.com/gravitational/teleport/api/utils/retryutils"
3738
"github.com/gravitational/teleport/lib/integrations/awsoidc/tags"
38-
"github.com/gravitational/teleport/lib/modules"
39+
"github.com/gravitational/teleport/lib/utils/teleportassets"
3940
)
4041

4142
var (
@@ -55,11 +56,6 @@ var (
5556
)
5657

5758
const (
58-
// distrolessTeleportOSS is the distroless image of the OSS version of Teleport
59-
distrolessTeleportOSS = "public.ecr.aws/gravitational/teleport-distroless"
60-
// distrolessTeleportEnt is the distroless image of the Enterprise version of Teleport
61-
distrolessTeleportEnt = "public.ecr.aws/gravitational/teleport-ent-distroless"
62-
6359
// clusterStatusActive is the string representing an ACTIVE ECS Cluster.
6460
clusterStatusActive = "ACTIVE"
6561
// clusterStatusInactive is the string representing an INACTIVE ECS Cluster.
@@ -472,7 +468,10 @@ type upsertTaskRequest struct {
472468

473469
// upsertTask ensures a TaskDefinition with TaskName exists
474470
func upsertTask(ctx context.Context, clt DeployServiceClient, req upsertTaskRequest) (*ecsTypes.TaskDefinition, error) {
475-
taskAgentContainerImage := getDistrolessTeleportImage(req.TeleportVersionTag)
471+
taskAgentContainerImage, err := getDistrolessTeleportImage(req.TeleportVersionTag)
472+
if err != nil {
473+
return nil, trace.Wrap(err)
474+
}
476475

477476
taskDefIn := &ecs.RegisterTaskDefinitionInput{
478477
Family: aws.String(req.TaskName),
@@ -760,10 +759,11 @@ func upsertService(ctx context.Context, clt DeployServiceClient, req upsertServi
760759
}
761760

762761
// getDistrolessTeleportImage returns the distroless teleport image string
763-
func getDistrolessTeleportImage(version string) string {
764-
teleportImage := distrolessTeleportOSS
765-
if modules.GetModules().BuildType() == modules.BuildEnterprise {
766-
teleportImage = distrolessTeleportEnt
762+
func getDistrolessTeleportImage(version string) (string, error) {
763+
semVer, err := semver.NewVersion(version)
764+
if err != nil {
765+
return "", trace.BadParameter("invalid version tag %s", version)
767766
}
768-
return fmt.Sprintf("%s:%s", teleportImage, version)
767+
768+
return teleportassets.DistrolessImage(*semVer), nil
769769
}

lib/integrations/awsoidc/deployservice_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ func TestUpsertTask(t *testing.T) {
238238
},
239239
}
240240

241-
taskDefinition, err := upsertTask(ctx, mockClient, upsertTaskRequest{})
241+
semVer := *teleport.SemVersion
242+
semVer.PreRelease = ""
243+
taskDefinition, err := upsertTask(ctx, mockClient, upsertTaskRequest{TeleportVersionTag: semVer.String()})
242244
require.NoError(t, err)
243245
require.Equal(t, expected, taskDefinition.ContainerDefinitions[0].Environment)
244246
}

lib/integrations/awsoidc/deployservice_update.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ func UpdateDeployService(ctx context.Context, clt DeployServiceClient, log *slog
7171
return trace.Wrap(err)
7272
}
7373

74-
teleportImage := getDistrolessTeleportImage(req.TeleportVersionTag)
74+
teleportImage, err := getDistrolessTeleportImage(req.TeleportVersionTag)
75+
if err != nil {
76+
return trace.Wrap(err)
77+
}
7578
services, err := getManagedServices(ctx, clt, log, req.TeleportClusterName, req.OwnershipTags)
7679
if err != nil {
7780
return trace.Wrap(err)

lib/integrations/awsoidc/deployservice_update_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ func TestUpdateDeployServices(t *testing.T) {
162162
clusterName := "my-cluster"
163163
integrationName := "my-integration"
164164
ownershipTags := tags.DefaultResourceCreationTags(clusterName, integrationName)
165-
teleportVersion := teleport.Version
165+
semVer := *teleport.SemVersion
166+
semVer.PreRelease = ""
167+
teleportVersion := semVer.String()
166168
log := utils.NewSlogLoggerForTests().With("test", t.Name())
167169

168170
t.Run("only legacy service present", func(t *testing.T) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Teleport
3+
* Copyright (C) 2024 Gravitational, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package teleportassets
20+
21+
import (
22+
"fmt"
23+
24+
"github.com/coreos/go-semver/semver"
25+
26+
"github.com/gravitational/teleport"
27+
"github.com/gravitational/teleport/lib/modules"
28+
)
29+
30+
const (
31+
// teleportReleaseCDN is the Teleport CDN URL for release builds.
32+
// This can be used to download the Teleport binary for release builds.
33+
teleportReleaseCDN = "https://cdn.teleport.dev"
34+
// teleportPreReleaseCDN is the Teleport CDN URL for pre-release builds.
35+
// This can be used to download the Teleport binary for pre-release builds.
36+
teleportPreReleaseCDN = "https://cdn.cloud.gravitational.io"
37+
)
38+
39+
// CDNBaseURL returns the URL of the CDN that can be used to download Teleport
40+
// binary assets.
41+
func CDNBaseURL() string {
42+
return cdnBaseURL(*teleport.SemVersion)
43+
}
44+
45+
// cdnBaseURL returns the base URL of the CDN that can be used to download
46+
// Teleport binary assets.
47+
func cdnBaseURL(version semver.Version) string {
48+
if version.PreRelease != "" {
49+
return teleportPreReleaseCDN
50+
}
51+
return teleportReleaseCDN
52+
}
53+
54+
const (
55+
// teleportReleaseECR is the official release repo for Teleport images.
56+
teleportReleaseECR = "public.ecr.aws/gravitational"
57+
// teleportReleaseECR is the pre-release repo for Teleport images.
58+
teleportPreReleaseECR = "public.ecr.aws/gravitational-staging"
59+
// distrolessTeleportOSSImage is the distroless image of the OSS version of Teleport
60+
distrolessTeleportOSSImage = "teleport-distroless"
61+
// distrolessTeleportEntImage is the distroless image of the Enterprise version of Teleport
62+
distrolessTeleportEntImage = "teleport-ent-distroless"
63+
)
64+
65+
// DistrolessImage returns the distroless teleport image repo.
66+
func DistrolessImage(version semver.Version) string {
67+
repo := distrolessImageRepo(version)
68+
name := distrolessImageName(modules.GetModules().BuildType())
69+
return fmt.Sprintf("%s/%s:%s", repo, name, version)
70+
}
71+
72+
func distrolessImageRepo(version semver.Version) string {
73+
if version.PreRelease != "" {
74+
return teleportPreReleaseECR
75+
}
76+
return teleportReleaseECR
77+
}
78+
79+
func distrolessImageName(buildType string) string {
80+
if buildType == modules.BuildEnterprise {
81+
return distrolessTeleportEntImage
82+
}
83+
return distrolessTeleportOSSImage
84+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Teleport
3+
* Copyright (C) 2024 Gravitational, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package teleportassets
20+
21+
import (
22+
"testing"
23+
24+
"github.com/coreos/go-semver/semver"
25+
"github.com/stretchr/testify/require"
26+
27+
"github.com/gravitational/teleport/lib/modules"
28+
)
29+
30+
func TestDistrolessTeleportImageRepo(t *testing.T) {
31+
tests := []struct {
32+
desc string
33+
buildType string
34+
version string
35+
want string
36+
}{
37+
{
38+
desc: "ent release",
39+
buildType: modules.BuildEnterprise,
40+
version: "16.0.0",
41+
want: "public.ecr.aws/gravitational/teleport-ent-distroless:16.0.0",
42+
},
43+
{
44+
desc: "oss release",
45+
buildType: modules.BuildOSS,
46+
version: "16.0.0",
47+
want: "public.ecr.aws/gravitational/teleport-distroless:16.0.0",
48+
},
49+
{
50+
desc: "community release",
51+
buildType: modules.BuildCommunity,
52+
version: "16.0.0",
53+
want: "public.ecr.aws/gravitational/teleport-distroless:16.0.0",
54+
},
55+
{
56+
desc: "ent pre-release",
57+
buildType: modules.BuildEnterprise,
58+
version: "16.0.0-alpha.1",
59+
want: "public.ecr.aws/gravitational-staging/teleport-ent-distroless:16.0.0-alpha.1",
60+
},
61+
{
62+
desc: "oss pre-release",
63+
buildType: modules.BuildOSS,
64+
version: "16.0.0-alpha.1",
65+
want: "public.ecr.aws/gravitational-staging/teleport-distroless:16.0.0-alpha.1",
66+
},
67+
{
68+
desc: "community pre-release",
69+
buildType: modules.BuildCommunity,
70+
version: "16.0.0-alpha.1",
71+
want: "public.ecr.aws/gravitational-staging/teleport-distroless:16.0.0-alpha.1",
72+
},
73+
}
74+
for _, test := range tests {
75+
t.Run(test.desc, func(t *testing.T) {
76+
semVer, err := semver.NewVersion(test.version)
77+
require.NoError(t, err)
78+
modules.SetTestModules(t, &modules.TestModules{TestBuildType: test.buildType})
79+
require.Equal(t, test.want, DistrolessImage(*semVer))
80+
})
81+
}
82+
}

lib/web/scripts/oneoff/oneoff.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ import (
2929
"github.com/gravitational/teleport/api"
3030
"github.com/gravitational/teleport/api/types"
3131
"github.com/gravitational/teleport/lib/modules"
32+
"github.com/gravitational/teleport/lib/utils/teleportassets"
3233
)
3334

3435
const (
35-
// teleportCDNLocation is the Teleport's CDN URL
36-
// This is used to download the Teleport Binary
37-
teleportCDNLocation = "https://cdn.teleport.dev"
38-
3936
// binUname is the default binary name for inspecting the host's OS.
4037
binUname = "uname"
4138

@@ -113,14 +110,14 @@ func (p *OneOffScriptParams) CheckAndSetDefaults() error {
113110
p.binSudo = "sudo"
114111
}
115112

116-
if p.CDNBaseURL == "" {
117-
p.CDNBaseURL = teleportCDNLocation
118-
}
119-
120113
if p.TeleportVersion == "" {
121114
p.TeleportVersion = "v" + api.Version
122115
}
123116

117+
if p.CDNBaseURL == "" {
118+
p.CDNBaseURL = teleportassets.CDNBaseURL()
119+
}
120+
124121
if p.TeleportFlavor == "" {
125122
p.TeleportFlavor = types.PackageNameOSS
126123
if modules.GetModules().BuildType() == modules.BuildEnterprise {

0 commit comments

Comments
 (0)