-
Notifications
You must be signed in to change notification settings - Fork 4
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
XAWS-4: Added CDK code for XWiki demo installation with unit tests. #6
Changes from 7 commits
f7aeac2
3450ebd
4b57e31
bd04393
9174ac0
d13e1a0
7c77b46
1697a17
69f03be
ec346bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
*.d.ts | ||
node_modules | ||
|
||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out | ||
.eslintrc.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"vpc-provider:account=656019072197:filter.isDefault=true:region=us-east-1:returnAsymmetricSubnets=true": { | ||
"vpcId": "vpc-740af709", | ||
"vpcCidrBlock": "172.31.0.0/16", | ||
"availabilityZones": [], | ||
"subnetGroups": [ | ||
{ | ||
"name": "Public", | ||
"type": "Public", | ||
"subnets": [ | ||
{ | ||
"subnetId": "subnet-257c0c68", | ||
"cidr": "172.31.16.0/20", | ||
"availabilityZone": "us-east-1a", | ||
"routeTableId": "rtb-8f8ff7f1" | ||
}, | ||
{ | ||
"subnetId": "subnet-20d8757f", | ||
"cidr": "172.31.32.0/20", | ||
"availabilityZone": "us-east-1b", | ||
"routeTableId": "rtb-8f8ff7f1" | ||
}, | ||
{ | ||
"subnetId": "subnet-f1319097", | ||
"cidr": "172.31.0.0/20", | ||
"availabilityZone": "us-east-1c", | ||
"routeTableId": "rtb-8f8ff7f1" | ||
}, | ||
{ | ||
"subnetId": "subnet-0e8b242f", | ||
"cidr": "172.31.80.0/20", | ||
"availabilityZone": "us-east-1d", | ||
"routeTableId": "rtb-8f8ff7f1" | ||
}, | ||
{ | ||
"subnetId": "subnet-7a3dc94b", | ||
"cidr": "172.31.48.0/20", | ||
"availabilityZone": "us-east-1e", | ||
"routeTableId": "rtb-8f8ff7f1" | ||
}, | ||
{ | ||
"subnetId": "subnet-47f76d49", | ||
"cidr": "172.31.64.0/20", | ||
"availabilityZone": "us-east-1f", | ||
"routeTableId": "rtb-8f8ff7f1" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"vpc-provider:account=656019072197:filter.isDefault=true:region=eu-central-1:returnAsymmetricSubnets=true": { | ||
"vpcId": "vpc-16268b7c", | ||
"vpcCidrBlock": "172.31.0.0/16", | ||
"availabilityZones": [], | ||
"subnetGroups": [ | ||
{ | ||
"name": "Public", | ||
"type": "Public", | ||
"subnets": [ | ||
{ | ||
"subnetId": "subnet-f691059c", | ||
"cidr": "172.31.16.0/20", | ||
"availabilityZone": "eu-central-1a", | ||
"routeTableId": "rtb-708ea91a" | ||
}, | ||
{ | ||
"subnetId": "subnet-afe724d3", | ||
"cidr": "172.31.32.0/20", | ||
"availabilityZone": "eu-central-1b", | ||
"routeTableId": "rtb-708ea91a" | ||
}, | ||
{ | ||
"subnetId": "subnet-1711c75b", | ||
"cidr": "172.31.0.0/20", | ||
"availabilityZone": "eu-central-1c", | ||
"routeTableId": "rtb-708ea91a" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"availability-zones:account=656019072197:region=us-east-1": [ | ||
"us-east-1a", | ||
"us-east-1b", | ||
"us-east-1c", | ||
"us-east-1d", | ||
"us-east-1e", | ||
"us-east-1f" | ||
], | ||
"availability-zones:account=656019072197:region=eu-central-1": [ | ||
"eu-central-1a", | ||
"eu-central-1b", | ||
"eu-central-1c" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { StackProps } from '@aws-cdk/core' | ||
|
||
export interface ec2props extends StackProps{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add JavaDoc for all classes. Explain parameters in comments. What's the use of each. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Please suggest the changes if required |
||
|
||
xwiki: string | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const xwikidownload = 'https://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/platform/xwiki-platform-distribution-flavor-jetty-hsqldb/13.1/xwiki-platform-distribution-flavor-jetty-hsqldb-13.1.zip' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
import { Stack, App, CfnOutput } from '@aws-cdk/core' | ||
import { Vpc, SecurityGroup, Peer, Port, Instance, InstanceType, InstanceClass, InstanceSize, MachineImage, AmazonLinuxGeneration, SubnetType, UserData } from '@aws-cdk/aws-ec2' | ||
import { Role, ServicePrincipal } from '@aws-cdk/aws-iam' | ||
import { ec2props } from '../stacks/Ec2-model' | ||
|
||
export class EC2XwikiDemo extends Stack { | ||
constructor (scope: App, id: string, props: ec2props) { | ||
super(scope, id, props) | ||
|
||
const defaultVpc = new Vpc(this, 'VPC', { | ||
cidr: '10.0.0.0/16', | ||
maxAzs: 2, | ||
subnetConfiguration: [ | ||
{ | ||
name: 'public', | ||
subnetType: SubnetType.PUBLIC, | ||
cidrMask: 27 | ||
} | ||
] | ||
}) | ||
|
||
const role = new Role( | ||
this, | ||
'ec2-xwiki-demo-instance-role', | ||
{ assumedBy: new ServicePrincipal('ec2.amazonaws.com') } | ||
) | ||
|
||
const securityGroup = new SecurityGroup( | ||
this, | ||
'ec2-xwiki-demo-sg', | ||
{ | ||
vpc: defaultVpc, | ||
allowAllOutbound: true, // will let xwiki instance send outbound traffic | ||
securityGroupName: 'ec2-xwiki-demo-sg' | ||
} | ||
) | ||
|
||
// configuring the security group to allow inbound traffic at specific ports | ||
securityGroup.addIngressRule( | ||
Peer.anyIpv4(), | ||
Port.tcp(22), | ||
'Allows SSH access from Internet' | ||
) | ||
|
||
securityGroup.addIngressRule( | ||
Peer.anyIpv4(), | ||
Port.tcp(80), | ||
'Allows HTTP access from Internet' | ||
) | ||
|
||
securityGroup.addIngressRule( | ||
Peer.anyIpv4(), | ||
Port.tcp(443), | ||
'Allows HTTPS access from Internet' | ||
) | ||
|
||
securityGroup.addIngressRule( | ||
Peer.anyIpv6(), | ||
Port.tcp(8080), | ||
'Allows port 8080 on Ipv6' | ||
) | ||
|
||
securityGroup.addIngressRule( | ||
Peer.anyIpv4(), | ||
Port.tcp(8080), | ||
'Allows port 8080 on Ipv4' | ||
|
||
) | ||
|
||
// provesioning the EC2 instance inside the VPC containg xwiki | ||
const instance = new Instance(this, 'ec2-xwiki-demo', { | ||
vpc: defaultVpc, | ||
role: role, | ||
securityGroup: securityGroup, | ||
instanceName: 'ec2-xwiki-demo', | ||
instanceType: InstanceType.of( // t2.micro has free tier usage in aws | ||
InstanceClass.T2, | ||
InstanceSize.MEDIUM | ||
), | ||
machineImage: MachineImage.latestAmazonLinux({ | ||
generation: AmazonLinuxGeneration.AMAZON_LINUX_2 | ||
}), | ||
|
||
keyName: 'test', // user will first create this key in console | ||
|
||
userData: UserData.forLinux({ | ||
shebang: `#! /bin/bash \n sudo yum -q -y install java-1.8.0-openjdk \n sudo yum -q -y install unzip \n mkdir xwikihome \n wget -q -O xwiki_packer.zip ${props.xwiki} \n unzip -q xwiki_packer.zip -d /home/ec2-user/xwikihome` | ||
}) | ||
|
||
}) | ||
|
||
// const commands = ['sudo yum -q -y install java-1.8.0-openjdk && sudo yum -q -y install unzip && mkdir xwikihome && wget -q -O xwiki_packer.zip https://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/platform/xwiki-platform-distribution-flavor-jetty-hsqldb/13.1/xwiki-platform-distribution-flavor-jetty-hsqldb-13.1.zip && unzip -q xwiki_packer.zip -d /home/ec2-user/xwikihome'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove these lines if they are not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
// // adding the commands that will install xwiki in the instance | ||
// instance.addUserData( | ||
// fs.readFileSync('lib/stacks/user_script.sh', 'utf8') | ||
// ) | ||
|
||
// cdk lets us output prperties of the resources we create after they are created | ||
// we want the ip address of this new instance so we can ssh into it later | ||
new CfnOutput(this, 'xwiki-demo-instance-output', { | ||
value: instance.instancePublicIp | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#! /bin/bash | ||
# become root user | ||
|
||
sudo yum -q -y install java-1.8.0-openjdk | ||
sudo yum -q -y install unzip | ||
mkdir xwikihome | ||
wget -q -O xwiki_packer.zip https://nexus.xwiki.org/nexus/content/groups/public/org/xwiki/platform/xwiki-platform-distribution-flavor-jetty-hsqldb/13.1/xwiki-platform-distribution-flavor-jetty-hsqldb-13.1.zip | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file. |
||
unzip -q xwiki_packer.zip -d /home/ec2-user/xwikihome | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont hard code the region. Get it from some configuration file as discussed