Skip to content
Merged
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
64 changes: 64 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
Name|Description
----|-----------
[ValheimWorld](#cdk-valheim-valheimworld)|*No description*
[ValheimWorldScalingSchedule](#cdk-valheim-valheimworldscalingschedule)|Represents the schedule to determine when the server starts or terminates.


**Structs**

Name|Description
----|-----------
[ValheimWorldProps](#cdk-valheim-valheimworldprops)|*No description*
[ValheimWorldScalingScheduleProps](#cdk-valheim-valheimworldscalingscheduleprops)|Options for ValheimWorldScalingSchedule.



Expand Down Expand Up @@ -42,6 +44,7 @@ new ValheimWorld(scope: Construct, id: string, props?: ValheimWorldProps)
* **image** (<code>[ContainerImage](#aws-cdk-aws-ecs-containerimage)</code>) *No description* __*Optional*__
* **logGroup** (<code>[LogDriver](#aws-cdk-aws-ecs-logdriver)</code>) Valheim Server log Group. __*Default*__: Create the new AWS Cloudwatch Log Group for Valheim Server.
* **memoryLimitMiB** (<code>number</code>) The amount (in MiB) of memory used by the task. __*Default*__: 2048
* **schedules** (<code>Array<[ValheimWorldScalingScheduleProps](#cdk-valheim-valheimworldscalingscheduleprops)></code>) Running schedules. __*Default*__: Always running.
* **vpc** (<code>[IVpc](#aws-cdk-aws-ec2-ivpc)</code>) The VPC where your ECS instances will be running or your ENIs will be deployed. __*Default*__: creates a new VPC with two AZs


Expand All @@ -54,6 +57,52 @@ Name | Type | Description
**backupPlan** | <code>[BackupPlan](#aws-cdk-aws-backup-backupplan)</code> | <span></span>
**fileSystem** | <code>[FileSystem](#aws-cdk-aws-efs-filesystem)</code> | <span></span>
**service** | <code>[FargateService](#aws-cdk-aws-ecs-fargateservice)</code> | <span></span>
**schedules**? | <code>Array<[ValheimWorldScalingSchedule](#cdk-valheim-valheimworldscalingschedule)></code> | __*Optional*__



## class ValheimWorldScalingSchedule <a id="cdk-valheim-valheimworldscalingschedule"></a>

Represents the schedule to determine when the server starts or terminates.


### Initializer




```ts
new ValheimWorldScalingSchedule(schedule: ValheimWorldScalingScheduleProps)
```

* **schedule** (<code>[ValheimWorldScalingScheduleProps](#cdk-valheim-valheimworldscalingscheduleprops)</code>) *No description*
* **startAt** (<code>[CronOptions](#aws-cdk-aws-applicationautoscaling-cronoptions)</code>) Options to configure a cron expression for server for server launching schedule.
* **stopAt** (<code>[CronOptions](#aws-cdk-aws-applicationautoscaling-cronoptions)</code>) Options to configure a cron expression for server zero-scale schedule.



### Properties


Name | Type | Description
-----|------|-------------
**startAt** | <code>[CronOptions](#aws-cdk-aws-applicationautoscaling-cronoptions)</code> | Options to configure a cron expression for server for server launching schedule.
**stopAt** | <code>[CronOptions](#aws-cdk-aws-applicationautoscaling-cronoptions)</code> | Options to configure a cron expression for server zero-scale schedule.

### Methods


#### toCronOptions() <a id="cdk-valheim-valheimworldscalingschedule-tocronoptions"></a>

Returns the cron option merged both startAt and endAt.

```ts
toCronOptions(): CronOptions
```


__Returns__:
* <code>[CronOptions](#aws-cdk-aws-applicationautoscaling-cronoptions)</code>



Expand All @@ -74,7 +123,22 @@ Name | Type | Description
**image**? | <code>[ContainerImage](#aws-cdk-aws-ecs-containerimage)</code> | __*Optional*__
**logGroup**? | <code>[LogDriver](#aws-cdk-aws-ecs-logdriver)</code> | Valheim Server log Group.<br/>__*Default*__: Create the new AWS Cloudwatch Log Group for Valheim Server.
**memoryLimitMiB**? | <code>number</code> | The amount (in MiB) of memory used by the task.<br/>__*Default*__: 2048
**schedules**? | <code>Array<[ValheimWorldScalingScheduleProps](#cdk-valheim-valheimworldscalingscheduleprops)></code> | Running schedules.<br/>__*Default*__: Always running.
**vpc**? | <code>[IVpc](#aws-cdk-aws-ec2-ivpc)</code> | The VPC where your ECS instances will be running or your ENIs will be deployed.<br/>__*Default*__: creates a new VPC with two AZs



## struct ValheimWorldScalingScheduleProps <a id="cdk-valheim-valheimworldscalingscheduleprops"></a>


Options for ValheimWorldScalingSchedule.



Name | Type | Description
-----|------|-------------
**startAt** | <code>[CronOptions](#aws-cdk-aws-applicationautoscaling-cronoptions)</code> | Options to configure a cron expression for server for server launching schedule.
**stopAt** | <code>[CronOptions](#aws-cdk-aws-applicationautoscaling-cronoptions)</code> | Options to configure a cron expression for server zero-scale schedule.



26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ See [API.md](API.md)
new ValheimWorld(stack, 'ValheimWorld', {
cpu: 2048,
memoryLimitMiB: 4096,
schedules: [{
startAt: { hour: '12', weekDay: '0-3' },
stopAt: { hour: '1', weekDay: '0-3' },
}],
environment: {
SERVER_NAME: 'CDK Valheim',
WORLD_NAME: 'Amazon',
SERVER_PASS: 'fargate',
// SERVER_PUBLIC: 1,
// UPDATE_INTERVAL: 900,
// BACKUPS_INTERVAL: 3600,
BACKUPS: 'false',
// SERVER_PORT: '2456',
// SERVER_PUBLIC: 'true',
// UPDATE_CRON: '*/15 * * * *',
// RESTART_CRON: '0 5 * * *',
// TZ: 'Etc/UTC',
// BACKUPS_CRON: '0 * * * *',
// BACKUPS_DIRECTORY: '/config/backups',
// BACKUPS_MAX_AGE: 3,
// BACKUPS_DIRECTORY_PERMISSIONS: 755,
// BACKUPS_FILE_PERMISSIONS: 644,
// CONFIG_DIRECTORY_PERMISSIONS: 755,
// WORLDS_DIRECTORY_PERMISSIONS: 755,
// WORLDS_FILE_PERMISSIONS: 644,
// BACKUPS_MAX_AGE: '3',
// PERMISSIONS_UMASK: '022',
// STEAMCMD_ARGS: 'validate',
// VALHEIM_PLUS: 'false',
},
});
```
Expand All @@ -35,7 +41,7 @@ new ValheimWorld(stack, 'ValheimWorld', {
* Snapshot

```sh
yarn test
npx projen test
```

* Integration
Expand Down
45 changes: 16 additions & 29 deletions src/integ.valheim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as appscaling from '@aws-cdk/aws-applicationautoscaling';
import { App, Stack } from '@aws-cdk/core';
import { ValheimWorld } from './index';

Expand All @@ -10,37 +9,25 @@ const env = {
const app = new App();
const stack = new Stack(app, 'ValheimStack', { env });

const valheimWorld = new ValheimWorld(stack, 'ValheimWorld', {
new ValheimWorld(stack, 'ValheimWorld', {
// Warning: It's UTC.
schedules: [{
startAt: { hour: '12', weekDay: '0-3' },
stopAt: { hour: '1', weekDay: '0-3' },
},
// It's friday night ;)
{
startAt: { hour: '12', weekDay: '4' },
stopAt: { hour: '4', weekDay: '4' },
},
// It's weekend.
{
startAt: { weekDay: '5' },
stopAt: { weekDay: '0' },
}],
environment: {
SERVER_NAME: 'CDK Valheim',
WORLD_NAME: 'Amazon',
SERVER_PASS: 'fargate',
// SERVER_PUBLIC: 1,
// UPDATE_INTERVAL: 900,
// BACKUPS_INTERVAL: 3600,
// BACKUPS_DIRECTORY: '/config/backups',
// BACKUPS_MAX_AGE: 3,
// BACKUPS_DIRECTORY_PERMISSIONS: 755,
// BACKUPS_FILE_PERMISSIONS: 644,
// CONFIG_DIRECTORY_PERMISSIONS: 755,
// WORLDS_DIRECTORY_PERMISSIONS: 755,
// WORLDS_FILE_PERMISSIONS: 644,
},
});

const taskCount = valheimWorld.service.autoScaleTaskCount({
maxCapacity: 1,
});

// Warning: It's UTC
taskCount.scaleOnSchedule('StopAtMidnigt', {
schedule: appscaling.Schedule.cron({ hour: '0' }),
minCapacity: 0,
maxCapacity: 0,
});

taskCount.scaleOnSchedule('StartAtMorning', {
schedule: appscaling.Schedule.cron({ hour: '9' }),
minCapacity: 1,
maxCapacity: 1,
});
Loading