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

Support for using a particular tag of the minecraft docker images. #32

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions cdk/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ TWILIO_AUTH_CODE =
# Advanced

DEBUG = false
MINECRAFT_IMAGE_TAG =
1 change: 1 addition & 0 deletions cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ set in `.env`.
| TWILIO_ACCOUNT_ID | Twilio account ID. | -- |
| TWILIO_AUTH_CODE | Twilio auth code. | -- |
| DEBUG | Enables debug mode. | -- |
| MINECRAFT_IMAGE_TAG | Use a particular tag of the minecraft docker image. (e.g. java11-openj9 from https://github.com/itzg/docker-minecraft-server/blob/master/README.md#running-minecraft-server-on-different-java-version) | -- |

## Cleanup

Expand Down
1 change: 1 addition & 0 deletions cdk/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export const resolveConfig = (): StackConfig => ({
authCode: process.env.TWILIO_AUTH_CODE || '',
},
debug: stringAsBoolean(process.env.DEBUG) || false,
minecraftImageTag: process.env.MINECRAFT_IMAGE_TAG || '',
});
2 changes: 1 addition & 1 deletion cdk/lib/minecraft-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class MinecraftStack extends Stack {
);

const minecraftServerConfig = getMinecraftServerConfig(
config.minecraftEdition
config.minecraftEdition, config.minecraftImageTag
);

const minecraftServerContainer = new ecs.ContainerDefinition(
Expand Down
8 changes: 8 additions & 0 deletions cdk/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ export interface StackConfig {
* - CloudWatch Logs for the `minecraft-ecsfargate-watchdog` ECS Container
*/
debug: boolean;
/**
* The tag of the docker image to use for the
* [Minecraft Docker Server](https://github.com/itzg/docker-minecraft-server/blob/master/README.md)
* [Minecraft Bedrock Docker](https://github.com/itzg/docker-minecraft-bedrock-server/blob/master/README.md)
*
* @default ''
*/
minecraftImageTag: string;
}

export interface MinecraftEditionConfig {
Expand Down
21 changes: 18 additions & 3 deletions cdk/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@ export const isDockerInstalled = (): boolean => {
}
};

function imageFromTag(base:string, tag:string) {
if (tag && tag.length > 0) {
if (base.includes(':')) {
return base.substring(0, base.indexOf(':')) + ':' + tag
} else {
return base + ':' + tag;
}
} else {
return base;
}
}

export const getMinecraftServerConfig = (
edition: StackConfig['minecraftEdition']
edition: StackConfig['minecraftEdition'],
imageTag: StackConfig['minecraftImageTag']
): MinecraftEditionConfig => {
const javaEditionImage = imageFromTag(constants.JAVA_EDITION_DOCKER_IMAGE, imageTag)
const bedrockEditionImage = imageFromTag(constants.BEDROCK_EDITION_DOCKER_IMAGE, imageTag)
const javaConfig = {
image: constants.JAVA_EDITION_DOCKER_IMAGE,
image: javaEditionImage,
port: 25565,
protocol: Protocol.TCP,
ingressRulePort: Port.tcp(25565),
};

const bedrockConfig = {
image: constants.BEDROCK_EDITION_DOCKER_IMAGE,
image: bedrockEditionImage,
port: 19132,
protocol: Protocol.UDP,
ingressRulePort: Port.udp(19132),
Expand Down