As of December 2020, Lambda functions can also be packaged as OCI compatible container
images. Your Sparta application can leverage this capability by providing
a dockerFile argument to provision
. The contents of your Dockerfile must
produce a container with a reserved label so that Sparta can determine what
ECR instance to push your container.
Sparta docker build arguments:
A simple HelloWorld Dockerfile is as follows:
FROM public.ecr.aws/lambda/go:1
ARG AWS_ACCOUNT_ID
ARG AWS_REGION
ARG SPARTA_BINARY
ARG SPARTA_ECR_LABEL_NAME
ARG SPARTA_BUILD_ID
LABEL ${SPARTA_ECR_LABEL_NAME}=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/spartaoci:${SPARTA_BUILD_ID}
COPY ${SPARTA_BINARY} /var/task/SpartaOCI
WORKDIR /var/task
CMD [ "SpartaOCI" ]
Providing the reserved LABEL value allows Sparta to locally tag, authenticate with the ECR, push the image, and finally use the uploaded CodeURI as a provisioning argument:
...
01 Jan 21 20:27 PST |INFO | Successfully built 95a7695342c5 io=stdout
01 Jan 21 20:27 PST |INFO | Successfully tagged sparta/myocistack-123412341234:58e1819785b3a40e1642879c60b0716dad873021 io=stdout
01 Jan 21 20:27 PST |INFO | '123412341234.dkr.ecr.us-west-2.amazonaws.com/spartaoci:58e1819785b3a40e1642879c60b0716dad873021' io=stdout
01 Jan 21 20:27 PST |INFO | Provisioning service InPlaceUpdates=false NOOP=false Params={"ArtifactS3Bucket":"weagle"} Tags={"io:sparta:buildId":"58e1819785b3a40e1642879c60b0716dad873021"} Template=.sparta/MyOCIStack_123412341234-cftemplate.json
01 Jan 21 20:27 PST |INFO | Checking S3 region Bucket=weagle CredentialsRegion=us-west-2 Region=us-west-2
01 Jan 21 20:27 PST |INFO | Checking S3 versioning policy Bucket=weagle Region=us-west-2 VersioningEnabled=true
01 Jan 21 20:27 PST |INFO | Pushing local image to ECR Tag=123412341234.dkr.ecr.us-west-2.amazonaws.com/spartaoci:58e1819785b3a40e1642879c60b0716dad873021
01 Jan 21 20:27 PST |INFO | Uploading Bucket=weagle Key=MyOCIStack-123412341234/MyOCIStack_123412341234-cftemplate.json Path=.sparta/MyOCIStack_123412341234-cftemplate.json Size="2.6 kB"
01 Jan 21 20:27 PST |INFO | The push refers to repository [123412341234.dkr.ecr.us-west-2.amazonaws.com/spartaoci] io=stdout
01 Jan 21 20:27 PST |INFO | 4a307d712ef3: Preparing io=stdout
01 Jan 21 20:27 PST |INFO | c9041e2fe22e: Preparing io=stdout
...