-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support different architectures when copying images #570
base: main
Are you sure you want to change the base?
Changes from all commits
10d0f9e
2dbed59
6bc2bcb
deb2675
c3872c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a new test case using and asserting the new feature, keeping the old test case as it was. If the old test case also needs to be changed, please explain why. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,11 @@ import ( | |
) | ||
|
||
const ( | ||
SRC_IMAGE string = "SrcImage" | ||
DEST_IMAGE string = "DestImage" | ||
SRC_CREDS string = "SrcCreds" | ||
DEST_CREDS string = "DestCreds" | ||
SRC_IMAGE string = "SrcImage" | ||
DEST_IMAGE string = "DestImage" | ||
SRC_CREDS string = "SrcCreds" | ||
DEST_CREDS string = "DestCreds" | ||
ARCHITECTURE string = "Architecture" | ||
) | ||
|
||
type ECRAuth struct { | ||
|
@@ -35,6 +36,33 @@ type ECRAuth struct { | |
ExpiresAt time.Time | ||
} | ||
|
||
var validArchs = []string{ | ||
"386", | ||
"amd64", | ||
"amd64p32", | ||
"arm", | ||
"arm64", | ||
"arm64be", | ||
"armbe", | ||
"loong64", | ||
"mips", | ||
"mips64", | ||
"mips64le", | ||
"mips64p32", | ||
"mips64p32le", | ||
"mipsle", | ||
"ppc", | ||
"ppc64", | ||
"ppc64le", | ||
"riscv", | ||
"riscv64", | ||
"s390", | ||
"s390x", | ||
"sparc", | ||
"sparc64", | ||
"wasm", | ||
} | ||
|
||
func GetECRRegion(uri string) string { | ||
re := regexp.MustCompile(`dkr\.ecr\.(.+?)\.`) | ||
m := re.FindStringSubmatch(uri) | ||
|
@@ -86,14 +114,15 @@ type ImageOpts struct { | |
requireECRLogin bool | ||
region string | ||
creds string | ||
architecture string | ||
} | ||
|
||
func NewImageOpts(uri string) *ImageOpts { | ||
func NewImageOpts(uri string, arch string) *ImageOpts { | ||
requireECRLogin := strings.Contains(uri, "dkr.ecr") | ||
if requireECRLogin { | ||
return &ImageOpts{uri, requireECRLogin, GetECRRegion(uri), ""} | ||
return &ImageOpts{uri, requireECRLogin, GetECRRegion(uri), "", arch} | ||
} else { | ||
return &ImageOpts{uri, requireECRLogin, "", ""} | ||
return &ImageOpts{uri, requireECRLogin, "", "", arch} | ||
} | ||
} | ||
|
||
|
@@ -109,6 +138,7 @@ func (s *ImageOpts) NewSystemContext() (*types.SystemContext, error) { | |
ctx := &types.SystemContext{ | ||
DockerRegistryUserAgent: "ecr-deployment", | ||
DockerAuthConfig: &types.DockerAuthConfig{}, | ||
ArchitectureChoice: s.architecture, | ||
} | ||
|
||
if s.creds != "" { | ||
|
@@ -184,3 +214,13 @@ func GetSecret(secretId string) (secret string, err error) { | |
} | ||
return *resp.SecretString, nil | ||
} | ||
|
||
func IsValidGOARCH(arch string) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this used? |
||
for _, validArch := range validArchs { | ||
if arch == validArch { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this file doing? Why was it added? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
ECR_URI="758920976184.dkr.ecr.us-east-1.amazonaws.com" | ||
ECR_REPO_URI=$ECR_URI/cdk-ecr-deployment | ||
# Authenticate with AWS ECR | ||
aws ecr get-login-password --profile "$AWS_PROFILE" --region "$AWS_REGION" | docker login --username AWS --password-stdin "$ECR_URI" | ||
|
||
# Get the current Git commit hash | ||
GIT_COMMIT_HASH=$(git rev-parse --short HEAD) | ||
|
||
# push to registry | ||
# --provenance=true necessary to avoid the error https://stackoverflow.com/a/75149347/4820648 | ||
docker buildx build \ | ||
--provenance=false \ | ||
--file lambda/Dockerfile \ | ||
--push \ | ||
--tag $ECR_REPO_URI:latest \ | ||
--tag $ECR_REPO_URI:$GIT_COMMIT_HASH \ | ||
--platform linux/amd64 \ | ||
--progress=plain \ | ||
lambda/. | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,6 +31,11 @@ export interface ECRDeploymentProps { | |||||||||
*/ | ||||||||||
readonly dest: IImageName; | ||||||||||
|
||||||||||
/** | ||||||||||
* The architecture of the docker images to copy. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
*/ | ||||||||||
readonly architecture?: string; | ||||||||||
|
||||||||||
/** | ||||||||||
* The amount of memory (in MiB) to allocate to the AWS Lambda function which | ||||||||||
* replicates the files from the CDK bucket to the destination bucket. | ||||||||||
|
@@ -192,6 +197,7 @@ export class ECRDeployment extends Construct { | |||||||||
SrcCreds: props.src.creds, | ||||||||||
DestImage: props.dest.uri, | ||||||||||
DestCreds: props.dest.creds, | ||||||||||
Architecture: props.architecture, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reckon we should fix this and move away from defaulting to the lambda architecture to explicitly defining a default here. |
||||||||||
}, | ||||||||||
}); | ||||||||||
} | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add e new test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?