Skip to content
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

Avoid building the docker images if custom runtimes are provided #87

Open
emileten opened this issue Nov 28, 2023 · 1 comment
Open

Comments

@emileten
Copy link
Contributor

We recently allowed for customizable deployment runtimes for all the services. However, there is a big caveat in how we implemented this : the docker images associated with the default runtimes are built even if the user passes custom runtimes. In an of itself this is undesirable, but even more so because the way the CDK handles docker builds under the hood is kind of messy -- the less often it happens the better.

This ticket flags that we should make sure not to build our default images if custom runtimes are provided.

@emileten
Copy link
Contributor Author

Taking the stac api example, the fix should be as easy as

// Check if 'code' is provided in lambdaFunctionOptions
const isCodeProvided = props.lambdaFunctionOptions && 'code' in props.lambdaFunctionOptions;

// Initialize a variable for the code configuration
let lambdaCodeConfig;

// If 'code' is not provided in props.lambdaFunctionOptions, then define the default code configuration
// If 'code' is indeed provided in props.lambdaFunctionOptions, we'll skip building the images of the default runtimes. 
if (!isCodeProvided) {
    lambdaCodeConfig = lambda.Code.fromDockerBuild(__dirname, {
        file: "runtime/Dockerfile",
        buildArgs: { PYTHON_VERSION: '3.11' },
    });
}

this.stacApiLambdaFunction = new lambda.Function(this, "lambda", {
    // defaults for configurable properties
    runtime: lambda.Runtime.PYTHON_3_11,
    handler: "src.handler.handler",
    memorySize: 8192,
    logRetention: aws_logs.RetentionDays.ONE_WEEK,
    timeout: Duration.seconds(30),
    // Use the defined code configuration if 'code' is not provided in props
    code: isCodeProvided ? undefined : lambdaCodeConfig,
    // overwrites defaults with user-provided configurable properties
    ...props.lambdaFunctionOptions,
    // Non configurable properties that are going to be overwritten even if provided by the user
    vpc: props.vpc,
    vpcSubnets: props.subnetSelection,
    allowPublicSubnet: true,
    environment: {
        PGSTAC_SECRET_ARN: props.dbSecret.secretArn,
        DB_MIN_CONN_SIZE: "0",
        DB_MAX_CONN_SIZE: "1",
        ...props.apiEnv,
    },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant