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

XAWS-4: Added CDK code for XWiki demo installation with unit tests. #6

Merged
merged 10 commits into from Jun 28, 2021

Conversation

sanchita141011
Copy link
Contributor

Added CDK code for installing XWiki demo using user-script on EC2 instance of type T2.medium inside public subnet of default VPC of the user's account. Added unit tests using jest test framework.

@sanchita141011 sanchita141011 changed the title Added CDK code for XWiki demo installation with unit tests. XAWS-4: Added CDK code for XWiki demo installation with unit tests. Jun 20, 2021
Copy link
Member

@9inpachi 9inpachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sanchita141011,

The code styling seems a bit inconsistent, could you maybe set up prettier and ideally eslint as well? It would make it easier to maintain code checking and styling for the future. ;)

@sanchita141011
Copy link
Contributor Author

Hi @sanchita141011,

The code styling seems a bit inconsistent, could you maybe set up prettier and ideally eslint as well? It would make it easier to maintain code checking and styling for the future. ;)

Thankyou for suggestion. :)

Copy link
Member

@9inpachi 9inpachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (TypeScript-wise — I don't know much about CDK). ;)
Thanks for the changes.

Copy link
Contributor

@sachin10101998 sachin10101998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add better tests. Remove import * statements. Add entry point file to this cdk app. Currently, there's only single stack with no entry point for this application. This code won't work.

* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
import * as cdk from '@aws-cdk/core'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all * imports. Import only the modules you want in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
import * as cdk from '@aws-cdk/core'
import * as ec2 from '@aws-cdk/aws-ec2'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all * imports. Import only the modules you want in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

*/
import * as cdk from '@aws-cdk/core'
import * as ec2 from '@aws-cdk/aws-ec2'
import * as iam from '@aws-cdk/aws-iam'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all * imports. Import only the modules you want in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

import * as fs from 'fs'

export class EC2XwikiDemo extends cdk.Stack {
constructor (scope: cdk.Construct, id: string, props?: cdk.StackProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope here should be cdp.App and not cdk.Construct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected :)

constructor (scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)

const defaultVpc = ec2.Vpc.fromLookup(this, 'VPC', { isDefault: true })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hard code VPC. In case default vpc is not present , then the code will fail. Take it from the consumer. Give him the flexibility to choose default vpc or create a new one or pass any other vpc. Manage it in entry point of the cdk application.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the VPC from default to new VPC.

import * as cdk from '@aws-cdk/core';
import * as XwikiDemoCdk from '../lib/xwiki-demo-cdk-stack';
import { expect as expectCDK, haveResourceLike, countResources } from '@aws-cdk/assert'
import * as cdk from '@aws-cdk/core'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont use import * statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// expect(stack).toBe(countResources("AWS::EC2::Instance", 1));
// THEN
expectCDK(stack).to(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add snapshot tests for CDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added snapshot test

// THEN
expectCDK(stack).to(
countResources('AWS::EC2::Instance', 1))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dd more granular tests. Just testing the presence of ec2 instance is not gonna make it. Check for other resources you created via CDK too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit test to check EC2 instance, VPC, IAM Role, Security Group and to check if EC2 instance is launched inside a subnet with public IPv4. Please check and suggest changes If required

Copy link
Contributor

@sachin10101998 sachin10101998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more granular tests is possible.

new EC2XwikiDemo(app, 'ec2XwikiDemo', {
xwiki: xwikidownload,
env: {
region: 'eu-central-1'
Copy link
Contributor

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

@@ -0,0 +1,7 @@
import { StackProps } from '@aws-cdk/core'

export interface ec2props extends StackProps{
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Please suggest the changes if required


})

// 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']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these lines if they are not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file.

@sachin10101998 sachin10101998 merged commit 041af2d into xwiki-contrib:master Jun 28, 2021
@sachin10101998
Copy link
Contributor

Good work on the PR. Hope to get the Production PR merged too soon after it's completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants