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

feat: healthcheck config #55

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ inputs:
auto-scaling-config-arn:
description: 'ARN of an App Runner automatic scaling configuration that you want to associate with the App Runner service'
required: false
healthcheck-path:
description: 'The URL path that the App Runner service uses to perform health checks on the service. Setting this value configures the protocol to HTTP.'
required: false
healthcheck-timeout-seconds:
description: 'Amount of time the load balancer waits for a health check response.'
default: '2'
required: false
healthcheck-interval-seconds:
description: 'Amount of time between health checks of an individual instance.'
deafult: '5'
required: false
healthcheck-unhealthy-threshold:
description: 'The number of consecutive health check failures that determine an instance is unhealthy.'
default: '5'
required: false
healthcheck-healthy-threshold:
description: 'The number of consecutive successful health checks that determine an instance is healthy.'
default: '1'
required: false
outputs:
service-id:
description: 'App Runner service ID'
Expand Down
114 changes: 27 additions & 87 deletions dist/index.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/action-configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test, describe } from "@jest/globals";
import { expect, test, describe, it } from "@jest/globals";
import { getConfig } from "./action-configuration";

describe("getConfig", () => {
Expand All @@ -23,4 +23,15 @@ describe("getConfig", () => {
test("autoscaling config ARN is undefined when input is not specified/empty", () => {
expect(getConfig().autoScalingConfigArn).toBeUndefined();
})

it('should return tcp healtcheck protocol when path is not set', () => {
const config = getConfig();
expect(config.healthCheckConfig.protocol).toBe('TCP');
})

it('should return http healthcheck protocol when healthcheck-path is set', () => {
process.env["INPUT_HEALTHCHECK-PATH"] = "/health";
const config = getConfig();
expect(config.healthCheckConfig.protocol).toBe('HTTP');
})
})
20 changes: 20 additions & 0 deletions src/action-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export interface IImageConfiguration {
accessRoleArn: string;
}

export interface IHealthCheckConfiguration {
protocol: 'HTTP' | 'TCP';
path?: string;
interval: number;
timout: number;
healthyThreshold: number;
unhealthyThreshold: number;
}

export interface ICreateOrUpdateActionParams {
action: Actions.CreateOrUpdate;
serviceName: string;
Expand All @@ -38,6 +47,7 @@ export interface ICreateOrUpdateActionParams {
tags: Tag[]
autoScalingConfigArn?: string;
instanceRoleArn?: string;
healthCheckConfig: IHealthCheckConfiguration;
}

export type IActionParams = ICreateOrUpdateActionParams;
Expand Down Expand Up @@ -139,6 +149,15 @@ function getCreateOrUpdateConfig(): ICreateOrUpdateActionParams {

const instanceRoleArn = getOptionalInputStr('instance-role-arn', { trimWhitespace: true });

const healthCheckConfig: IHealthCheckConfiguration = {
protocol: getOptionalInputStr('healthcheck-path', { required: false, trimWhitespace: true }) ? 'HTTP' : 'TCP',
path: getOptionalInputStr('healthcheck-path', { required: false }),
interval: getInputNumber('healthcheck-interval-seconds', 5, { intOnly: true }),
timout: getInputNumber('healthcheck-timeout-seconds', 2, { intOnly: true }),
healthyThreshold: getInputNumber('healthcheck-healthy-threshold', 2, { intOnly: true }),
unhealthyThreshold: getInputNumber('healthcheck-unhealthy-threshold', 2, { intOnly: true }),
};

return {
action,
serviceName,
Expand All @@ -154,6 +173,7 @@ function getCreateOrUpdateConfig(): ICreateOrUpdateActionParams {
tags: getTags(tags),
autoScalingConfigArn: autoScalingConfigArn,
instanceRoleArn: instanceRoleArn,
healthCheckConfig: healthCheckConfig,
};
}

Expand Down
17 changes: 15 additions & 2 deletions src/client-apprunner-commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateServiceCommand, DeleteServiceCommand, DescribeServiceCommand, ImageRepositoryType, ListServicesCommand, SourceConfiguration, UpdateServiceCommand, TagResourceCommand, ListOperationsCommand } from "@aws-sdk/client-apprunner";
import { ICodeConfiguration, ICreateOrUpdateActionParams, IImageConfiguration } from "./action-configuration";
import { CreateServiceCommand, DeleteServiceCommand, DescribeServiceCommand, ImageRepositoryType, ListServicesCommand, SourceConfiguration, UpdateServiceCommand, TagResourceCommand, ListOperationsCommand, HealthCheckConfiguration } from "@aws-sdk/client-apprunner";
import { ICodeConfiguration, ICreateOrUpdateActionParams, IHealthCheckConfiguration, IImageConfiguration } from "./action-configuration";

export function getCreateCommand(config: ICreateOrUpdateActionParams): CreateServiceCommand {
return new CreateServiceCommand({
Expand All @@ -14,6 +14,7 @@ export function getCreateCommand(config: ICreateOrUpdateActionParams): CreateSer
? getImageSourceConfiguration(config.port, config.sourceConfig, config.environment, config.environmentSecret)
: getCodeSourceConfiguration(config.port, config.sourceConfig, config.environment, config.environmentSecret),
Tags: config.tags,
HealthCheckConfiguration: getHealthCheckConfiguration(config.healthCheckConfig)
});
}

Expand All @@ -29,6 +30,7 @@ export function getUpdateCommand(serviceArn: string, config: ICreateOrUpdateActi
SourceConfiguration: (config.sourceConfig.sourceType == 'image')
? getImageSourceConfiguration(config.port, config.sourceConfig, config.environment, config.environmentSecret)
: getCodeSourceConfiguration(config.port, config.sourceConfig, config.environment, config.environmentSecret),
HealthCheckConfiguration: getHealthCheckConfiguration(config.healthCheckConfig),
});
}

Expand Down Expand Up @@ -111,3 +113,14 @@ function getImageSourceConfiguration(port: number, config: IImageConfiguration,
}
};
}

function getHealthCheckConfiguration(config: IHealthCheckConfiguration): HealthCheckConfiguration {
return {
Protocol: config.protocol,
Path: config.path,
Interval: config.interval,
Timeout: config.timout,
HealthyThreshold: config.healthyThreshold,
UnhealthyThreshold: config.unhealthyThreshold,
}
}