diff --git a/.env.example b/.env.example index 5f9c6b4..d0934a3 100644 --- a/.env.example +++ b/.env.example @@ -8,3 +8,4 @@ USER_AVATAR_FOLDER_NAME= BUCKET_NAME= AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= +FRONTEND_URL= \ No newline at end of file diff --git a/auth-config.yml b/auth-config.yml new file mode 100644 index 0000000..36ec5fc --- /dev/null +++ b/auth-config.yml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: auth-config +data: + mysql-url: jdbc:mysql://13.233.137.1:3306/bookmysport + user-avatar-folder-name: UserAvatars + bucket-name: bookmysport.com + front-end-url: http://13.233.137.1:5173 diff --git a/auth-secret.yml b/auth-secret.yml new file mode 100644 index 0000000..9dc3583 --- /dev/null +++ b/auth-secret.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Secret +metadata: + name: auth-secret +data: + mysql-user: YW5hbmRh + mysql-password: Ym9va215c3BvcnQ= + auth-username: dm9ydGV4MTY0OUBnbWFpbC5jb20= + auth-password: bG5teSBydHNnIHRtdHYga3h0YQ== + auth-secret-key: U0VDUkVUS0VZU0VDUkVUS0VZU0VDUkVUS0VZU0VDUkVUS0VZU0VDUkVUS0VZU0VDUkVUS0VZU0VDUkVUS0VZ + aws-access-key-id: QUtJQVczTUVBU0NWRlpWR0s0V0Q= + aws-secret-key: ai81NXBtU0F1ZlJJbFdLMmRjai9pelhIdll6eHhNbWh6eWFzVkxkcA== \ No newline at end of file diff --git a/auth-service.yml b/auth-service.yml new file mode 100644 index 0000000..96dfbb4 --- /dev/null +++ b/auth-service.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: auth-service +spec: + type: LoadBalancer + selector: + app: auth + ports: + - protocol: TCP + port: 80 + targetPort: 8090 \ No newline at end of file diff --git a/authentication-service.yml b/authentication-service.yml new file mode 100644 index 0000000..44c187f --- /dev/null +++ b/authentication-service.yml @@ -0,0 +1,78 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: authentication-service-deployment + labels: + app: auth +spec: + replicas: 2 + selector: + matchLabels: + app: auth + template: + metadata: + labels: + app: auth + spec: + containers: + - name: auth + image: 471112650922.dkr.ecr.ap-south-1.amazonaws.com/authentication-service:latest + ports: + - containerPort: 8090 + env: + - name: DATABASE_URL + valueFrom: + configMapKeyRef: + name: auth-config + key: mysql-url + - name: USERNAME + valueFrom: + secretKeyRef: + name: auth-secret + key: mysql-user + - name: PASSWORD + valueFrom: + secretKeyRef: + name: auth-secret + key: mysql-password + - name: ADMIN_USERNAME + valueFrom: + secretKeyRef: + name: auth-secret + key: auth-username + - name: ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: auth-secret + key: auth-password + - name: SECRET_KEY + valueFrom: + secretKeyRef: + name: auth-secret + key: auth-secret-key + - name: USER_AVATAR_FOLDER_NAME + valueFrom: + configMapKeyRef: + name: auth-config + key: user-avatar-folder-name + - name: BUCKET_NAME + valueFrom: + configMapKeyRef: + name: auth-config + key: bucket-name + - name: FRONTEND_URL + valueFrom: + configMapKeyRef: + name: auth-config + key: front-end-url + - name: AWS_ACCESS_KEY_ID + valueFrom: + secretKeyRef: + name: auth-secret + key: aws-access-key-id + - name: AWS_SECRET_ACCESS_KEY + valueFrom: + secretKeyRef: + name: auth-secret + key: aws-secret-key + diff --git a/cicd-pipeline.yml b/cicd-pipeline.yml new file mode 100644 index 0000000..ca017b9 --- /dev/null +++ b/cicd-pipeline.yml @@ -0,0 +1,63 @@ +version: 0.2 +run-as: root + +phases: + + install: + commands: + - echo Installing app dependencies... + - curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.29.3/2024-04-19/bin/linux/amd64/kubectl + - curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.29.3/2024-04-19/bin/linux/amd64/kubectl.sha256 + - sha256sum -c kubectl.sha256 + - openssl sha1 -sha256 kubectl + - chmod +x ./kubectl + - mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH + - echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc + - source ~/.bashrc + - echo 'Check kubectl version' + - kubectl version --client + - echo "AWS Version Check successfully" + - aws --version + + pre_build: + commands: + - echo Uploading aws credentials + - aws configure set aws_access_key_id $YOUR_ACCESS_KEY_ID + - aws configure set aws_secret_access_key $YOUR_SECRET_ACCESS_KEY + - echo Logging in to Amazon EKS... + - aws eks update-kubeconfig --region $AWS_DEFAULT_REGION --name $AWS_CLUSTER_NAME + - echo check config + - kubectl config view --minify + - echo check kubectl access + - kubectl get svc + - echo Logging in to Amazon ECR... + - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com + - REPOSITORY_URI=$ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME + - docker pull $REPOSITORY_URI:$IMAGE_TAG + + + build: + commands: + - echo Build started on `date` + - echo Building the Docker image... + - docker build --cache-from $REPOSITORY_URI:$IMAGE_TAG -t $IMAGE_REPO_NAME:$IMAGE_TAG . + - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG + + post_build: + commands: + - echo Build completed on `date` + - echo Pushing the Docker image... + - docker push $ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG + - echo Push the latest image to cluster + - echo Setting up the database url + - sed -i 's|${MYSQL_URL}|http://$DATABASE_IP:3306/$DATABASE_NAME|g' auth-config.yml + - echo Setting up the PORT + - sed -i 's|${PORT}|$PORT|g' auth-service.yml + - kubectl apply -f auth-config.yml + - kubectl apply -f auth-secret.yml + - kubectl apply -f authentication-service.yml + - kubectl apply -f auth-service.yml + - kubectl rollout restart -f authentication-service.yml + - echo Deployed successfully + - echo Checking kubectl status + - kubectl get all \ No newline at end of file diff --git a/src/main/java/com/bookmysport/authentication_service/UserServices/UserService.java b/src/main/java/com/bookmysport/authentication_service/UserServices/UserService.java index d60cec3..27185b3 100644 --- a/src/main/java/com/bookmysport/authentication_service/UserServices/UserService.java +++ b/src/main/java/com/bookmysport/authentication_service/UserServices/UserService.java @@ -73,8 +73,8 @@ public ResponseEntity generateOTPforTwoFAService(UserModel userModel) { String response = emailService.sendSimpleMail(userModel.getEmail(), "Your OTP for Two-Factor Authentication is " + otpForTwoFA - + " . It is valid only for 5 minutes.", - "OTP for Two-Factor Authentication"); + + " . It is valid only for 2 minutes.", + "OTP for Two-Factor Authentication valid for 2 minutes"); otpRepo.save(otp); responseMessage.setSuccess(true); responseMessage.setMessage(response); @@ -105,8 +105,8 @@ public ResponseEntity generateOTPforTwoFAServiceProviderService(ServiceP String response = emailService.sendSimpleMail(serviceProviderModel.getEmail(), "Your OTP for Two-Factor Authentication is " + otpForTwoFA - + " . It is valid only for 5 minutes.", - "OTP for Two-Factor Authentication"); + + " . It is valid only for 2 minutes.", + "OTP for Two-Factor Authentication and valid for 2 minutes"); responseMessage.setSuccess(true); responseMessage.setMessage(response); otpRepo.save(otp); @@ -304,7 +304,7 @@ public ResponseEntity sendingEmailService(String email, String role) { String response = emailService.sendSimpleMail(email, "Your OTP for resetting your password is " + Integer.toString(otp) - + ". It is valid only for 5 minutes.", + + ". It is valid only for 2 minutes.", "OTP for Resetting your password"); responseMessage.setSuccess(true); responseMessage.setMessage(response); @@ -327,7 +327,7 @@ public ResponseEntity sendingEmailService(String email, String role) { String response = emailService.sendSimpleMail(email, "Your OTP for resetting your password is " + Integer.toString(otp) - + ". It is valid only for 5 minutes.", + + ". It is valid only for 2 minutes.", "OTP for Resetting your password"); responseMessage.setSuccess(true); responseMessage.setMessage(response);