diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy new file mode 100644 index 0000000..9d6f3bd --- /dev/null +++ b/Jenkinsfile.groovy @@ -0,0 +1,55 @@ +import groovy.json.JsonSlurperClassic + + +node { + env.AWS_DEFAULT_REGION = 'ap-southeast-1' + + def applicationName = 'amelia-app' //change me + def deploymentGroupName = 'amelia-app-group' // change me + def s3BucketName = 'deployment-cdc' + + //Cleanup workspace + deleteDir() + + stage('Checkout') { + checkout scm + } + + + stage("Sonar Analyze") { + def scannerHome = tool 'default'; + withSonarQubeEnv('default') { + sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=${deploymentGroupName} -Dsonar.sources=app" + } + } + + + stage('Deploy') { + withCredentials([[$class : 'UsernamePasswordMultiBinding', + credentialsId : 'CdcAWS', + usernameVariable: 'AWS_ACCESS_KEY_ID', + passwordVariable: 'AWS_SECRET_ACCESS_KEY']]) { + + + + //Zip artifact + def artifactName = "${applicationName}-${deploymentGroupName}" + sh("zip -r ${artifactName}.zip .") + + //Upload artifact to S3 + sh("aws s3 cp ${artifactName}.zip s3://${s3BucketName}/${artifactName}.zip") + + //Create Deployment + def result = sh(returnStdout:true, script: "aws deploy create-deployment --application-name ${applicationName} --deployment-group-name ${deploymentGroupName} --s3-location bucket=${s3BucketName},bundleType=zip,key=${artifactName}.zip") + def json = parseJson(result) + String deploymentId = json.deploymentId + + //Wait until success + sh("aws deploy wait deployment-successful --deployment-id ${deploymentId}") + } + } +} + +def parseJson(String json) { + return new JsonSlurperClassic().parseText(json) +} diff --git a/README.md b/README.md index 2ea2724..969dfb1 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# sample-html \ No newline at end of file +# sample-html +dasfdasf \ No newline at end of file diff --git a/LICENSE b/app/LICENSE similarity index 100% rename from LICENSE rename to app/LICENSE diff --git a/app/README.md b/app/README.md new file mode 100644 index 0000000..39d0cb7 --- /dev/null +++ b/app/README.md @@ -0,0 +1,3 @@ +# sample-html +edited by erwin_h +edit lagi ah \ No newline at end of file diff --git a/css/main.css b/app/css/main.css similarity index 100% rename from css/main.css rename to app/css/main.css diff --git a/index.html b/app/index.html similarity index 100% rename from index.html rename to app/index.html diff --git a/js/main.js b/app/js/main.js similarity index 100% rename from js/main.js rename to app/js/main.js diff --git a/sonar-project.properties b/app/sonar-project.properties similarity index 73% rename from sonar-project.properties rename to app/sonar-project.properties index 778a5a6..bc33c05 100644 --- a/sonar-project.properties +++ b/app/sonar-project.properties @@ -2,3 +2,4 @@ sonar.projectKey=sample-html sonar.projectName=Sample HTML sonar.sources=. sonar.sourceEncoding=UTF-8 +sonar.host.url=http://127.0.0.1:8081 diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..bcb1918 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,10 @@ +version: 0.0 +os: linux +files: + - source: /app + destination: /opt/bitnami/apache2/htdocs/app +hooks: + ApplicationStart: + - location: start_service + timeout: 300 + runas: root diff --git a/start_service b/start_service new file mode 100644 index 0000000..8860925 --- /dev/null +++ b/start_service @@ -0,0 +1 @@ +/opt/bitnami/ctlscript.sh restart apache