From 12ae8360b2cbafc4cae412f7b0ffbdc582fb46b7 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sat, 10 Oct 2020 14:24:31 -0400 Subject: [PATCH 01/39] added packaging script --- package-with-mvn-wrapper.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 package-with-mvn-wrapper.sh diff --git a/package-with-mvn-wrapper.sh b/package-with-mvn-wrapper.sh new file mode 100644 index 000000000..4ce8371c2 --- /dev/null +++ b/package-with-mvn-wrapper.sh @@ -0,0 +1,2 @@ +# package-with-mvn-wrapper +./mvnw clean package \ No newline at end of file From faf01a5f7f056f308885008d4ee2f08e044bdc1b Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sat, 10 Oct 2020 15:58:48 -0400 Subject: [PATCH 02/39] added Dockerfiles for microservices --- spring-petclinic-admin-server/Dockerfile | 10 ++++++++++ spring-petclinic-api-gateway/Dockerfile | 10 ++++++++++ spring-petclinic-config-server/Dockerfile | 10 ++++++++++ spring-petclinic-customers-service/Dockerfile | 10 ++++++++++ spring-petclinic-discovery-server/Dockerfile | 10 ++++++++++ spring-petclinic-hystrix-dashboard/Dockerfile | 10 ++++++++++ spring-petclinic-vets-service/Dockerfile | 10 ++++++++++ spring-petclinic-visits-service/Dockerfile | 10 ++++++++++ 8 files changed, 80 insertions(+) create mode 100644 spring-petclinic-admin-server/Dockerfile create mode 100644 spring-petclinic-api-gateway/Dockerfile create mode 100644 spring-petclinic-config-server/Dockerfile create mode 100644 spring-petclinic-customers-service/Dockerfile create mode 100644 spring-petclinic-discovery-server/Dockerfile create mode 100644 spring-petclinic-hystrix-dashboard/Dockerfile create mode 100644 spring-petclinic-vets-service/Dockerfile create mode 100644 spring-petclinic-visits-service/Dockerfile diff --git a/spring-petclinic-admin-server/Dockerfile b/spring-petclinic-admin-server/Dockerfile new file mode 100644 index 000000000..1accabb18 --- /dev/null +++ b/spring-petclinic-admin-server/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=9090 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] diff --git a/spring-petclinic-api-gateway/Dockerfile b/spring-petclinic-api-gateway/Dockerfile new file mode 100644 index 000000000..8ecdaf7c3 --- /dev/null +++ b/spring-petclinic-api-gateway/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=8888 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] \ No newline at end of file diff --git a/spring-petclinic-config-server/Dockerfile b/spring-petclinic-config-server/Dockerfile new file mode 100644 index 000000000..8ecdaf7c3 --- /dev/null +++ b/spring-petclinic-config-server/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=8888 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] \ No newline at end of file diff --git a/spring-petclinic-customers-service/Dockerfile b/spring-petclinic-customers-service/Dockerfile new file mode 100644 index 000000000..269e87bab --- /dev/null +++ b/spring-petclinic-customers-service/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=8081 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] \ No newline at end of file diff --git a/spring-petclinic-discovery-server/Dockerfile b/spring-petclinic-discovery-server/Dockerfile new file mode 100644 index 000000000..1ff14cccb --- /dev/null +++ b/spring-petclinic-discovery-server/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=8761 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] \ No newline at end of file diff --git a/spring-petclinic-hystrix-dashboard/Dockerfile b/spring-petclinic-hystrix-dashboard/Dockerfile new file mode 100644 index 000000000..9610e433e --- /dev/null +++ b/spring-petclinic-hystrix-dashboard/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=7979 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] \ No newline at end of file diff --git a/spring-petclinic-vets-service/Dockerfile b/spring-petclinic-vets-service/Dockerfile new file mode 100644 index 000000000..046d51b36 --- /dev/null +++ b/spring-petclinic-vets-service/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=8083 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] \ No newline at end of file diff --git a/spring-petclinic-visits-service/Dockerfile b/spring-petclinic-visits-service/Dockerfile new file mode 100644 index 000000000..6b578ff12 --- /dev/null +++ b/spring-petclinic-visits-service/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:11-jre +ARG DOCKERIZE_VERSION=v0.6.1 +ARG EXPOSED_PORT=8082 +ENV SPRING_PROFILES_ACTIVE docker +ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz +RUN tar xzf dockerize.tar.gz +RUN chmod +x dockerize +ADD ./target/*.jar /app.jar +EXPOSE ${EXPOSED_PORT} +ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar" ] \ No newline at end of file From cb148ad71a4661d8d01a9d901297fd5fcce51443 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 11 Oct 2020 14:13:22 -0400 Subject: [PATCH 03/39] added script for building docker images --- build-dev-docker-images.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 build-dev-docker-images.sh diff --git a/build-dev-docker-images.sh b/build-dev-docker-images.sh new file mode 100644 index 000000000..26a097a55 --- /dev/null +++ b/build-dev-docker-images.sh @@ -0,0 +1,14 @@ +#build-dev-docker-images +./mvnw clean package +docker build --force-rm -t "petclinic-admin-server:dev" ./spring-petclinic-admin-server +docker build --force-rm -t "petclinic-api-gateway:dev" ./spring-petclinic-api-gateway +docker build --force-rm -t "petclinic-config-server:dev" ./spring-petclinic-config-server +docker build --force-rm -t "petclinic-customer-service:dev" ./spring-petclinic-customer-service +docker build --force-rm -t "petclinic-discovery-server:dev" ./spring-petclinic-discovery-server +docker build --force-rm -t "petclinic-hystrix-dashboard:dev" ./spring-petclinic-hystrix-dashboard +docker build --force-rm -t "petclinic-vets-service:dev" ./spring-petclinic-vets-service +docker build --force-rm -t "petclinic-visits-service:dev" ./spring-petclinic-visits-service +docker build --force-rm -t "petclinic-prometheus-server:dev" ./docker/prometheus +docker build --force-rm -t "petclinic-grafana-server:dev" ./docker/grafana + + From b5059b377caf4dfcc1b1bf4e70ee1c950c62a842 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 11 Oct 2020 14:26:53 -0400 Subject: [PATCH 04/39] v2 --- build-dev-docker-images.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-dev-docker-images.sh b/build-dev-docker-images.sh index 26a097a55..88ce7fba1 100644 --- a/build-dev-docker-images.sh +++ b/build-dev-docker-images.sh @@ -3,7 +3,7 @@ docker build --force-rm -t "petclinic-admin-server:dev" ./spring-petclinic-admin-server docker build --force-rm -t "petclinic-api-gateway:dev" ./spring-petclinic-api-gateway docker build --force-rm -t "petclinic-config-server:dev" ./spring-petclinic-config-server -docker build --force-rm -t "petclinic-customer-service:dev" ./spring-petclinic-customer-service +docker build --force-rm -t "petclinic-customers-service:dev" ./spring-petclinic-customers-service docker build --force-rm -t "petclinic-discovery-server:dev" ./spring-petclinic-discovery-server docker build --force-rm -t "petclinic-hystrix-dashboard:dev" ./spring-petclinic-hystrix-dashboard docker build --force-rm -t "petclinic-vets-service:dev" ./spring-petclinic-vets-service From a12072f697207470187230723544b6188388e03d Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 11 Oct 2020 15:33:32 -0400 Subject: [PATCH 05/39] added docker compose file and script for local deployment --- docker-compose-local.yml | 97 ++++++++++++++++++++++++++++++++++++++++ test-local-deployment.sh | 2 + 2 files changed, 99 insertions(+) create mode 100644 docker-compose-local.yml create mode 100644 test-local-deployment.sh diff --git a/docker-compose-local.yml b/docker-compose-local.yml new file mode 100644 index 000000000..195b20637 --- /dev/null +++ b/docker-compose-local.yml @@ -0,0 +1,97 @@ +version: '2' +services: + config-server: + image: petclinic-config-server:dev + container_name: config-server + mem_limit: 512M + ports: + - 8888:8888 + discovery-server: + image: petclinic-discovery-server:dev + container_name: discovery-server + mem_limit: 512M + ports: + - 8761:8761 + depends_on: + - config-server + entrypoint: ["./dockerize", "-wait=tcp://config-server:8888", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + customers-service: + image: petclinic-customers-service:dev + container_name: customers-service + mem_limit: 512M + ports: + - 8081:8081 + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + visits-service: + image: petclinic-visits-service:dev + container_name: visits-service + mem_limit: 512M + ports: + - 8082:8082 + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + vets-service: + image: petclinic-vets-service:dev + container_name: vets-service + mem_limit: 512M + ports: + - 8083:8083 + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + api-gateway: + image: petclinic-api-gateway:dev + container_name: api-gateway + mem_limit: 512M + ports: + - 8080:8080 + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + admin-server: + image: petclinic-admin-server:dev + container_name: admin-server + mem_limit: 512M + ports: + - 9090:9090 + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + hystrix-dashboard: + image: petclinic-hystrix-dashboard:dev + container_name: hystrix-dashboard + mem_limit: 512M + ports: + - 7979:7979 + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + tracing-server: + image: openzipkin/zipkin + container_name: tracing-server + mem_limit: 512M + environment: + - JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -Djava.security.egd=file:/dev/./urandom + ports: + - 9411:9411 + grafana-server: + image: petclinic-grafana-server:dev + container_name: grafana-server + mem_limit: 256M + ports: + - 3000:3000 + prometheus-server: + image: petclinic-prometheus-server:dev + container_name: prometheus-server + mem_limit: 256M + ports: + - 9091:9090 \ No newline at end of file diff --git a/test-local-deployment.sh b/test-local-deployment.sh new file mode 100644 index 000000000..2698f346a --- /dev/null +++ b/test-local-deployment.sh @@ -0,0 +1,2 @@ +#test local deployment +docker-compose -f docker-compose-local.yml up \ No newline at end of file From c03f7d979545f749d2a61769324b139d934e4126 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 11 Oct 2020 17:26:33 -0400 Subject: [PATCH 06/39] changed dockerfile --- spring-petclinic-api-gateway/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-petclinic-api-gateway/Dockerfile b/spring-petclinic-api-gateway/Dockerfile index 8ecdaf7c3..eda2a5f0e 100644 --- a/spring-petclinic-api-gateway/Dockerfile +++ b/spring-petclinic-api-gateway/Dockerfile @@ -1,6 +1,6 @@ FROM openjdk:11-jre ARG DOCKERIZE_VERSION=v0.6.1 -ARG EXPOSED_PORT=8888 +ARG EXPOSED_PORT=8080 ENV SPRING_PROFILES_ACTIVE docker ADD https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-alpine-linux-amd64-${DOCKERIZE_VERSION}.tar.gz dockerize.tar.gz RUN tar xzf dockerize.tar.gz From da5330f8b582aed198a467dff23add39ea75bc95 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 13 Oct 2020 19:33:42 -0400 Subject: [PATCH 07/39] added cloudformation template --- infrastructure/dev-server-for-petclinic-app-cfn-template.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 infrastructure/dev-server-for-petclinic-app-cfn-template.yml diff --git a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml new file mode 100644 index 000000000..e69de29bb From 903262c71b07d1965c5a676fd095af9b2c01adf0 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 13 Oct 2020 19:36:22 -0400 Subject: [PATCH 08/39] added cloudformation template for dev server --- ...-server-for-petclinic-app-cfn-template.yml | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 infrastructure/dev-server-for-petclinic-app-cfn-template.yml diff --git a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml new file mode 100644 index 000000000..c4d00cdb6 --- /dev/null +++ b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml @@ -0,0 +1,117 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: > + This Cloudformation template prepares development environment for + Petclinic Microservices Application. + User needs to select appropriate key name when launching the template. +Parameters: + KeyPairName: + Description: Enter the name of your Key Pair for SSH connections. + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: Must one of the existing EC2 KeyPair +Resources: + PetclinicDemoSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH and HTTP for Petclinic Microservices + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 80 + ToPort: 80 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 9090 + ToPort: 9090 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8081 + ToPort: 8081 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8082 + ToPort: 8082 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8083 + ToPort: 8083 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8888 + ToPort: 8888 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 9411 + ToPort: 9411 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 7979 + ToPort: 7979 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 3000 + ToPort: 3000 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 9091 + ToPort: 9091 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8761 + ToPort: 8761 + CidrIp: 0.0.0.0/0 + PetclinicServerLT: + Type: "AWS::EC2::LaunchTemplate" + Properties: + LaunchTemplateData: + ImageId: ami-038b5c5d2ad6a5090 + InstanceType: t2.medium + KeyName: !Ref KeyPairName + SecurityGroupIds: + - !GetAtt PetclinicDemoSG.GroupId + UserData: + Fn::Base64: | + #! /bin/bash + # update os + sudo yum update -y + # set hostname as petclinic-dev-server + sudo hostnamectl set-hostname petclinic-dev-server + # install docker + sudo amazon-linux-extras install docker -y + sudo systemctl start docker + sudo systemctl enable docker + sudo usermod -a -G docker ec2-user + # install docker compose + sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + # install JDK 11 + sudo yum install java-11-amazon-corretto -y + # install Git + sudo yum install git -y + cd /home/ec2-user + git clone https://github.com/callahan-cw/microservices-ci-cd-pipeline-with-petclinic-app.git + git fetch + git checkout dev + git clone https://github.com/vildan71/microservices-ci-cd-pipeline-with-petclinic-app.git + git fetch + git checkout dev + PetclinicServer: + Type: AWS::EC2::Instance + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref PetclinicServerLT + Version: !GetAtt PetclinicServerLT.LatestVersionNumber + Tags: + - Key: Name + Value: !Sub Petclinic App Dev Server of ${AWS::StackName} +Outputs: + PetclinicServerDNSName: + Description: Petclinic App URL + Value: !GetAtt PetclinicServer.PublicDnsName + \ No newline at end of file From 4b49c9f5197ee365df10921ee70ed8c78709e1bf Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 13 Oct 2020 19:44:09 -0400 Subject: [PATCH 09/39] added cloudformation template for dev server --- ...-server-for-petclinic-app-cfn-template.yml | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml index e69de29bb..59e98971a 100644 --- a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml +++ b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml @@ -0,0 +1,117 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: > + This Cloudformation template prepares development environment for + Petclinic Microservices Application. + User needs to select appropriate key name when launching the template. +Parameters: + KeyPairName: + Description: Enter the name of your Key Pair for SSH connections. + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: Must one of the existing EC2 KeyPair +Resources: + PetclinicDemoSG: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH and HTTP for Petclinic Microservices + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 80 + ToPort: 80 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 9090 + ToPort: 9090 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8081 + ToPort: 8081 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8082 + ToPort: 8082 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8083 + ToPort: 8083 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8888 + ToPort: 8888 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 9411 + ToPort: 9411 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 7979 + ToPort: 7979 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 3000 + ToPort: 3000 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 9091 + ToPort: 9091 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8761 + ToPort: 8761 + CidrIp: 0.0.0.0/0 + PetclinicServerLT: + Type: "AWS::EC2::LaunchTemplate" + Properties: + LaunchTemplateData: + ImageId: ami-0947d2ba12ee1ff75 + InstanceType: t2.medium + KeyName: !Ref KeyPairName + SecurityGroupIds: + - !GetAtt PetclinicDemoSG.GroupId + UserData: + Fn::Base64: | + #! /bin/bash + # update os + sudo yum update -y + # set hostname as petclinic-dev-server + sudo hostnamectl set-hostname petclinic-dev-server + # install docker + sudo amazon-linux-extras install docker -y + sudo systemctl start docker + sudo systemctl enable docker + sudo usermod -a -G docker ec2-user + # install docker compose + sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + # install JDK 11 + sudo yum install java-11-amazon-corretto -y + # install Git + sudo yum install git -y + cd /home/ec2-user + git clone https://github.com/callahan-cw/microservices-ci-cd-pipeline-with-petclinic-app.git + git fetch + git checkout dev + git clone https://github.com/vildan71/microservices-ci-cd-pipeline-with-petclinic-app.git + git fetch + git checkout dev + PetclinicServer: + Type: AWS::EC2::Instance + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref PetclinicServerLT + Version: !GetAtt PetclinicServerLT.LatestVersionNumber + Tags: + - Key: Name + Value: !Sub Petclinic App Dev Server of ${AWS::StackName} +Outputs: + PetclinicServerDNSName: + Description: Petclinic App URL + Value: !GetAtt PetclinicServer.PublicDnsName + \ No newline at end of file From 9c80c733837d5e29d10257807b1a63ad6136e5ea Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 13 Oct 2020 20:49:43 -0400 Subject: [PATCH 10/39] added 3 UTs for customer-service --- .../petclinic/customers/web/PetTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java diff --git a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java new file mode 100644 index 000000000..17d65da32 --- /dev/null +++ b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java @@ -0,0 +1,35 @@ +package org.springframework.samples.petclinic.customers.model; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +public class PetTest { + @Test + public void testGetName(){ + //Arrange + Pet pet = new Pet(); + //Act + pet.setName("Fluffy"); + //Assert + assertEquals("Fluffy", pet.getName()); + } + @Test + public void testGetOwner(){ + //Arrange + Pet pet = new Pet(); + Owner owner = new Owner(); + owner.setFirstName("Call"); + //Act + pet.setOwner(owner); + //Assert + assertEquals("Call", pet.getOwner().getFirstName()); + } + @Test + public void testBirthDate(){ + //Arrange + Pet pet = new Pet(); + Date bd = new Date(); + //Act + pet.setBirthDate(bd); + //Assert + assertEquals(bd,pet.getBirthDate()); + } +} \ No newline at end of file From d57ed90a82cff51c2313750189e36736f9880864 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 13 Oct 2020 21:19:14 -0400 Subject: [PATCH 11/39] updated POM with Jacoco plugin --- pom.xml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pom.xml b/pom.xml index da42b9ce9..eb949e0a5 100644 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,26 @@ false + + org.jacoco + jacoco-maven-plugin + 0.8.2 + + + + prepare-agent + + + + + report + test + + report + + + + From c11e6dc59a215c4f41abab57ea61db070261a009 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 13 Oct 2020 21:47:43 -0400 Subject: [PATCH 12/39] update pettest.java file --- .../samples/petclinic/customers/web/PetTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java index 17d65da32..a180f5a2d 100644 --- a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java +++ b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java @@ -1,5 +1,6 @@ package org.springframework.samples.petclinic.customers.model; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Date; import org.junit.jupiter.api.Test; public class PetTest { @Test @@ -16,7 +17,7 @@ public void testGetOwner(){ //Arrange Pet pet = new Pet(); Owner owner = new Owner(); - owner.setFirstName("Call"); + owner.setFirstName("Call2"); //Act pet.setOwner(owner); //Assert From 290e007bce6fb0faae3c9c9b21cafba5e4d1314f Mon Sep 17 00:00:00 2001 From: vildan71 Date: Wed, 14 Oct 2020 15:49:45 -0400 Subject: [PATCH 13/39] updated dev-server-for-petclinic-app-cfn-template.yml --- .../dev-server-for-petclinic-app-cfn-template.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml index 8886be501..07424b093 100644 --- a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml +++ b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml @@ -70,11 +70,7 @@ Resources: Type: "AWS::EC2::LaunchTemplate" Properties: LaunchTemplateData: -<<<<<<< HEAD - ImageId: ami-038b5c5d2ad6a5090 -======= ImageId: ami-0947d2ba12ee1ff75 ->>>>>>> feature/msp-5 InstanceType: t2.medium KeyName: !Ref KeyPairName SecurityGroupIds: @@ -99,9 +95,6 @@ Resources: # install Git sudo yum install git -y cd /home/ec2-user - git clone https://github.com/callahan-cw/microservices-ci-cd-pipeline-with-petclinic-app.git - git fetch - git checkout dev git clone https://github.com/vildan71/microservices-ci-cd-pipeline-with-petclinic-app.git git fetch git checkout dev From 6bf2886e6c749c72a0377c24a3221cfa8cbba6ba Mon Sep 17 00:00:00 2001 From: vildan71 Date: Wed, 14 Oct 2020 18:33:37 -0400 Subject: [PATCH 14/39] updated PetTest.java --- .../samples/petclinic/customers/{web => model}/PetTest.java | 4 ++++ 1 file changed, 4 insertions(+) rename spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/{web => model}/PetTest.java (97%) diff --git a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java similarity index 97% rename from spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java rename to spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java index 17d65da32..a353c89c0 100644 --- a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java +++ b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java @@ -1,5 +1,9 @@ package org.springframework.samples.petclinic.customers.model; + import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Date; + import org.junit.jupiter.api.Test; public class PetTest { @Test From f1facd5ae3bf346440c0f3b4c3d0f9a839f7d5f7 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Wed, 14 Oct 2020 19:03:44 -0400 Subject: [PATCH 15/39] updated POM with Jacoco plugin --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index eb949e0a5..d83bd47b1 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ - + @@ -204,4 +204,4 @@ - + \ No newline at end of file From 546d7de98b2755bf5f15a9868332f8362df69b61 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Wed, 14 Oct 2020 19:14:21 -0400 Subject: [PATCH 16/39] updated POM with Jacoco plugin --- pom.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pom.xml b/pom.xml index 5a930cfa7..d83bd47b1 100644 --- a/pom.xml +++ b/pom.xml @@ -156,6 +156,21 @@ buildDocker + + + + + com.spotify + docker-maven-plugin + ${docker.plugin.version} + + + install + + build + + + ${docker.image.prefix}/${project.artifactId} ${docker.image.dockerfile.dir} From f9216d20ba4a7880c16e3a8ce3454cadf72ea3ed Mon Sep 17 00:00:00 2001 From: vildan71 Date: Wed, 14 Oct 2020 23:08:21 -0400 Subject: [PATCH 17/39] updated build-dev-docker-images.sh and docker-compose-local.yml files --- build-dev-docker-images.sh | 6 ++---- docker-compose-local.yml | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/build-dev-docker-images.sh b/build-dev-docker-images.sh index 88ce7fba1..1c5441a21 100644 --- a/build-dev-docker-images.sh +++ b/build-dev-docker-images.sh @@ -1,4 +1,4 @@ -#build-dev-docker-images +# build-dev-docker-images ./mvnw clean package docker build --force-rm -t "petclinic-admin-server:dev" ./spring-petclinic-admin-server docker build --force-rm -t "petclinic-api-gateway:dev" ./spring-petclinic-api-gateway @@ -9,6 +9,4 @@ docker build --force-rm -t "petclinic-hystrix-dashboard:dev" ./spring-petclinic- docker build --force-rm -t "petclinic-vets-service:dev" ./spring-petclinic-vets-service docker build --force-rm -t "petclinic-visits-service:dev" ./spring-petclinic-visits-service docker build --force-rm -t "petclinic-prometheus-server:dev" ./docker/prometheus -docker build --force-rm -t "petclinic-grafana-server:dev" ./docker/grafana - - +docker build --force-rm -t "petclinic-grafana-server:dev" ./docker/grafana \ No newline at end of file diff --git a/docker-compose-local.yml b/docker-compose-local.yml index 195b20637..93bd22768 100644 --- a/docker-compose-local.yml +++ b/docker-compose-local.yml @@ -1,4 +1,5 @@ version: '2' + services: config-server: image: petclinic-config-server:dev @@ -6,6 +7,7 @@ services: mem_limit: 512M ports: - 8888:8888 + discovery-server: image: petclinic-discovery-server:dev container_name: discovery-server @@ -15,6 +17,7 @@ services: depends_on: - config-server entrypoint: ["./dockerize", "-wait=tcp://config-server:8888", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + customers-service: image: petclinic-customers-service:dev container_name: customers-service @@ -25,6 +28,7 @@ services: - config-server - discovery-server entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + visits-service: image: petclinic-visits-service:dev container_name: visits-service @@ -35,6 +39,7 @@ services: - config-server - discovery-server entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + vets-service: image: petclinic-vets-service:dev container_name: vets-service @@ -45,6 +50,7 @@ services: - config-server - discovery-server entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + api-gateway: image: petclinic-api-gateway:dev container_name: api-gateway @@ -55,6 +61,7 @@ services: - config-server - discovery-server entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + admin-server: image: petclinic-admin-server:dev container_name: admin-server @@ -65,6 +72,7 @@ services: - config-server - discovery-server entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + hystrix-dashboard: image: petclinic-hystrix-dashboard:dev container_name: hystrix-dashboard @@ -75,6 +83,7 @@ services: - config-server - discovery-server entrypoint: ["./dockerize", "-wait=tcp://discovery-server:8761", "-timeout=60s", "--", "java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar" ] + tracing-server: image: openzipkin/zipkin container_name: tracing-server @@ -83,12 +92,14 @@ services: - JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -Djava.security.egd=file:/dev/./urandom ports: - 9411:9411 + grafana-server: image: petclinic-grafana-server:dev container_name: grafana-server mem_limit: 256M ports: - 3000:3000 + prometheus-server: image: petclinic-prometheus-server:dev container_name: prometheus-server From 43e8a1fa6592d0ed7b7d0420b86ff1d717e4dc58 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Wed, 14 Oct 2020 23:30:53 -0400 Subject: [PATCH 18/39] reupload PetTest.java file --- .../petclinic/customers/model/PetTest.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java index 782366e89..4e639f07c 100644 --- a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java +++ b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java @@ -1,15 +1,11 @@ package org.springframework.samples.petclinic.customers.model; - +​ import static org.junit.jupiter.api.Assertions.assertEquals; -<<<<<<< HEAD:spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/web/PetTest.java -import java.util.Date; -======= - -import java.util.Date; - ->>>>>>> feature/msp-9:spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java +​ import org.junit.jupiter.api.Test; +​ public class PetTest { +​ @Test public void testGetName(){ //Arrange @@ -19,17 +15,19 @@ public void testGetName(){ //Assert assertEquals("Fluffy", pet.getName()); } +​ @Test public void testGetOwner(){ //Arrange Pet pet = new Pet(); Owner owner = new Owner(); - owner.setFirstName("Call2"); + owner.setFirstName("Call"); //Act pet.setOwner(owner); //Assert assertEquals("Call", pet.getOwner().getFirstName()); } + @Test public void testBirthDate(){ //Arrange From 265043572b0d8ded350eea42292353fa32e66772 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Thu, 15 Oct 2020 10:35:20 -0400 Subject: [PATCH 19/39] pettest.java --- .../samples/petclinic/customers/model/PetTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java index 4e639f07c..05cff1759 100644 --- a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java +++ b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java @@ -2,10 +2,10 @@ ​ import static org.junit.jupiter.api.Assertions.assertEquals; ​ -import org.junit.jupiter.api.Test; +import java.util.Date; ​ +import org.junit.jupiter.api.Test; public class PetTest { -​ @Test public void testGetName(){ //Arrange @@ -15,7 +15,6 @@ public void testGetName(){ //Assert assertEquals("Fluffy", pet.getName()); } -​ @Test public void testGetOwner(){ //Arrange @@ -27,7 +26,6 @@ public void testGetOwner(){ //Assert assertEquals("Call", pet.getOwner().getFirstName()); } - @Test public void testBirthDate(){ //Arrange From b2c33b57d968ffe5f6bf84ef4cea565d2cc6ba6a Mon Sep 17 00:00:00 2001 From: vildan71 Date: Thu, 15 Oct 2020 10:51:10 -0400 Subject: [PATCH 20/39] pettest.java --- .../samples/petclinic/customers/model/PetTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java index 05cff1759..2a6380fbc 100644 --- a/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java +++ b/spring-petclinic-customers-service/src/test/java/org/springframework/samples/petclinic/customers/model/PetTest.java @@ -1,9 +1,9 @@ package org.springframework.samples.petclinic.customers.model; -​ + import static org.junit.jupiter.api.Assertions.assertEquals; -​ + import java.util.Date; -​ + import org.junit.jupiter.api.Test; public class PetTest { @Test @@ -36,4 +36,4 @@ public void testBirthDate(){ //Assert assertEquals(bd,pet.getBirthDate()); } -} \ No newline at end of file +} From 4c015ac1d4a33512f76a00a8f727098b5f195b98 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Thu, 15 Oct 2020 19:18:04 -0400 Subject: [PATCH 21/39] updated dev-server cfn template --- ...-server-for-petclinic-app-cfn-template.yml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml index 07424b093..f1a8f3460 100644 --- a/infrastructure/dev-server-for-petclinic-app-cfn-template.yml +++ b/infrastructure/dev-server-for-petclinic-app-cfn-template.yml @@ -79,21 +79,21 @@ Resources: Fn::Base64: | #! /bin/bash # update os - sudo yum update -y + yum update -y # set hostname as petclinic-dev-server - sudo hostnamectl set-hostname petclinic-dev-server + hostnamectl set-hostname petclinic-dev-server # install docker - sudo amazon-linux-extras install docker -y - sudo systemctl start docker - sudo systemctl enable docker - sudo usermod -a -G docker ec2-user + amazon-linux-extras install docker -y + systemctl start docker + systemctl enable docker + usermod -a -G docker ec2-user # install docker compose - sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose + curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose # install JDK 11 - sudo yum install java-11-amazon-corretto -y + yum install java-11-amazon-corretto -y # install Git - sudo yum install git -y + yum install git -y cd /home/ec2-user git clone https://github.com/vildan71/microservices-ci-cd-pipeline-with-petclinic-app.git git fetch From cd5f7ed1f884b2f06872e2ba366ac048b5113243 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Thu, 15 Oct 2020 19:39:13 -0400 Subject: [PATCH 22/39] added selenium jobs written in python --- selenium-jobs/test_owners_all_headless.py | 22 ++++++++++ .../test_owners_register_headless.py | 41 +++++++++++++++++++ selenium-jobs/test_veterinarians_headless.py | 39 ++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 selenium-jobs/test_owners_all_headless.py create mode 100644 selenium-jobs/test_owners_register_headless.py create mode 100644 selenium-jobs/test_veterinarians_headless.py diff --git a/selenium-jobs/test_owners_all_headless.py b/selenium-jobs/test_owners_all_headless.py new file mode 100644 index 000000000..4db808e66 --- /dev/null +++ b/selenium-jobs/test_owners_all_headless.py @@ -0,0 +1,22 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from time import sleep +# Set chrome options for working with headless mode (no screen) +chrome_options = webdriver.ChromeOptions() +chrome_options.add_argument("headless") +# Update webdriver instance of chrome-driver with adding chrome options +driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) +# Connect to the application +url = "ec2-18-232-125-248.compute-1.amazonaws.com:8080" +driver.get(url) +owners_link = driver.find_element_by_link_text("OWNERS") +owners_link.click() +all_link = driver.find_element_by_link_text("ALL") +all_link.click() +# Verify that table loaded +sleep(1) +verify_table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "table"))) +print("Table loaded") +driver.quit() \ No newline at end of file diff --git a/selenium-jobs/test_owners_register_headless.py b/selenium-jobs/test_owners_register_headless.py new file mode 100644 index 000000000..11c697827 --- /dev/null +++ b/selenium-jobs/test_owners_register_headless.py @@ -0,0 +1,41 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import random +# Set chrome options for working with headless mode (no screen) +chrome_options = webdriver.ChromeOptions() +chrome_options.add_argument("headless") +# Update webdriver instance of chrome-driver with adding chrome options +driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) +# Connect to the application +url = "ec2-18-232-125-248.compute-1.amazonaws.com:8080" +driver.get(url) +owners_link = driver.find_element_by_link_text("OWNERS") +owners_link.click() +all_link = driver.find_element_by_link_text("REGISTER") +all_link.click() +# Register new Owner to Petclinic App +fn_field = driver.find_element_by_name('firstName') +fn = 'Callahan' + str(random.randint(0, 100)) +fn_field.send_keys(fn) +fn_field = driver.find_element_by_name('lastName') +fn_field.send_keys('Clarusway') +fn_field = driver.find_element_by_name('address') +fn_field.send_keys('Ridge Corp. Street') +fn_field = driver.find_element_by_name('city') +fn_field.send_keys('McLean') +fn_field = driver.find_element_by_name('telephone') +fn_field.send_keys('+1230576803') +fn_field.send_keys(Keys.ENTER) +# Wait until Owner List table loaded +verify_table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "table"))) +# Verify that new user is added to Owner List +if fn in driver.page_source: + print(fn, 'is added and found in the Owners Table') + print("Test Passed") +else: + print(fn, 'is not found in the Owners Table') + print("Test Failed") +driver.quit() \ No newline at end of file diff --git a/selenium-jobs/test_veterinarians_headless.py b/selenium-jobs/test_veterinarians_headless.py new file mode 100644 index 000000000..36dfc2107 --- /dev/null +++ b/selenium-jobs/test_veterinarians_headless.py @@ -0,0 +1,39 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from time import sleep +# Set chrome options for working with headless mode (no screen) +chrome_options = webdriver.ChromeOptions() +chrome_options.add_argument("headless") +# Update webdriver instance of chrome-driver with adding chrome options +driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) +# Connect to the application +url = "from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from time import sleep +# Set chrome options for working with headless mode (no screen) +chrome_options = webdriver.ChromeOptions() +chrome_options.add_argument("headless") +# Update webdriver instance of chrome-driver with adding chrome options +driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) +# Connect to the application +url = "ec2-18-232-125-248.compute-1.amazonaws.com:8080" +driver.get(url) +vet_link = driver.find_element_by_link_text("VETERINARIANS") +vet_link.click() +# Verify that table loaded +sleep(1) +verify_table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "table"))) +print("Table loaded") +driver.quit():8080" +driver.get(url) +vet_link = driver.find_element_by_link_text("VETERINARIANS") +vet_link.click() +# Verify that table loaded +sleep(1) +verify_table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "table"))) +print("Table loaded") +driver.quit() \ No newline at end of file From ea473383ede14dc3f4c0f652b009c14cc819d071 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Thu, 15 Oct 2020 20:55:13 -0400 Subject: [PATCH 23/39] added jenkins server cfn template --- .../jenkins-server-cfn-template.yml | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 infrastructure/jenkins-server-cfn-template.yml diff --git a/infrastructure/jenkins-server-cfn-template.yml b/infrastructure/jenkins-server-cfn-template.yml new file mode 100644 index 000000000..4beea1742 --- /dev/null +++ b/infrastructure/jenkins-server-cfn-template.yml @@ -0,0 +1,153 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: > + This Cloudformation Template creates a Jenkins Server using JDK 11 on EC2 Instance. + Jenkins Server is enabled with Git, Docker and Docker Compose, + AWS CLI Version 2, ECR Credential Helper, Python 3, Ansible, and Boto3. + Jenkins Server will run on Amazon Linux 2 EC2 Instance with + custom security group allowing HTTP(80, 8080) and SSH (22) connections from anywhere. +Parameters: + KeyPairName: + Description: Enter the name of your Key Pair for SSH connections. + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: Must one of the existing EC2 KeyPair +Resources: + EmpoweringPolicyforJenkinsServer: + Type: "AWS::IAM::ManagedPolicy" + Properties: + PolicyDocument: #required + Version: 2012-10-17 + Statement: + - Effect: Allow + Action: + - iam:AddRoleToInstanceProfile + - iam:CreateInstanceProfile + - iam:CreatePolicy + - iam:CreateRole + - iam:DeleteInstanceProfile + - iam:DeletePolicy + - iam:DeleteRole + - iam:GetPolicy + - iam:GetRole + - iam:ListPolicyVersions + - iam:AttachRolePolicy + - iam:DetachRolePolicy + - iam:PassRole + - iam:RemoveRoleFromInstanceProfile + - iam:GetInstanceProfile + Resource: "*" + - Effect: Allow + Action: + - ec2:* + Resource: "*" + EmpoweringRoleforJenkinsServer: + Type: "AWS::IAM::Role" + Properties: + AssumeRolePolicyDocument: + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - 'sts:AssumeRole' + ManagedPolicyArns: + - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess + - arn:aws:iam::aws:policy/AWSCloudFormationFullAccess + - !Ref EmpoweringPolicyforJenkinsServer + JenkinsServerEC2Profile: + Type: "AWS::IAM::InstanceProfile" + Properties: + Roles: #required + - !Ref EmpoweringRoleforJenkinsServer + JenkinsServerSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH and HTTP for Jenkins Server + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 80 + ToPort: 80 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: 0.0.0.0/0 + JenkinsServer: + Type: AWS::EC2::Instance + Properties: + ImageId: ami-0947d2ba12ee1ff75 + InstanceType: t2.medium + KeyName: !Ref KeyPairName + IamInstanceProfile: !Ref JenkinsServerEC2Profile + SecurityGroupIds: + - !GetAtt JenkinsServerSecurityGroup.GroupId + Tags: + - Key: Name + Value: !Sub Jenkins Server of ${AWS::StackName} + - Key: server + Value: jenkins + UserData: + Fn::Base64: | + #! /bin/bash + # update os + yum update -y + # set server hostname as jenkins-server + hostnamectl set-hostname jenkins-server + # install git + yum install git -y + # install java 11 + yum install java-11-amazon-corretto -y + # install jenkins + wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo + rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key + yum install jenkins -y + systemctl start jenkins + systemctl enable jenkins + # install docker + amazon-linux-extras install docker -y + systemctl start docker + systemctl enable docker + usermod -a -G docker ec2-user + usermod -a -G docker jenkins + # configure docker as cloud agent for jenkins + cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bak + sed -i 's/^ExecStart=.*/ExecStart=\/usr\/bin\/dockerd -H tcp:\/\/127.0.0.1:2375 -H unix:\/\/\/var\/run\/docker.sock/g' /lib/systemd/system/docker.service + systemctl daemon-reload + systemctl restart docker + systemctl restart jenkins + # install docker compose + curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \ + -o /usr/local/bin/docker-compose + chmod +x /usr/local/bin/docker-compose + # uninstall aws cli version 1 + rm -rf /bin/aws + # install aws cli version 2 + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" + unzip awscliv2.zip + ./aws/install + # install aws ecr credential helper + yum install amazon-ecr-credential-helper -y + mkdir -p /home/jenkins/.docker + cd /home/jenkins/.docker + echo '{"credsStore": "ecr-login"}' > config.json + # install python 3 + yum install python3 -y + # install ansible + pip3 install ansible + # install boto3 + pip3 install boto3 +Outputs: + JenkinsDNS: + Description: Jenkins Server DNS Name + Value: !Sub + - ${PublicAddress} + - PublicAddress: !GetAtt JenkinsServer.PublicDnsName + JenkinsURL: + Description: Jenkins Server URL + Value: !Sub + - http://${PublicAddress}:8080 + - PublicAddress: !GetAtt JenkinsServer.PublicDnsName \ No newline at end of file From 873953ee6c1f65f89c84996e0e96501fa91578e4 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sat, 17 Oct 2020 13:52:11 -0400 Subject: [PATCH 24/39] added script for petclinic-ci-job --- jenkins/jenkins-petclinic-ci-job.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 jenkins/jenkins-petclinic-ci-job.sh diff --git a/jenkins/jenkins-petclinic-ci-job.sh b/jenkins/jenkins-petclinic-ci-job.sh new file mode 100644 index 000000000..e80b48774 --- /dev/null +++ b/jenkins/jenkins-petclinic-ci-job.sh @@ -0,0 +1,2 @@ +echo 'Running unit tests on Petclinic Application' +docker run --rm -v $HOME/.m2:/root/.m2 -v `pwd`:/app -w /app maven:3.6.3-openjdk-11 mvn clean test \ No newline at end of file From bcbaac4ad7dc0650fde8b3f463b4456c0dda00e0 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sat, 17 Oct 2020 14:29:27 -0400 Subject: [PATCH 25/39] added script for creating ECR registry for dev --- jenkins/create-ecr-docker-registry-for-dev.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 jenkins/create-ecr-docker-registry-for-dev.sh diff --git a/jenkins/create-ecr-docker-registry-for-dev.sh b/jenkins/create-ecr-docker-registry-for-dev.sh new file mode 100644 index 000000000..8710704f1 --- /dev/null +++ b/jenkins/create-ecr-docker-registry-for-dev.sh @@ -0,0 +1,8 @@ +PATH="$PATH:/usr/local/bin" +APP_REPO_NAME="vildan71/petclinic-app-dev" +AWS_REGION="us-east-1" +aws ecr create-repository \ + --repository-name ${APP_REPO_NAME} \ + --image-scanning-configuration scanOnPush=false \ + --image-tag-mutability MUTABLE \ + --region ${AWS_REGION} \ No newline at end of file From e6f1879c28474af347e99cee6a8fd8d639d73234 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sat, 17 Oct 2020 15:19:17 -0400 Subject: [PATCH 26/39] added cloudformation template for Docker Swarm infrastructure --- ...cker-swarm-infrastructure-cfn-template.yml | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 infrastructure/docker-swarm-infrastructure-cfn-template.yml diff --git a/infrastructure/docker-swarm-infrastructure-cfn-template.yml b/infrastructure/docker-swarm-infrastructure-cfn-template.yml new file mode 100644 index 000000000..091aa3ccc --- /dev/null +++ b/infrastructure/docker-swarm-infrastructure-cfn-template.yml @@ -0,0 +1,173 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: | + This Cloudformation Template creates an infrastructure for Docker Swarm + with five EC2 Instances with Amazon Linux 2. Instances are configured + with custom security group allowing SSH (22), HTTP (80) UDP (4789, 7946), + and TCP(2377, 7946, 8080) connections from anywhere. + User needs to select appropriate key name when launching the template. +Parameters: + KeyPairName: + Description: Enter the name of your Key Pair for SSH connections. + Type: AWS::EC2::KeyPair::KeyName + ConstraintDescription: Must one of the existing EC2 KeyPair +Resources: + RoleEnablingEC2forECR: + Type: "AWS::IAM::Role" + Properties: + AssumeRolePolicyDocument: + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - 'sts:AssumeRole' + ManagedPolicyArns: + - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess + EC2Profile: + Type: "AWS::IAM::InstanceProfile" + Properties: + Roles: #required + - !Ref RoleEnablingEC2forECR + DockerMachinesSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Enable SSH and HTTP for Docker Machines + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 80 + ToPort: 80 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 2377 + ToPort: 2377 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 7946 + ToPort: 7946 + CidrIp: 0.0.0.0/0 + - IpProtocol: udp + FromPort: 7946 + ToPort: 7946 + CidrIp: 0.0.0.0/0 + - IpProtocol: udp + FromPort: 4789 + ToPort: 4789 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8080 + ToPort: 8080 + CidrIp: 0.0.0.0/0 + DockerMachineLT: + Type: "AWS::EC2::LaunchTemplate" + Properties: + LaunchTemplateData: + ImageId: ami-0947d2ba12ee1ff75 + InstanceType: t2.micro + KeyName: !Ref KeyPairName + IamInstanceProfile: + Arn: !GetAtt EC2Profile.Arn + SecurityGroupIds: + - !GetAtt DockerMachinesSecurityGroup.GroupId + TagSpecifications: + - ResourceType: instance + Tags: + - Key: app-stack-name + Value: !Sub ${AWS::StackName} + - Key: environment + Value: dev + DockerInstance1: + Type: AWS::EC2::Instance + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref DockerMachineLT + Version: !GetAtt DockerMachineLT.LatestVersionNumber + Tags: + - Key: server + Value: docker-instance-1 + - Key: swarm-role + Value: grand-master + - Key: Name + Value: !Sub ${AWS::StackName} Docker Machine 1st + DockerInstance2: + Type: AWS::EC2::Instance + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref DockerMachineLT + Version: !GetAtt DockerMachineLT.LatestVersionNumber + Tags: + - Key: server + Value: docker-instance-2 + - Key: swarm-role + Value: manager + - Key: Name + Value: !Sub ${AWS::StackName} Docker Machine 2nd + DockerInstance3: + Type: AWS::EC2::Instance + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref DockerMachineLT + Version: !GetAtt DockerMachineLT.LatestVersionNumber + Tags: + - Key: server + Value: docker-instance-3 + - Key: swarm-role + Value: manager + - Key: Name + Value: !Sub ${AWS::StackName} Docker Machine 3rd + DockerInstance4: + Type: AWS::EC2::Instance + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref DockerMachineLT + Version: !GetAtt DockerMachineLT.LatestVersionNumber + Tags: + - Key: server + Value: docker-instance-4 + - Key: swarm-role + Value: worker + - Key: Name + Value: !Sub ${AWS::StackName} Docker Machine 4th + DockerInstance5: + Type: AWS::EC2::Instance + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref DockerMachineLT + Version: !GetAtt DockerMachineLT.LatestVersionNumber + Tags: + - Key: server + Value: docker-instance-5 + - Key: swarm-role + Value: worker + - Key: Name + Value: !Sub ${AWS::StackName} Docker Machine 5th +Outputs: + 1stDockerInstanceDNSName: + Description: 1st Docker Instance DNS Name + Value: !Sub + - ${PublicAddress} + - PublicAddress: !GetAtt DockerInstance1.PublicDnsName + 2ndDockerInstanceDNSName: + Description: 2nd Docker Instance DNS Name + Value: !Sub + - ${PublicAddress} + - PublicAddress: !GetAtt DockerInstance2.PublicDnsName + 3rdDockerInstanceDNSName: + Description: 3rd Docker Instance DNS Name + Value: !Sub + - ${PublicAddress} + - PublicAddress: !GetAtt DockerInstance3.PublicDnsName + 4thDockerInstanceDNSName: + Description: 4th Docker Instance DNS Name + Value: !Sub + - ${PublicAddress} + - PublicAddress: !GetAtt DockerInstance4.PublicDnsName + 5thDockerInstanceDNSName: + Description: 5th Docker Instance DNS Name + Value: !Sub + - ${PublicAddress} + - PublicAddress: !GetAtt DockerInstance5.PublicDnsName \ No newline at end of file From 5792d1ab077c2aa68ac007221358cbfe5e59083c Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 18 Oct 2020 12:07:44 -0400 Subject: [PATCH 27/39] added cloudformation template for Docker Swarm infrastructure --- hello.key | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello.key diff --git a/hello.key b/hello.key new file mode 100644 index 000000000..e69de29bb From a6f2d5c3e5cbb702dcc3ec4ac8350cf8ce21119e Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 18 Oct 2020 12:09:32 -0400 Subject: [PATCH 28/39] hello --- hello.key | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 hello.key diff --git a/hello.key b/hello.key deleted file mode 100644 index e69de29bb..000000000 From 6557cde5c8d51cbf5439a7889369bb641bd95e0b Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 18 Oct 2020 12:30:22 -0400 Subject: [PATCH 29/39] added ansible static inventory host.ini for testing --- ansible/inventory/hosts.ini | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 ansible/inventory/hosts.ini diff --git a/ansible/inventory/hosts.ini b/ansible/inventory/hosts.ini new file mode 100644 index 000000000..3d10f65aa --- /dev/null +++ b/ansible/inventory/hosts.ini @@ -0,0 +1,5 @@ +172.31.83.232 ansible_user=ec2-user +172.31.29.65 ansible_user=ec2-user +172.31.17.177 ansible_user=ec2-user +172.31.24.221 ansible_user=ec2-user +172.31.25.179 ansible_user=ec2-user From dbffe010abaf65fe843500e2cc16c6f4ad475456 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Mon, 19 Oct 2020 18:52:50 -0400 Subject: [PATCH 30/39] added ansible static inventory hosts.ini for testing --- ansible/inventory/hosts.ini | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ansible/inventory/hosts.ini b/ansible/inventory/hosts.ini index 3d10f65aa..02c64ea41 100644 --- a/ansible/inventory/hosts.ini +++ b/ansible/inventory/hosts.ini @@ -1,5 +1,5 @@ -172.31.83.232 ansible_user=ec2-user -172.31.29.65 ansible_user=ec2-user -172.31.17.177 ansible_user=ec2-user -172.31.24.221 ansible_user=ec2-user -172.31.25.179 ansible_user=ec2-user +172.31.83.80 ansible_user=ec2-user +172.31.86.251 ansible_user=ec2-user +172.31.84.195 ansible_user=ec2-user +172.31.82.149 ansible_user=ec2-user +172.31.87.90 ansible_user=ec2-user From b0b37193046a72f0944777063a5ce21cd49864b6 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Mon, 19 Oct 2020 21:29:09 -0400 Subject: [PATCH 31/39] added ansible dynamic inventory files for dev environment --- .../dev_stack_dynamic_inventory_aws_ec2.yaml | 22 +++++++++++++++++++ .../dev_stack_swarm_grand_master_aws_ec2.yaml | 11 ++++++++++ .../dev_stack_swarm_managers_aws_ec2.yaml | 11 ++++++++++ .../dev_stack_swarm_workers_aws_ec2.yaml | 11 ++++++++++ 4 files changed, 55 insertions(+) create mode 100644 ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml create mode 100644 ansible/inventory/dev_stack_swarm_grand_master_aws_ec2.yaml create mode 100644 ansible/inventory/dev_stack_swarm_managers_aws_ec2.yaml create mode 100644 ansible/inventory/dev_stack_swarm_workers_aws_ec2.yaml diff --git a/ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml b/ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml new file mode 100644 index 000000000..add3b2431 --- /dev/null +++ b/ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml @@ -0,0 +1,22 @@ +plugin: aws_ec2 +regions: + - "us-east-1" +filters: + tag:app-stack-name: APP_STACK_NAME + tag:environment: dev +keyed_groups: + - key: tags['app-stack-name'] + prefix: 'app_stack_' + separator: '' + - key: tags['swarm-role'] + prefix: 'role_' + separator: '' + - key: tags['environment'] + prefix: 'env_' + separator: '' + - key: tags['server'] + separator: '' +hostnames: + - "private-ip-address" +compose: + ansible_user: "'ec2-user'" \ No newline at end of file diff --git a/ansible/inventory/dev_stack_swarm_grand_master_aws_ec2.yaml b/ansible/inventory/dev_stack_swarm_grand_master_aws_ec2.yaml new file mode 100644 index 000000000..b1569ff1d --- /dev/null +++ b/ansible/inventory/dev_stack_swarm_grand_master_aws_ec2.yaml @@ -0,0 +1,11 @@ +plugin: aws_ec2 +regions: + - "us-east-1" +filters: + tag:app-stack-name: APP_STACK_NAME + tag:environment: dev + tag:swarm-role: grand-master +hostnames: + - "private-ip-address" +compose: + ansible_user: "'ec2-user'" \ No newline at end of file diff --git a/ansible/inventory/dev_stack_swarm_managers_aws_ec2.yaml b/ansible/inventory/dev_stack_swarm_managers_aws_ec2.yaml new file mode 100644 index 000000000..e9647b593 --- /dev/null +++ b/ansible/inventory/dev_stack_swarm_managers_aws_ec2.yaml @@ -0,0 +1,11 @@ +plugin: aws_ec2 +regions: + - "us-east-1" +filters: + tag:app-stack-name: APP_STACK_NAME + tag:environment: dev + tag:swarm-role: manager +hostnames: + - "private-ip-address" +compose: + ansible_user: "'ec2-user'" \ No newline at end of file diff --git a/ansible/inventory/dev_stack_swarm_workers_aws_ec2.yaml b/ansible/inventory/dev_stack_swarm_workers_aws_ec2.yaml new file mode 100644 index 000000000..f702f7ad9 --- /dev/null +++ b/ansible/inventory/dev_stack_swarm_workers_aws_ec2.yaml @@ -0,0 +1,11 @@ +plugin: aws_ec2 +regions: + - "us-east-1" +filters: + tag:app-stack-name: APP_STACK_NAME + tag:environment: dev + tag:swarm-role: worker +hostnames: + - "private-ip-address" +compose: + ansible_user: "'ec2-user'" \ No newline at end of file From 5f1c0f268d57c848b367aeeca0debe9a765a44c5 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 20 Oct 2020 20:36:49 -0400 Subject: [PATCH 32/39] added scripts for qa automation environment --- ansible/inventory/hosts.ini | 10 ++-- .../playbooks/pb_initialize_docker_swarm.yaml | 13 +++++ ..._setup_for_all_docker_swarm_instances.yaml | 54 +++++++++++++++++++ .../create-qa-automation-environment.sh | 31 +++++++++++ ...ker-swarm-infrastructure-cfn-template.yml} | 17 ++++-- 5 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 ansible/playbooks/pb_initialize_docker_swarm.yaml create mode 100644 ansible/playbooks/pb_setup_for_all_docker_swarm_instances.yaml create mode 100644 infrastructure/create-qa-automation-environment.sh rename infrastructure/{docker-swarm-infrastructure-cfn-template.yml => dev-docker-swarm-infrastructure-cfn-template.yml} (94%) diff --git a/ansible/inventory/hosts.ini b/ansible/inventory/hosts.ini index 02c64ea41..a20d5d467 100644 --- a/ansible/inventory/hosts.ini +++ b/ansible/inventory/hosts.ini @@ -1,5 +1,5 @@ -172.31.83.80 ansible_user=ec2-user -172.31.86.251 ansible_user=ec2-user -172.31.84.195 ansible_user=ec2-user -172.31.82.149 ansible_user=ec2-user -172.31.87.90 ansible_user=ec2-user +172.31.83.80 ansible_user=ec2-user +172.31.86.251 ansible_user=ec2-user +172.31.84.195 ansible_user=ec2-user +172.31.82.149 ansible_user=ec2-user +172.31.87.90 ansible_user=ec2-user diff --git a/ansible/playbooks/pb_initialize_docker_swarm.yaml b/ansible/playbooks/pb_initialize_docker_swarm.yaml new file mode 100644 index 000000000..e1a9c473f --- /dev/null +++ b/ansible/playbooks/pb_initialize_docker_swarm.yaml @@ -0,0 +1,13 @@ +--- +- hosts: role_grand_master + tasks: + - name: initialize docker swarm + shell: docker swarm init + - name: run the visualizer app for docker swarm + shell: | + docker service create \ + --name=viz \ + --publish=8088:8080/tcp \ + --constraint=node.role==manager \ + --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \ + dockersamples/visualizer \ No newline at end of file diff --git a/ansible/playbooks/pb_setup_for_all_docker_swarm_instances.yaml b/ansible/playbooks/pb_setup_for_all_docker_swarm_instances.yaml new file mode 100644 index 000000000..d13bd619d --- /dev/null +++ b/ansible/playbooks/pb_setup_for_all_docker_swarm_instances.yaml @@ -0,0 +1,54 @@ +--- +- hosts: all + tasks: + - name: update os + yum: + name: '*' + state: present + - name: install docker + command: amazon-linux-extras install docker=latest -y + - name: start docker + service: + name: docker + state: started + enabled: yes + - name: add ec2-user to docker group + shell: "usermod -a -G docker ec2-user" + - name: Install Docker Compose (if configured). + get_url: + url: https://github.com/docker/compose/releases/download/1.26.2/docker-compose-Linux-x86_64 + dest: /usr/local/bin/docker-compose + mode: 0755 + - name: uninstall aws cli v1 + file: + path: /bin/aws + state: absent + - name: Download awscliv2 installer + unarchive: + src: https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip + dest: /tmp + remote_src: yes + creates: /tmp/aws + mode: 0755 + - name: Run the installer. + command: + args: + cmd: "/tmp/aws/install" + creates: /usr/local/bin/aws + - name: install ecr credential helper + yum: + name: amazon-ecr-credential-helper + state: present + - name: Create folder for config file of ecr cred helper + file: + path: /home/ec2-user/.docker + state: directory + owner: "ec2-user" + mode: "g+rwx" + - name: create config file with content for ecr creds + copy: + content: '{"credsStore":"ecr-login"}' + dest: /home/ec2-user/.docker/config.json + owner: "ec2-user" + mode: "g+rwx" + \ No newline at end of file diff --git a/infrastructure/create-qa-automation-environment.sh b/infrastructure/create-qa-automation-environment.sh new file mode 100644 index 000000000..781ca025c --- /dev/null +++ b/infrastructure/create-qa-automation-environment.sh @@ -0,0 +1,31 @@ +# Environment variables +PATH="$PATH:/usr/local/bin" +APP_NAME="Petclinic" +CFN_KEYPAIR="Vildan-$APP_NAME-dev-${BUILD_NUMBER}.key" +CFN_TEMPLATE="./infrastructure/dev-docker-swarm-infrastructure-cfn-template.yml" +AWS_REGION="us-east-1" +export ANSIBLE_PRIVATE_KEY_FILE="${WORKSPACE}/${CFN_KEYPAIR}" +export ANSIBLE_HOST_KEY_CHECKING=False +export APP_STACK_NAME="Vildan-$APP_NAME-App-${BUILD_NUMBER}" +# Create key pair for Ansible +aws ec2 create-key-pair --region ${AWS_REGION} --key-name ${CFN_KEYPAIR} --query "KeyMaterial" --output text > ${CFN_KEYPAIR} +chmod 400 ${CFN_KEYPAIR} +# Create infrastructure for Docker Swarm +aws cloudformation create-stack --region ${AWS_REGION} --stack-name ${APP_STACK_NAME} --capabilities CAPABILITY_IAM --template-body file://${CFN_TEMPLATE} --parameters ParameterKey=KeyPairName,ParameterValue=${CFN_KEYPAIR} +# Install Docker Swarm environment on the infrastructure +# Update dynamic inventory (hosts/docker nodes) +sed -i "s/APP_STACK_NAME/$APP_STACK_NAME/" ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml +# Install common tools on all instances/nodes +ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_setup_for_all_docker_swarm_instances.yaml +# Initialize Docker Swarm on Grand Master +ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_initialize_docker_swarm.yaml +# Join the manager instances to the Swarm +ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_join_docker_swarm_managers.yaml +# Join the worker instances to the Swarm +ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_join_docker_swarm_workers.yaml +# Build, Deploy, Test the application +# Tear down the Docker Swarm infrastructure +aws cloudformation delete-stack --region ${AWS_REGION} --stack-name ${AWS_STACK_NAME} +# Delete key pair +aws ec2 delete-key-pair --region ${AWS_REGION} --key-name ${CFN_KEYPAIR} +rm -rf ${CFN_KEYPAIR} \ No newline at end of file diff --git a/infrastructure/docker-swarm-infrastructure-cfn-template.yml b/infrastructure/dev-docker-swarm-infrastructure-cfn-template.yml similarity index 94% rename from infrastructure/docker-swarm-infrastructure-cfn-template.yml rename to infrastructure/dev-docker-swarm-infrastructure-cfn-template.yml index 091aa3ccc..6a034195d 100644 --- a/infrastructure/docker-swarm-infrastructure-cfn-template.yml +++ b/infrastructure/dev-docker-swarm-infrastructure-cfn-template.yml @@ -1,5 +1,5 @@ AWSTemplateFormatVersion: 2010-09-09 -Description: | +Description: > This Cloudformation Template creates an infrastructure for Docker Swarm with five EC2 Instances with Amazon Linux 2. Instances are configured with custom security group allowing SSH (22), HTTP (80) UDP (4789, 7946), @@ -10,7 +10,7 @@ Parameters: Description: Enter the name of your Key Pair for SSH connections. Type: AWS::EC2::KeyPair::KeyName ConstraintDescription: Must one of the existing EC2 KeyPair -Resources: +Resources: RoleEnablingEC2forECR: Type: "AWS::IAM::Role" Properties: @@ -62,12 +62,16 @@ Resources: FromPort: 8080 ToPort: 8080 CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 8088 + ToPort: 8088 + CidrIp: 0.0.0.0/0 DockerMachineLT: Type: "AWS::EC2::LaunchTemplate" Properties: LaunchTemplateData: ImageId: ami-0947d2ba12ee1ff75 - InstanceType: t2.micro + InstanceType: t2.medium KeyName: !Ref KeyPairName IamInstanceProfile: Arn: !GetAtt EC2Profile.Arn @@ -82,6 +86,8 @@ Resources: Value: dev DockerInstance1: Type: AWS::EC2::Instance + DependsOn: + - "DockerInstance2" Properties: LaunchTemplate: LaunchTemplateId: !Ref DockerMachineLT @@ -92,7 +98,7 @@ Resources: - Key: swarm-role Value: grand-master - Key: Name - Value: !Sub ${AWS::StackName} Docker Machine 1st + Value: !Sub ${AWS::StackName} Docker Machine 1st DockerInstance2: Type: AWS::EC2::Instance Properties: @@ -170,4 +176,5 @@ Outputs: Description: 5th Docker Instance DNS Name Value: !Sub - ${PublicAddress} - - PublicAddress: !GetAtt DockerInstance5.PublicDnsName \ No newline at end of file + - PublicAddress: !GetAtt DockerInstance5.PublicDnsName + \ No newline at end of file From 0cb29210700e3b0837db629ea9e1bc2e9081d498 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 20 Oct 2020 21:23:37 -0400 Subject: [PATCH 33/39] added scripts for qa automation environment --- jenkins/build-dev-docker-images-for-ecr.sh | 10 ++++++++++ jenkins/package-with-maven-container.sh | 1 + .../prepare-tags-ecr-for-dev-docker-images.sh | 18 ++++++++++++++++++ jenkins/push-dev-docker-images-to-ecr.sh | 11 +++++++++++ 4 files changed, 40 insertions(+) create mode 100644 jenkins/build-dev-docker-images-for-ecr.sh create mode 100644 jenkins/package-with-maven-container.sh create mode 100644 jenkins/prepare-tags-ecr-for-dev-docker-images.sh create mode 100644 jenkins/push-dev-docker-images-to-ecr.sh diff --git a/jenkins/build-dev-docker-images-for-ecr.sh b/jenkins/build-dev-docker-images-for-ecr.sh new file mode 100644 index 000000000..4ea98df32 --- /dev/null +++ b/jenkins/build-dev-docker-images-for-ecr.sh @@ -0,0 +1,10 @@ +docker build --force-rm -t "${IMAGE_TAG_ADMIN_SERVER}" "${WORKSPACE}/spring-petclinic-admin-server" +docker build --force-rm -t "${IMAGE_TAG_API_GATEWAY}" "${WORKSPACE}/spring-petclinic-api-gateway" +docker build --force-rm -t "${IMAGE_TAG_CONFIG_SERVER}" "${WORKSPACE}/spring-petclinic-config-server" +docker build --force-rm -t "${IMAGE_TAG_CUSTOMERS_SERVICE}" "${WORKSPACE}/spring-petclinic-customers-service" +docker build --force-rm -t "${IMAGE_TAG_DISCOVERY_SERVER}" "${WORKSPACE}/spring-petclinic-discovery-server" +docker build --force-rm -t "${IMAGE_TAG_HYSTRIX_DASHBOARD}" "${WORKSPACE}/spring-petclinic-hystrix-dashboard" +docker build --force-rm -t "${IMAGE_TAG_VETS_SERVICE}" "${WORKSPACE}/spring-petclinic-vets-service" +docker build --force-rm -t "${IMAGE_TAG_VISITS_SERVICE}" "${WORKSPACE}/spring-petclinic-visits-service" +docker build --force-rm -t "${IMAGE_TAG_GRAFANA_SERVICE}" "${WORKSPACE}/docker/grafana" +docker build --force-rm -t "${IMAGE_TAG_PROMETHEUS_SERVICE}" "${WORKSPACE}/docker/prometheus" \ No newline at end of file diff --git a/jenkins/package-with-maven-container.sh b/jenkins/package-with-maven-container.sh new file mode 100644 index 000000000..6d691a5ed --- /dev/null +++ b/jenkins/package-with-maven-container.sh @@ -0,0 +1 @@ +docker run --rm -v $HOME/.m2:/root/.m2 -v $WORKSPACE:/app -w /app maven:3.6-openjdk-11 mvn clean package \ No newline at end of file diff --git a/jenkins/prepare-tags-ecr-for-dev-docker-images.sh b/jenkins/prepare-tags-ecr-for-dev-docker-images.sh new file mode 100644 index 000000000..8fff3dbf6 --- /dev/null +++ b/jenkins/prepare-tags-ecr-for-dev-docker-images.sh @@ -0,0 +1,18 @@ +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-admin-server/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_ADMIN_SERVER="${ECR_REGISTRY}/${APP_REPO_NAME}:admin-server-v${MVN_VERSION}-b${BUILD_NUMBER}" +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-api-gateway/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_API_GATEWAY="${ECR_REGISTRY}/${APP_REPO_NAME}:api-gateway-v${MVN_VERSION}-b${BUILD_NUMBER}" +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-config-server/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_CONFIG_SERVER="${ECR_REGISTRY}/${APP_REPO_NAME}:config-server-v${MVN_VERSION}-b${BUILD_NUMBER}" +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-customers-service/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_CUSTOMERS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:customers-service-v${MVN_VERSION}-b${BUILD_NUMBER}" +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-discovery-server/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_DISCOVERY_SERVER="${ECR_REGISTRY}/${APP_REPO_NAME}:discovery-server-v${MVN_VERSION}-b${BUILD_NUMBER}" +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-hystrix-dashboard/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_HYSTRIX_DASHBOARD="${ECR_REGISTRY}/${APP_REPO_NAME}:hystrix-dashboard-v${MVN_VERSION}-b${BUILD_NUMBER}" +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-vets-service/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_VETS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:vets-service-v${MVN_VERSION}-b${BUILD_NUMBER}" +MVN_VERSION=$(. ${WORKSPACE}/spring-petclinic-visits-service/target/maven-archiver/pom.properties && echo $version) +export IMAGE_TAG_VISITS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:visits-service-v${MVN_VERSION}-b${BUILD_NUMBER}" +export IMAGE_TAG_GRAFANA_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:grafana-service" +export IMAGE_TAG_PROMETHEUS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:prometheus-service" \ No newline at end of file diff --git a/jenkins/push-dev-docker-images-to-ecr.sh b/jenkins/push-dev-docker-images-to-ecr.sh new file mode 100644 index 000000000..a65975e75 --- /dev/null +++ b/jenkins/push-dev-docker-images-to-ecr.sh @@ -0,0 +1,11 @@ +aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY} +docker push "${IMAGE_TAG_ADMIN_SERVER}" +ocker push "${IMAGE_TAG_API_GATEWAY}" +docker push "${IMAGE_TAG_CONFIG_SERVER}" +docker push "${IMAGE_TAG_CUSTOMERS_SERVICE}" +docker push "${IMAGE_TAG_DISCOVERY_SERVER}" +docker push "${IMAGE_TAG_HYSTRIX_DASHBOARD}" +docker push "${IMAGE_TAG_VETS_SERVICE}" +docker push "${IMAGE_TAG_VISITS_SERVICE}" +docker push "${IMAGE_TAG_GRAFANA_SERVICE}" +docker push "${IMAGE_TAG_PROMETHEUS_SERVICE}" \ No newline at end of file From 4a151625ba5c4b1662e4484b9e3731793815130a Mon Sep 17 00:00:00 2001 From: vildan71 Date: Tue, 20 Oct 2020 21:44:55 -0400 Subject: [PATCH 34/39] added scripts for qa automation environment --- jenkins/push-dev-docker-images-to-ecr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/push-dev-docker-images-to-ecr.sh b/jenkins/push-dev-docker-images-to-ecr.sh index a65975e75..7ae5bfdfd 100644 --- a/jenkins/push-dev-docker-images-to-ecr.sh +++ b/jenkins/push-dev-docker-images-to-ecr.sh @@ -1,6 +1,6 @@ aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY} docker push "${IMAGE_TAG_ADMIN_SERVER}" -ocker push "${IMAGE_TAG_API_GATEWAY}" +docker push "${IMAGE_TAG_API_GATEWAY}" docker push "${IMAGE_TAG_CONFIG_SERVER}" docker push "${IMAGE_TAG_CUSTOMERS_SERVICE}" docker push "${IMAGE_TAG_DISCOVERY_SERVER}" From ca1839217c1f76622fbe49d44e0a6be26415c7f7 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Thu, 22 Oct 2020 20:36:25 -0400 Subject: [PATCH 35/39] added scripts for running dummy selenium job --- .../pb_deploy_app_on_docker_swarm.yaml | 14 ++ .../playbooks/pb_run_dummy_selenium_job.yaml | 10 ++ ansible/scripts/deploy_app_on_docker_swarm.sh | 4 + ansible/scripts/run_dummy_selenium_job.sh | 2 + docker-compose-swarm-dev.yml | 125 ++++++++++++++++++ selenium-jobs/dummy_selenium_test_headless.py | 14 ++ 6 files changed, 169 insertions(+) create mode 100644 ansible/playbooks/pb_deploy_app_on_docker_swarm.yaml create mode 100644 ansible/playbooks/pb_run_dummy_selenium_job.yaml create mode 100644 ansible/scripts/deploy_app_on_docker_swarm.sh create mode 100644 ansible/scripts/run_dummy_selenium_job.sh create mode 100644 docker-compose-swarm-dev.yml create mode 100644 selenium-jobs/dummy_selenium_test_headless.py diff --git a/ansible/playbooks/pb_deploy_app_on_docker_swarm.yaml b/ansible/playbooks/pb_deploy_app_on_docker_swarm.yaml new file mode 100644 index 000000000..fe81737bb --- /dev/null +++ b/ansible/playbooks/pb_deploy_app_on_docker_swarm.yaml @@ -0,0 +1,14 @@ +--- +- hosts: role_grand_master + tasks: + - name: Copy docker compose file to grand master + copy: + src: "{{ workspace }}/docker-compose-swarm-dev-tagged.yml" + dest: /home/ec2-user/docker-compose-swarm-dev-tagged.yml + - name: get login credentials for ecr + shell: "export PATH=$PATH:/usr/local/bin/ && aws ecr get-login-password --region {{ aws_region }} | docker login --username AWS --password-stdin {{ ecr_registry }}" + register: output + - name: deploy the app stack on swarm + shell: "docker stack deploy --with-registry-auth -c /home/ec2-user/docker-compose-swarm-dev-tagged.yml {{ app_name }}" + register: output + - debug: msg="{{ output.stdout }}" \ No newline at end of file diff --git a/ansible/playbooks/pb_run_dummy_selenium_job.yaml b/ansible/playbooks/pb_run_dummy_selenium_job.yaml new file mode 100644 index 000000000..9585026ca --- /dev/null +++ b/ansible/playbooks/pb_run_dummy_selenium_job.yaml @@ -0,0 +1,10 @@ +--- +- hosts: all + tasks: + - name: run dummy selenium job + shell: "docker run --rm -v {{ workspace }}:{{ workspace }} -w {{ workspace }} callahanclarus/selenium-py-chrome:latest python {{ item }}" + with_fileglob: "{{ workspace }}/selenium-jobs/dummy*.py" + register: output + - name: show results + debug: msg="{{ item.stdout }}" + with_items: "{{ output.results }}" \ No newline at end of file diff --git a/ansible/scripts/deploy_app_on_docker_swarm.sh b/ansible/scripts/deploy_app_on_docker_swarm.sh new file mode 100644 index 000000000..d36c706bf --- /dev/null +++ b/ansible/scripts/deploy_app_on_docker_swarm.sh @@ -0,0 +1,4 @@ +PATH="$PATH:/usr/local/bin" +APP_NAME="petclinic" +envsubst < docker-compose-swarm-dev.yml > docker-compose-swarm-dev-tagged.yml +ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b --extra-vars "workspace=${WORKSPACE} app_name=${APP_NAME} aws_region=${AWS_REGION} ecr_registry=${ECR_REGISTRY}" ./ansible/playbooks/pb_deploy_app_on_docker_swarm.yaml \ No newline at end of file diff --git a/ansible/scripts/run_dummy_selenium_job.sh b/ansible/scripts/run_dummy_selenium_job.sh new file mode 100644 index 000000000..4e5d10d05 --- /dev/null +++ b/ansible/scripts/run_dummy_selenium_job.sh @@ -0,0 +1,2 @@ +PATH="$PATH:/usr/local/bin" +ansible-playbook --connection=local --inventory 127.0.0.1, --extra-vars "workspace=${WORKSPACE}" ./ansible/playbooks/pb_run_dummy_selenium_job.yaml \ No newline at end of file diff --git a/docker-compose-swarm-dev.yml b/docker-compose-swarm-dev.yml new file mode 100644 index 000000000..4ccb0f2f2 --- /dev/null +++ b/docker-compose-swarm-dev.yml @@ -0,0 +1,125 @@ +version: '3.8' +services: + config-server: + image: "${IMAGE_TAG_CONFIG_SERVER}" + networks: + - clarusnet + ports: + - 8888:8888 + discovery-server: + image: "${IMAGE_TAG_DISCOVERY_SERVER}" + depends_on: + - config-server + entrypoint: ["./dockerize","-wait=tcp://config-server:8888","-timeout=60s","--","java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] + networks: + - clarusnet + ports: + - 8761:8761 + customers-service: + image: "${IMAGE_TAG_CUSTOMERS_SERVICE}" + deploy: + replicas: 3 + update_config: + parallelism: 2 + delay: 5s + order: start-first + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] + networks: + - clarusnet + ports: + - 8081:8081 + visits-service: + image: "${IMAGE_TAG_VISITS_SERVICE}" + deploy: + replicas: 3 + update_config: + parallelism: 2 + delay: 5s + order: start-first + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] + networks: + - clarusnet + ports: + - 8082:8082 + vets-service: + image: "${IMAGE_TAG_VETS_SERVICE}" + deploy: + replicas: 3 + update_config: + parallelism: 2 + delay: 5s + order: start-first + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] + networks: + - clarusnet + ports: + - 8083:8083 + api-gateway: + image: "${IMAGE_TAG_API_GATEWAY}" + deploy: + replicas: 3 + update_config: + parallelism: 2 + delay: 5s + order: start-first + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] + networks: + - clarusnet + ports: + - 8080:8080 + tracing-server: + image: openzipkin/zipkin + environment: + - JAVA_OPTS=-XX:+UnlockExperimentalVMOptions -Djava.security.egd=file:/dev/./urandom + networks: + - clarusnet + ports: + - 9411:9411 + admin-server: + image: "${IMAGE_TAG_ADMIN_SERVER}" + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] + networks: + - clarusnet + ports: + - 9090:9090 + hystrix-dashboard: + image: "${IMAGE_TAG_HYSTRIX_DASHBOARD}" + depends_on: + - config-server + - discovery-server + entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] + networks: + - clarusnet + ports: + - 7979:7979 + ## Grafana / Prometheus + grafana-server: + image: "${IMAGE_TAG_GRAFANA_SERVICE}" + networks: + - clarusnet + ports: + - 3000:3000 + prometheus-server: + image: "${IMAGE_TAG_PROMETHEUS_SERVICE}" + networks: + - clarusnet + ports: + - 9091:9090 +networks: + clarusnet: + driver: overlay \ No newline at end of file diff --git a/selenium-jobs/dummy_selenium_test_headless.py b/selenium-jobs/dummy_selenium_test_headless.py new file mode 100644 index 000000000..05d9c12dc --- /dev/null +++ b/selenium-jobs/dummy_selenium_test_headless.py @@ -0,0 +1,14 @@ +from selenium import webdriver +chrome_options = webdriver.ChromeOptions() +chrome_options.add_argument("headless") +chrome_options.add_argument("no-sandbox") +chrome_options.add_argument("disable-dev-shm-usage") +driver = webdriver.Chrome(options=chrome_options) +base_url = "https://www.google.com/" +driver.get(base_url) +source = driver.page_source +if "I'm Feeling Lucky" in source: + print("Test passed") +else: + print("Test failed") +driver.close() \ No newline at end of file From f5444267d9ca619fdd78783d848d21ffd7991ee5 Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sat, 24 Oct 2020 11:47:11 -0400 Subject: [PATCH 36/39] added qa automation pipeline for dev --- ansible/playbooks/pb_run_selenium_jobs.yaml | 10 + ansible/scripts/run_selenium_jobs.sh | 2 + jenkins/jenkinsfile-petclinic-nightly | 174 ++++++++++++++++++ selenium-jobs/test_owners_all_headless.py | 9 +- .../test_owners_register_headless.py | 20 +- selenium-jobs/test_veterinarians_headless.py | 28 +-- 6 files changed, 212 insertions(+), 31 deletions(-) create mode 100644 ansible/playbooks/pb_run_selenium_jobs.yaml create mode 100644 ansible/scripts/run_selenium_jobs.sh create mode 100644 jenkins/jenkinsfile-petclinic-nightly diff --git a/ansible/playbooks/pb_run_selenium_jobs.yaml b/ansible/playbooks/pb_run_selenium_jobs.yaml new file mode 100644 index 000000000..3c76d8902 --- /dev/null +++ b/ansible/playbooks/pb_run_selenium_jobs.yaml @@ -0,0 +1,10 @@ +--- +- hosts: all + tasks: + - name: run all selenium jobs + shell: "docker run --rm --env MASTER_PUBLIC_IP={{ master_public_ip }} -v {{ workspace }}:{{ workspace }} -w {{ workspace }} callahanclarus/selenium-py-chrome:latest python {{ item }}" + register: output + with_fileglob: "{{ workspace }}/selenium-jobs/test*.py" + - name: show results + debug: msg="{{ item.stdout }}" + with_items: "{{ output.results }}" \ No newline at end of file diff --git a/ansible/scripts/run_selenium_jobs.sh b/ansible/scripts/run_selenium_jobs.sh new file mode 100644 index 000000000..573fa9513 --- /dev/null +++ b/ansible/scripts/run_selenium_jobs.sh @@ -0,0 +1,2 @@ +PATH="$PATH:/usr/local/bin" +ansible-playbook -vvv --connection=local --inventory 127.0.0.1, --extra-vars "workspace=${WORKSPACE} master_public_ip=${GRAND_MASTER_PUBLIC_IP}" ./ansible/playbooks/pb_run_selenium_jobs.yaml \ No newline at end of file diff --git a/jenkins/jenkinsfile-petclinic-nightly b/jenkins/jenkinsfile-petclinic-nightly new file mode 100644 index 000000000..712e985a0 --- /dev/null +++ b/jenkins/jenkinsfile-petclinic-nightly @@ -0,0 +1,174 @@ +pipeline { + agent { label "master" } + environment { + PATH=sh(script:"echo $PATH:/usr/local/bin", returnStdout:true).trim() + APP_NAME="petclinic" + APP_STACK_NAME="Vildan-${APP_NAME}-app-${BUILD_NUMBER}" + APP_REPO_NAME="vildan71/${APP_NAME}-app-dev" + AWS_ACCOUNT_ID=sh(script:'export PATH="$PATH:/usr/local/bin" && aws sts get-caller-identity --query Account --output text', returnStdout:true).trim() + AWS_REGION="us-east-1" + ECR_REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" + CFN_KEYPAIR="call-${APP_NAME}-dev-${BUILD_NUMBER}.key" + CFN_TEMPLATE="./infrastructure/dev-docker-swarm-infrastructure-cfn-template.yml" + ANSIBLE_PRIVATE_KEY_FILE="${WORKSPACE}/${CFN_KEYPAIR}" + ANSIBLE_HOST_KEY_CHECKING="False" + } + stages { + stage('Create ECR Repo') { + steps { + echo "Creating ECR Repo for ${APP_NAME} app" + sh """ + aws ecr create-repository \ + --repository-name ${APP_REPO_NAME} \ + --image-scanning-configuration scanOnPush=false \ + --image-tag-mutability MUTABLE \ + --region ${AWS_REGION} + """ + } + } + stage('Package Application') { + steps { + echo 'Packaging the app into jars with maven' + sh ". ./jenkins/package-with-maven-container.sh" + } + } + stage('Prepare Tags for Docker Images') { + steps { + echo 'Preparing Tags for Docker Images' + script { + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-admin-server/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_ADMIN_SERVER="${ECR_REGISTRY}/${APP_REPO_NAME}:admin-server-v${MVN_VERSION}-b${BUILD_NUMBER}" + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-api-gateway/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_API_GATEWAY="${ECR_REGISTRY}/${APP_REPO_NAME}:api-gateway-v${MVN_VERSION}-b${BUILD_NUMBER}" + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-config-server/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_CONFIG_SERVER="${ECR_REGISTRY}/${APP_REPO_NAME}:config-server-v${MVN_VERSION}-b${BUILD_NUMBER}" + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-customers-service/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_CUSTOMERS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:customers-service-v${MVN_VERSION}-b${BUILD_NUMBER}" + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-discovery-server/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_DISCOVERY_SERVER="${ECR_REGISTRY}/${APP_REPO_NAME}:discovery-server-v${MVN_VERSION}-b${BUILD_NUMBER}" + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-hystrix-dashboard/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_HYSTRIX_DASHBOARD="${ECR_REGISTRY}/${APP_REPO_NAME}:hystrix-dashboard-v${MVN_VERSION}-b${BUILD_NUMBER}" + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-vets-service/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_VETS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:vets-service-v${MVN_VERSION}-b${BUILD_NUMBER}" + MVN_VERSION=sh(script:'. ${WORKSPACE}/spring-petclinic-visits-service/target/maven-archiver/pom.properties && echo $version', returnStdout:true).trim() + env.IMAGE_TAG_VISITS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:visits-service-v${MVN_VERSION}-b${BUILD_NUMBER}" + env.IMAGE_TAG_GRAFANA_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:grafana-service" + env.IMAGE_TAG_PROMETHEUS_SERVICE="${ECR_REGISTRY}/${APP_REPO_NAME}:prometheus-service" + } + } + } + stage('Build App Docker Images') { + steps { + echo 'Building App Dev Images' + sh ". ./jenkins/build-dev-docker-images-for-ecr.sh" + sh 'docker image ls' + } + } + stage('Push Images to ECR Repo') { + steps { + echo "Pushing ${APP_NAME} App Images to ECR Repo" + sh ". ./jenkins/push-dev-docker-images-to-ecr.sh" + } + } + stage('Create Key Pair for Ansible') { + steps { + echo "Creating Key Pair for ${APP_NAME} App" + sh "aws ec2 create-key-pair --region ${AWS_REGION} --key-name ${CFN_KEYPAIR} --query KeyMaterial --output text > ${CFN_KEYPAIR}" + sh "chmod 400 ${CFN_KEYPAIR}" + } + } + stage('Create QA Automation Infrastructure') { + steps { + echo 'Creating QA Automation Infrastructure for Dev Environment with Cloudfomation' + sh "aws cloudformation create-stack --region ${AWS_REGION} --stack-name ${APP_STACK_NAME} --capabilities CAPABILITY_IAM --template-body file://${CFN_TEMPLATE} --parameters ParameterKey=KeyPairName,ParameterValue=${CFN_KEYPAIR}" + script { + while(true) { + echo "Docker Grand Master is not UP and running yet. Will try to reach again after 10 seconds..." + sleep(10) + ip = sh(script:"aws ec2 describe-instances --region ${AWS_REGION} --filters Name=tag-value,Values=grand-master Name=tag-value,Values=${APP_STACK_NAME} --query Reservations[*].Instances[*].[PublicIpAddress] --output text", returnStdout:true).trim() + if (ip.length() >= 7) { + echo "Docker Grand Master Public Ip Address Found: $ip" + env.GRAND_MASTER_PUBLIC_IP = "$ip" + break + } + } + while(true) { + try{ + sh "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${WORKSPACE}/${CFN_KEYPAIR} ec2-user@${GRAND_MASTER_PUBLIC_IP} hostname" + echo "Docker Grand Master is reachable with SSH." + break + } + catch(Exception){ + echo "Could not connect to Docker Grand Master with SSH, I will try again in 10 seconds" + sleep(10) + } + } + } + } + } + stage('Create Docker Swarm for QA Automation Build') { + steps { + echo "Setup Docker Swarm for QA Automation Build for ${APP_NAME} App" + echo "Update dynamic environment" + sh "sed -i 's/APP_STACK_NAME/${APP_STACK_NAME}/' ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml" + echo "Swarm Setup for all nodes (instances)" + sh "ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_setup_for_all_docker_swarm_instances.yaml" + echo "Swarm Setup for Grand Master node" + sh "ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_initialize_docker_swarm.yaml" + echo "Swarm Setup for Other Managers nodes" + sh "ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_join_docker_swarm_managers.yaml" + echo "Swarm Setup for Workers nodes" + sh "ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_join_docker_swarm_workers.yaml" + } + } + stage('Deploy App on Docker Swarm'){ + steps { + echo 'Deploying App on Swarm' + sh 'envsubst < docker-compose-swarm-dev.yml > docker-compose-swarm-dev-tagged.yml' + sh 'ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b --extra-vars "workspace=${WORKSPACE} app_name=${APP_NAME} aws_region=${AWS_REGION} ecr_registry=${ECR_REGISTRY}" ./ansible/playbooks/pb_deploy_app_on_docker_swarm.yaml' + } + } + stage('Test the Application Deployment'){ + steps { + echo "Check if the ${APP_NAME} app is ready or not" + script { + while(true) { + try{ + sh "curl -s ${GRAND_MASTER_PUBLIC_IP}:8080" + echo "${APP_NAME} app is successfully deployed." + break + } + catch(Exception){ + echo "Could not connect to ${APP_NAME} app" + sleep(5) + } + } + } + } + } + stage('Run QA Automation Tests'){ + steps { + echo "Run the Selenium Functional Test on QA Environment" + sh 'ansible-playbook -vvv --connection=local --inventory 127.0.0.1, --extra-vars "workspace=${WORKSPACE} master_public_ip=${GRAND_MASTER_PUBLIC_IP}" ./ansible/playbooks/pb_run_selenium_jobs.yaml' + } + } + } + post { + always { + echo 'Deleting all local images' + sh 'docker image prune -af' + echo 'Delete the Image Repository on ECR' + sh """ + aws ecr delete-repository \ + --repository-name ${APP_REPO_NAME} \ + --region ${AWS_REGION}\ + --force + """ + echo 'Tear down the Docker Swarm infrastructure using AWS CLI' + sh "aws cloudformation delete-stack --region ${AWS_REGION} --stack-name ${APP_STACK_NAME}" + echo "Delete existing key pair using AWS CLI" + sh "aws ec2 delete-key-pair --region ${AWS_REGION} --key-name ${CFN_KEYPAIR}" + sh "rm -rf ${CFN_KEYPAIR}" + } + } +} \ No newline at end of file diff --git a/selenium-jobs/test_owners_all_headless.py b/selenium-jobs/test_owners_all_headless.py index 4db808e66..97fd71148 100644 --- a/selenium-jobs/test_owners_all_headless.py +++ b/selenium-jobs/test_owners_all_headless.py @@ -3,13 +3,18 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from time import sleep +import os # Set chrome options for working with headless mode (no screen) chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("headless") +chrome_options.add_argument("no-sandbox") +chrome_options.add_argument("disable-dev-shm-usage") # Update webdriver instance of chrome-driver with adding chrome options -driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) +driver = webdriver.Chrome(options=chrome_options) # Connect to the application -url = "ec2-18-232-125-248.compute-1.amazonaws.com:8080" +APP_IP = os.environ['MASTER_PUBLIC_IP'] +url = "http://"+APP_IP.strip()+":8080/" +print(url) driver.get(url) owners_link = driver.find_element_by_link_text("OWNERS") owners_link.click() diff --git a/selenium-jobs/test_owners_register_headless.py b/selenium-jobs/test_owners_register_headless.py index 11c697827..1ab2f2daf 100644 --- a/selenium-jobs/test_owners_register_headless.py +++ b/selenium-jobs/test_owners_register_headless.py @@ -1,24 +1,28 @@ from selenium import webdriver -from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC +from time import sleep import random +import os # Set chrome options for working with headless mode (no screen) chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("headless") +chrome_options.add_argument("no-sandbox") +chrome_options.add_argument("disable-dev-shm-usage") # Update webdriver instance of chrome-driver with adding chrome options -driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) +driver = webdriver.Chrome(options=chrome_options) # Connect to the application -url = "ec2-18-232-125-248.compute-1.amazonaws.com:8080" +APP_IP = os.environ['MASTER_PUBLIC_IP'] +url = "http://"+APP_IP.strip()+":8080/" +print(url) driver.get(url) owners_link = driver.find_element_by_link_text("OWNERS") owners_link.click() all_link = driver.find_element_by_link_text("REGISTER") all_link.click() +sleep(2) # Register new Owner to Petclinic App fn_field = driver.find_element_by_name('firstName') -fn = 'Callahan' + str(random.randint(0, 100)) +fn = 'Vildan' + str(random.randint(0, 100)) fn_field.send_keys(fn) fn_field = driver.find_element_by_name('lastName') fn_field.send_keys('Clarusway') @@ -29,8 +33,8 @@ fn_field = driver.find_element_by_name('telephone') fn_field.send_keys('+1230576803') fn_field.send_keys(Keys.ENTER) -# Wait until Owner List table loaded -verify_table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "table"))) +# Wait 1 second to get updated Owner List +sleep(2) # Verify that new user is added to Owner List if fn in driver.page_source: print(fn, 'is added and found in the Owners Table') diff --git a/selenium-jobs/test_veterinarians_headless.py b/selenium-jobs/test_veterinarians_headless.py index 36dfc2107..fc6958c3c 100644 --- a/selenium-jobs/test_veterinarians_headless.py +++ b/selenium-jobs/test_veterinarians_headless.py @@ -3,32 +3,18 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from time import sleep +import os # Set chrome options for working with headless mode (no screen) chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("headless") +chrome_options.add_argument("no-sandbox") +chrome_options.add_argument("disable-dev-shm-usage") # Update webdriver instance of chrome-driver with adding chrome options -driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) +driver = webdriver.Chrome(options=chrome_options) # Connect to the application -url = "from selenium import webdriver -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC -from time import sleep -# Set chrome options for working with headless mode (no screen) -chrome_options = webdriver.ChromeOptions() -chrome_options.add_argument("headless") -# Update webdriver instance of chrome-driver with adding chrome options -driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options) -# Connect to the application -url = "ec2-18-232-125-248.compute-1.amazonaws.com:8080" -driver.get(url) -vet_link = driver.find_element_by_link_text("VETERINARIANS") -vet_link.click() -# Verify that table loaded -sleep(1) -verify_table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "table"))) -print("Table loaded") -driver.quit():8080" +APP_IP = os.environ['MASTER_PUBLIC_IP'] +url = "http://"+APP_IP.strip()+":8080/" +print(url) driver.get(url) vet_link = driver.find_element_by_link_text("VETERINARIANS") vet_link.click() From 86df8282bb9e7a38f156907653d60c5ef5000f1a Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sat, 24 Oct 2020 21:07:09 -0400 Subject: [PATCH 37/39] added qa automation pipeline for dev --- jenkins/jenkinsfile-petclinic-nightly | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jenkins/jenkinsfile-petclinic-nightly b/jenkins/jenkinsfile-petclinic-nightly index 712e985a0..b7b627627 100644 --- a/jenkins/jenkinsfile-petclinic-nightly +++ b/jenkins/jenkinsfile-petclinic-nightly @@ -8,7 +8,7 @@ pipeline { AWS_ACCOUNT_ID=sh(script:'export PATH="$PATH:/usr/local/bin" && aws sts get-caller-identity --query Account --output text', returnStdout:true).trim() AWS_REGION="us-east-1" ECR_REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" - CFN_KEYPAIR="call-${APP_NAME}-dev-${BUILD_NUMBER}.key" + CFN_KEYPAIR="vil-${APP_NAME}-dev-${BUILD_NUMBER}.key" CFN_TEMPLATE="./infrastructure/dev-docker-swarm-infrastructure-cfn-template.yml" ANSIBLE_PRIVATE_KEY_FILE="${WORKSPACE}/${CFN_KEYPAIR}" ANSIBLE_HOST_KEY_CHECKING="False" @@ -81,11 +81,14 @@ pipeline { steps { echo 'Creating QA Automation Infrastructure for Dev Environment with Cloudfomation' sh "aws cloudformation create-stack --region ${AWS_REGION} --stack-name ${APP_STACK_NAME} --capabilities CAPABILITY_IAM --template-body file://${CFN_TEMPLATE} --parameters ParameterKey=KeyPairName,ParameterValue=${CFN_KEYPAIR}" + script { while(true) { echo "Docker Grand Master is not UP and running yet. Will try to reach again after 10 seconds..." sleep(10) + ip = sh(script:"aws ec2 describe-instances --region ${AWS_REGION} --filters Name=tag-value,Values=grand-master Name=tag-value,Values=${APP_STACK_NAME} --query Reservations[*].Instances[*].[PublicIpAddress] --output text", returnStdout:true).trim() + if (ip.length() >= 7) { echo "Docker Grand Master Public Ip Address Found: $ip" env.GRAND_MASTER_PUBLIC_IP = "$ip" @@ -106,6 +109,7 @@ pipeline { } } } + stage('Create Docker Swarm for QA Automation Build') { steps { echo "Setup Docker Swarm for QA Automation Build for ${APP_NAME} App" @@ -121,6 +125,7 @@ pipeline { sh "ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b ./ansible/playbooks/pb_join_docker_swarm_workers.yaml" } } + stage('Deploy App on Docker Swarm'){ steps { echo 'Deploying App on Swarm' @@ -128,10 +133,12 @@ pipeline { sh 'ansible-playbook -i ./ansible/inventory/dev_stack_dynamic_inventory_aws_ec2.yaml -b --extra-vars "workspace=${WORKSPACE} app_name=${APP_NAME} aws_region=${AWS_REGION} ecr_registry=${ECR_REGISTRY}" ./ansible/playbooks/pb_deploy_app_on_docker_swarm.yaml' } } + stage('Test the Application Deployment'){ steps { echo "Check if the ${APP_NAME} app is ready or not" script { + while(true) { try{ sh "curl -s ${GRAND_MASTER_PUBLIC_IP}:8080" @@ -146,6 +153,7 @@ pipeline { } } } + stage('Run QA Automation Tests'){ steps { echo "Run the Selenium Functional Test on QA Environment" @@ -153,6 +161,7 @@ pipeline { } } } + post { always { echo 'Deleting all local images' From 8b70c3d07e976d2c72c5eb1a3287629198004cde Mon Sep 17 00:00:00 2001 From: vildan71 Date: Wed, 9 Dec 2020 00:43:31 -0500 Subject: [PATCH 38/39] added qa automation pipeline for dev --- jenkins/jenkinsfile-petclinic-nightly | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/jenkinsfile-petclinic-nightly b/jenkins/jenkinsfile-petclinic-nightly index b7b627627..a60b6ae6c 100644 --- a/jenkins/jenkinsfile-petclinic-nightly +++ b/jenkins/jenkinsfile-petclinic-nightly @@ -3,8 +3,8 @@ pipeline { environment { PATH=sh(script:"echo $PATH:/usr/local/bin", returnStdout:true).trim() APP_NAME="petclinic" - APP_STACK_NAME="Vildan-${APP_NAME}-app-${BUILD_NUMBER}" - APP_REPO_NAME="vildan71/${APP_NAME}-app-dev" + APP_STACK_NAME="vildan-${APP_NAME}-app-${BUILD_NUMBER}" + APP_REPO_NAME="vildan71/microservices-ci-cd-pipeline-with-petclinic-app" AWS_ACCOUNT_ID=sh(script:'export PATH="$PATH:/usr/local/bin" && aws sts get-caller-identity --query Account --output text', returnStdout:true).trim() AWS_REGION="us-east-1" ECR_REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" From 001da80304c7cea2ceab44eb90147173cd49b0fc Mon Sep 17 00:00:00 2001 From: vildan71 Date: Sun, 13 Dec 2020 15:29:07 -0500 Subject: [PATCH 39/39] updated selenium jobs --- ...y_selenium_job.sh => run_dummy_selenium_jobs.sh} | 0 selenium-jobs/test_owners_all_headless.py | 8 ++++++++ selenium-jobs/test_owners_register_headless.py | 13 +++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) rename ansible/scripts/{run_dummy_selenium_job.sh => run_dummy_selenium_jobs.sh} (100%) diff --git a/ansible/scripts/run_dummy_selenium_job.sh b/ansible/scripts/run_dummy_selenium_jobs.sh similarity index 100% rename from ansible/scripts/run_dummy_selenium_job.sh rename to ansible/scripts/run_dummy_selenium_jobs.sh diff --git a/selenium-jobs/test_owners_all_headless.py b/selenium-jobs/test_owners_all_headless.py index 97fd71148..f95d423ad 100644 --- a/selenium-jobs/test_owners_all_headless.py +++ b/selenium-jobs/test_owners_all_headless.py @@ -4,13 +4,16 @@ from selenium.webdriver.support import expected_conditions as EC from time import sleep import os + # Set chrome options for working with headless mode (no screen) chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("headless") chrome_options.add_argument("no-sandbox") chrome_options.add_argument("disable-dev-shm-usage") + # Update webdriver instance of chrome-driver with adding chrome options driver = webdriver.Chrome(options=chrome_options) + # Connect to the application APP_IP = os.environ['MASTER_PUBLIC_IP'] url = "http://"+APP_IP.strip()+":8080/" @@ -18,10 +21,15 @@ driver.get(url) owners_link = driver.find_element_by_link_text("OWNERS") owners_link.click() +sleep(2) all_link = driver.find_element_by_link_text("ALL") all_link.click() +sleep(2) + # Verify that table loaded sleep(1) verify_table = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "table"))) + print("Table loaded") + driver.quit() \ No newline at end of file diff --git a/selenium-jobs/test_owners_register_headless.py b/selenium-jobs/test_owners_register_headless.py index 1ab2f2daf..6f86c778d 100644 --- a/selenium-jobs/test_owners_register_headless.py +++ b/selenium-jobs/test_owners_register_headless.py @@ -8,8 +8,10 @@ chrome_options.add_argument("headless") chrome_options.add_argument("no-sandbox") chrome_options.add_argument("disable-dev-shm-usage") + # Update webdriver instance of chrome-driver with adding chrome options driver = webdriver.Chrome(options=chrome_options) + # Connect to the application APP_IP = os.environ['MASTER_PUBLIC_IP'] url = "http://"+APP_IP.strip()+":8080/" @@ -17,23 +19,30 @@ driver.get(url) owners_link = driver.find_element_by_link_text("OWNERS") owners_link.click() +sleep(2) all_link = driver.find_element_by_link_text("REGISTER") all_link.click() sleep(2) # Register new Owner to Petclinic App fn_field = driver.find_element_by_name('firstName') -fn = 'Vildan' + str(random.randint(0, 100)) +fn = 'Callahan' + str(random.randint(0, 100)) fn_field.send_keys(fn) +sleep(1) fn_field = driver.find_element_by_name('lastName') fn_field.send_keys('Clarusway') +sleep(1) fn_field = driver.find_element_by_name('address') fn_field.send_keys('Ridge Corp. Street') +sleep(1) fn_field = driver.find_element_by_name('city') fn_field.send_keys('McLean') +sleep(1) fn_field = driver.find_element_by_name('telephone') fn_field.send_keys('+1230576803') +sleep(1) fn_field.send_keys(Keys.ENTER) -# Wait 1 second to get updated Owner List +sleep(1) +# Wait 2 second to get updated Owner List sleep(2) # Verify that new user is added to Owner List if fn in driver.page_source: