Skip to content

Commit

Permalink
Remove ss_configs nest from config format
Browse files Browse the repository at this point in the history
  • Loading branch information
riseshia committed Aug 28, 2024
1 parent 79db466 commit 7c27d20
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 138 deletions.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,18 @@ Options:

```jsonnet
// `fubura.jsonnet`
{
ssConfigs: [{
state: {
// CreateStateMachine API Request Params except "versionDescription"
// https://docs.aws.amazon.com/step-functions/latest/apireference/API_CreateStateMachine.html
}, // should not be null
schedule: {
// CreateSchedule API Request Body except "ActionAfterCompletion", "ClientToken"
// https://docs.aws.amazon.com/scheduler/latest/APIReference/API_CreateSchedule.html
}, // could be null
deleteAll: true // Optional, default is false. If true, delete the state machine and schedule
deleteSchedule: true // Optional, default is false. If true, delete the schedule
}]
}
[{
state: {
// CreateStateMachine API Request Params except "versionDescription"
// https://docs.aws.amazon.com/step-functions/latest/apireference/API_CreateStateMachine.html
}, // should not be null
schedule: {
// CreateSchedule API Request Body except "ActionAfterCompletion", "ClientToken"
// https://docs.aws.amazon.com/scheduler/latest/APIReference/API_CreateSchedule.html
}, // could be null
deleteAll: true // Optional, default is false. If true, delete the state machine and schedule
deleteSchedule: true // Optional, default is false. If true, delete the schedule
}]
```

Full example configuration is available in [example](./example) directory.
Expand Down
188 changes: 92 additions & 96 deletions example/basic-example.jsonnet
Original file line number Diff line number Diff line change
@@ -1,112 +1,108 @@
{
ssConfigs: [
{
state: {
name: 'fubura-example',
definition: {
StartAt: 'RunTask',
States: {
Fail: {
Type: 'Fail',
},
RunTask: {
End: true,
Parameters: {
Cluster: 'fubura',
EnableExecuteCommand: true,
LaunchType: 'FARGATE',
NetworkConfiguration: {
AwsvpcConfiguration: {
SecurityGroups: [
'sg-00000000000000000',
],
Subnets: [
'subnet-00000000000000000',
'subnet-11111111111111111',
'subnet-22222222222222222',
],
},
},
Overrides: {
ContainerOverrides: [
{
Command: [
'bundle',
'exec',
'rails',
'routes',
],
Name: 'app',
},
],
Cpu: null,
Memory: null,
},
PropagateTags: 'TASK_DEFINITION',
TaskDefinition: 'arn:aws:ecs:us-west-2:123456789012:task-definition/fubura-batch',
[{
state: {
name: 'fubura-example',
definition: {
StartAt: 'RunTask',
States: {
Fail: {
Type: 'Fail',
},
RunTask: {
End: true,
Parameters: {
Cluster: 'fubura',
EnableExecuteCommand: true,
LaunchType: 'FARGATE',
NetworkConfiguration: {
AwsvpcConfiguration: {
SecurityGroups: [
'sg-00000000000000000',
],
Subnets: [
'subnet-00000000000000000',
'subnet-11111111111111111',
'subnet-22222222222222222',
],
},
Resource: 'arn:aws:states:::ecs:runTask.sync',
Retry: [
},
Overrides: {
ContainerOverrides: [
{
BackoffRate: 3,
ErrorEquals: [
'ECS.AmazonECSException',
Command: [
'bundle',
'exec',
'rails',
'routes',
],
IntervalSeconds: 5,
MaxAttempts: 4,
Name: 'app',
},
],
Type: 'Task',
Cpu: null,
Memory: null,
},
PropagateTags: 'TASK_DEFINITION',
TaskDefinition: 'arn:aws:ecs:us-west-2:123456789012:task-definition/fubura-batch',
},
},
roleArn: 'arn:aws:iam::123456789012:role/fubura_batch',
type: 'STANDARD',
loggingConfiguration: {
level: 'ALL',
includeExecutionData: true,
destinations: [
Resource: 'arn:aws:states:::ecs:runTask.sync',
Retry: [
{
cloudWatchLogsLogGroup: {
logGroupArn: 'arn:aws:logs:us-west-2:123456789012:log-group:/sfn/fubura_batch:*',
},
BackoffRate: 3,
ErrorEquals: [
'ECS.AmazonECSException',
],
IntervalSeconds: 5,
MaxAttempts: 4,
},
],
Type: 'Task',
},
tracingConfiguration: {
enabled: false,
},
tags: [
{
key: 'Name',
value: 'fubura-example',
},
],
},
schedule: {
groupName: 'fubura-group',
name: 'fubura-example',
state: 'ENABLED',
scheduleExpression: 'rate(10 hours)',
scheduleExpressionTimezone: 'Asia/Tokyo',
flexibleTimeWindow: {
mode: 'OFF',
},
target: {
arn: 'arn:aws:states:us-west-2:123456789012:stateMachine:fubura-example',
roleArn: 'arn:aws:iam::123456789012:role/fubura_batch',
deadLetterConfig: {
arn: 'arn:aws:sqs:us-west-2:123456789012:fubura_batch_dlq',
},
input: '{}',
retryPolicy: {
maximumEventAgeInSeconds: 86400,
maximumRetryAttempts: 0,
},
roleArn: 'arn:aws:iam::123456789012:role/fubura_batch',
type: 'STANDARD',
loggingConfiguration: {
level: 'ALL',
includeExecutionData: true,
destinations: [
{
cloudWatchLogsLogGroup: {
logGroupArn: 'arn:aws:logs:us-west-2:123456789012:log-group:/sfn/fubura_batch:*',
},
},
],
},
tracingConfiguration: {
enabled: false,
},
tags: [
{
key: 'Name',
value: 'fubura-example',
},
],
},
schedule: {
groupName: 'fubura-group',
name: 'fubura-example',
state: 'ENABLED',
scheduleExpression: 'rate(10 hours)',
scheduleExpressionTimezone: 'Asia/Tokyo',
flexibleTimeWindow: {
mode: 'OFF',
},
target: {
arn: 'arn:aws:states:us-west-2:123456789012:stateMachine:fubura-example',
roleArn: 'arn:aws:iam::123456789012:role/fubura_batch',
deadLetterConfig: {
arn: 'arn:aws:sqs:us-west-2:123456789012:fubura_batch_dlq',
},
input: '{}',
retryPolicy: {
maximumEventAgeInSeconds: 86400,
maximumRetryAttempts: 0,
},
deleteAll: false,
deleteSchedule: false,
},
],
}
},
deleteAll: false,
deleteSchedule: false,
}]
12 changes: 5 additions & 7 deletions example/simple-ecs-run-task.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ local batch(name, definition, schedule, scheduleEnabled=true) = {
schedule: buildSchedule(name, schedule, scheduleEnabled),
};

{
ssConfigs: [
batch('some-task', buildDefinition(
command=['bundle', 'exec', 'rails', 'routes']
), 'rate(1 hours)'),
],
}
[
batch('some-task', buildDefinition(
command=['bundle', 'exec', 'rails', 'routes']
), 'rate(1 hours)'),
]
37 changes: 18 additions & 19 deletions src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ impl ImportCommand {

config.ss_configs.push(ss_config);

std::fs::write(config_path, serde_json::to_string_pretty(&config).unwrap())?;
std::fs::write(
config_path,
serde_json::to_string_pretty(&config.ss_configs).unwrap(),
)?;

Ok(())
}
Expand Down Expand Up @@ -191,17 +194,15 @@ mod test {

let config_str =
std::fs::read_to_string(imported_config_path).expect("imported config not found");
let actual_config: Config =
let actual_config: Vec<SsConfig> =
serde_json::from_str(&config_str).expect("imported config is not valid json");

let expected_config = Config {
ss_configs: vec![SsConfig {
state: StateMachine::test_default(),
schedule: Some(Schedule::test_default()),
delete_all: false,
delete_schedule: false,
}],
};
let expected_config = vec![SsConfig {
state: StateMachine::test_default(),
schedule: Some(Schedule::test_default()),
delete_all: false,
delete_schedule: false,
}];

similar_asserts::assert_eq!(actual_config, expected_config);
}
Expand Down Expand Up @@ -291,16 +292,14 @@ mod test {

let config_str =
std::fs::read_to_string(imported_config_path).expect("imported config not found");
let actual_config: Config =
let actual_config: Vec<SsConfig> =
serde_json::from_str(&config_str).expect("imported config is not valid");
let expected_config = Config {
ss_configs: vec![SsConfig {
state: StateMachine::test_default(),
schedule: None,
delete_all: false,
delete_schedule: false,
}],
};
let expected_config = vec![SsConfig {
state: StateMachine::test_default(),
schedule: None,
delete_all: false,
delete_schedule: false,
}];

similar_asserts::assert_eq!(actual_config, expected_config);
}
Expand Down
6 changes: 4 additions & 2 deletions src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ impl Config {
fast_exit!("failed to evaluate jsonnet: {}", e);
});

serde_json::from_value(config_value).unwrap_or_else(|e| {
let ss_configs: Vec<SsConfig> = serde_json::from_value(config_value).unwrap_or_else(|e| {
fast_exit!("failed to parse config file: {}", e);
})
});

Config { ss_configs }
}

pub fn target_ss_configs(&self, targets: &Option<Vec<String>>) -> Vec<&SsConfig> {
Expand Down

0 comments on commit 7c27d20

Please sign in to comment.