Skip to content

Commit

Permalink
Testing ubuntu base image
Browse files Browse the repository at this point in the history
  • Loading branch information
314pies committed Oct 28, 2023
1 parent dc4b7bf commit 5ff0d10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions lib/mine-cloud-stack.ts
Expand Up @@ -19,12 +19,15 @@ import {
BlockDeviceVolume,
CfnKeyPair,
InstanceType,
MachineImage,
OperatingSystemType,
Peer,
Port,
SecurityGroup,
SpotInstanceInterruption,
SpotRequestType,
SubnetType,
UserData,
Vpc
} from 'aws-cdk-lib/aws-ec2';
import { DiscordInteractionsEndpointConstruct } from './discord-interactions-endpoint-construct';
Expand Down Expand Up @@ -146,6 +149,26 @@ export class MineCloud extends Stack {
);
}

const userData = UserData.forLinux();
userData.addCommands(
// Set up CloudFormation helper scripts
'apt update -y',
'apt install python3-pip -y',
'install setuptools',
'mkdir -p /opt/aws/bin',
'wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz',
'python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz',
'ln -s /root/aws-cfn-bootstrap-py3-latest/init/ubuntu/cfn-hub /etc/init.d/cfn-hub',
'echo "CloudFormation helper scripts setup completed"',
// Set up awscli
'apt-get install awscli'
);
// https://ubuntu.com/server/docs/cloud-images/amazon-ec2
const machineImage = MachineImage.fromSsmParameter(
'/aws/service/canonical/ubuntu/server-minimal/20.04/stable/current/amd64/hvm/ebs-gp2/ami-id',
{os: OperatingSystemType.LINUX, userData: userData}
);

// Key pair for ssh-ing into EC2 instance from aws console
const sshKeyPair = new CfnKeyPair(this, `${STACK_PREFIX}_ec2_key_pair`, {
keyName: `${STACK_PREFIX}_ec2_key`
Expand All @@ -161,9 +184,7 @@ export class MineCloud extends Stack {
// },
securityGroup: securityGroup,
instanceType: new InstanceType(EC2_INSTANCE_TYPE),
machineImage: new AmazonLinuxImage({
generation: AmazonLinuxGeneration.AMAZON_LINUX_2
}),
machineImage: machineImage,
templateId: `${STACK_PREFIX}_ec2_launch_template`,
launchTemplateSpotOptions: {
interruptionBehavior: SpotInstanceInterruption.STOP,
Expand Down
2 changes: 1 addition & 1 deletion minecloud_configs/advanced_configs/custom-instance-init.ts
Expand Up @@ -13,7 +13,7 @@ export const CUSTOM_INIT_CONFIG: InitConfig = getCustomInitConfig();
function getCustomInitConfig(): InitConfig {
let configs: (InitPackage | InitCommand | InitFile)[] = [
// Install an Amazon Java package using yum
InitPackage.yum('java-17-amazon-corretto-headless'),
InitCommand.shellCommand('apt install openjdk-17-jdk openjdk-17-jre'),
InitCommand.shellCommand("echo 'eula=true' > eula.txt", {
cwd: MINECLOUD_SERVER_DIR
})
Expand Down

0 comments on commit 5ff0d10

Please sign in to comment.