-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Sunbird-Serve/release-need-1.1.0.0
Release need 1.1.0.0 to main
- Loading branch information
Showing
97 changed files
with
2,444 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
name: Deploy to Amazon ECS | ||
|
||
on: | ||
push: | ||
branches: ["main", "release-*"] | ||
#pull_request: | ||
# The branches below must be a subset of the branches above | ||
#branches: [ "main" ] | ||
|
||
env: | ||
AWS_REGION: ${{ github.ref == 'refs/heads/main' && 'us-east-1' || startsWith(github.ref, 'refs/heads/release-') && 'ap-south-1' }} | ||
ECR_REPOSITORY: sunbird-serve-need # set this to your Amazon ECR repository name | ||
ECS_SERVICE: sunbird-serve-need # set this to your Amazon ECS service name | ||
ECS_CLUSTER: ${{ github.ref == 'refs/heads/main' && 'ecs-staging' || startsWith(github.ref, 'refs/heads/release-') && 'ecs-production' }} | ||
ECS_TASK_DEFINITION: | ||
.github/workflows/task-definition.json # set this to the path to your Amazon ECS task definition | ||
# file, e.g. .aws/task-definition.json | ||
CONTAINER_NAME: | ||
sunbird-serve-need # set this to the name of the container in the | ||
# containerDefinitions section of your task definition | ||
SHELL_SCRIPT_NAME: .github/workflows/create-json.sh | ||
PYTHON_FILE_NAME: .github/workflows/replace-secrets.py | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
#environment: ${{ github.ref == 'refs/heads/main' && 'stage-' || github.ref == 'refs/heads/release-' && '' }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set environment variables for the "release-" branch | ||
run: | | ||
if [ "${GITHUB_REF##*/}" = "release-" ]; then | ||
echo "Setting environment variables for release- branch" | ||
echo "environment=stage-" >> $GITHUB_ENV | ||
else | ||
echo "release- branch not detected. No environment variables to set." | ||
fi | ||
- name: Shell script to create JSON | ||
run: | | ||
chmod +x ${{ env.SHELL_SCRIPT_NAME }} | ||
${{ env.SHELL_SCRIPT_NAME }} | ||
shell: bash | ||
|
||
- name: Dump older task definition | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
run: | | ||
aws ecs describe-task-definition --region ${{ env.AWS_REGION }} --task-definition ${{ env.ECS_SERVICE }} --query taskDefinition > .github/workflows/task-definition.json | ||
aws ecs list-clusters --region ${{ env.AWS_REGION }} | ||
cat .github/workflows/task-definition.json | ||
- name: Python to update TD | ||
run: python ${{ env.PYTHON_FILE_NAME }} | ||
|
||
- name: Print new task definition | ||
run: | | ||
cat .github/workflows/task-definition.json | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
- name: Fill in the new image ID in the Amazon ECS task definition | ||
id: task-def | ||
uses: aws-actions/amazon-ecs-render-task-definition@v1 | ||
with: | ||
task-definition: ${{ env.ECS_TASK_DEFINITION }} | ||
container-name: ${{ env.CONTAINER_NAME }} | ||
image: ${{ steps.build-image.outputs.image }} | ||
|
||
- name: Deploy Amazon ECS task definition | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
service: ${{ env.ECS_SERVICE }} | ||
cluster: ${{ env.ECS_CLUSTER }} | ||
wait-for-service-stability: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#/bin/bash | ||
account_id=049302583731 | ||
if [ -f /tmp/__secrets.json ] ; then | ||
rm -f /tmp/__secrets.json | ||
fi | ||
|
||
branch_name=${GITHUB_REF#refs/heads/} | ||
echo $branch_name | ||
|
||
if [ "$branch_name" == "main" ] ; then | ||
prefix=stage | ||
#region="ap-south-1" | ||
elif [ "$branch_name" == "release" ] ; then | ||
prefix=prod | ||
#region=us-east-1 | ||
fi | ||
printf '{ | ||
"secrets": [' > /tmp/__secrets.json | ||
|
||
|
||
for line in `cat .${prefix}env` | ||
do | ||
key=$line | ||
if [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]]; then | ||
continue | ||
fi | ||
echo "{ | ||
"'"name"'": "'"'$key'"'", | ||
"'"valueFrom"'": "'"'"arn:aws:ssm:ap-south-1:$account_id:parameter/$key"'"'" | ||
}," >> /tmp/__secrets.json | ||
done | ||
sed '$ s/,$//' /tmp/__secrets.json > .github/workflows/secrets.json | ||
|
||
echo ']}' >> .github/workflows/secrets.json | ||
|
||
cat .github/workflows/secrets.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import json | ||
|
||
original_taskdef = ".github/workflows/task-definition.json" | ||
secrets_array = ".github/workflows/secrets.json" | ||
|
||
|
||
with open(original_taskdef, 'r') as file: | ||
task_definition = json.load(file) | ||
|
||
for item in task_definition: | ||
if "containerDefinitions" in item: | ||
containerDefinitions = task_definition['containerDefinitions'] | ||
for item in containerDefinitions: | ||
if "secrets" in item: | ||
print("secret block exists") | ||
# print(json.dumps(containerDefinitions[0]['secrets'], indent=4)) # if want to print | ||
|
||
|
||
with open(secrets_array, 'r') as new_file: | ||
new_data = json.load(new_file) | ||
new_secrets = new_data['secrets'] | ||
# print(json.dumps(new_secrets, indent=4)) | ||
|
||
# __task_definition = task_definition["taskDefinition"] | ||
# __secrets_to_replace = __task_definition["containerDefinitions"] | ||
# secrets_to_replace = __secrets_to_replace[0]["secrets"] | ||
# __secrets_to_replace[0]["secrets"] = new_secrets | ||
|
||
|
||
__secrets_to_replace = task_definition['containerDefinitions'] | ||
secrets_to_replace = __secrets_to_replace[0]['secrets'] | ||
__secrets_to_replace[0]['secrets'] = new_secrets | ||
|
||
# task_definition['secrets'] = new_secrets #replace old secrets block with new_secrets | ||
|
||
|
||
print(json.dumps(task_definition, indent=4)) | ||
|
||
|
||
# writing to new file | ||
with open(".github/workflows/task-definition.json", 'w') as outfile: | ||
json.dump(task_definition, outfile, indent=4) | ||
|
||
print("Updated JSON has been written to new_task_definition.json file.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#Fri Dec 01 16:04:51 IST 2023 | ||
gradle.version=8.5 |
Binary file not shown.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM gradle:7.6.0-jdk17 as build | ||
|
||
COPY --chown=gradle:gradle . /home/gradle/src | ||
WORKDIR /home/gradle/src | ||
COPY . /home/gradle/src | ||
|
||
#RUN gradle build -x test | ||
#RUN gradle build --debug | ||
RUN gradle build | ||
|
||
|
||
# TODO: check slim version of eclipse-temurin:17 and update it here | ||
FROM eclipse-temurin:17 | ||
RUN mkdir /usr/src/app | ||
COPY --from=build /home/gradle/src/build/libs/*SNAPSHOT.war /usr/src/app/app.war | ||
USER root | ||
|
||
EXPOSE 9000 | ||
RUN apt-get update | ||
RUN apt-get -y upgrade | ||
RUN apt-get install curl | ||
|
||
CMD ["java", "-jar", "/usr/src/app/app.war"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+7.02 KB
build/classes/java/main/com/sunbird/serve/need/NeedDiscoveryController.class
Binary file not shown.
Binary file added
BIN
+2.18 KB
build/classes/java/main/com/sunbird/serve/need/NeedDiscoveryRepository.class
Binary file not shown.
Binary file added
BIN
+8.1 KB
build/classes/java/main/com/sunbird/serve/need/NeedDiscoveryService.class
Binary file not shown.
Binary file added
BIN
+781 Bytes
build/classes/java/main/com/sunbird/serve/need/NeedMicroServiceApplication.class
Binary file not shown.
Binary file added
BIN
+5.84 KB
build/classes/java/main/com/sunbird/serve/need/NeedTypeDiscoveryController.class
Binary file not shown.
Binary file added
BIN
+1.42 KB
build/classes/java/main/com/sunbird/serve/need/NeedTypeDiscoveryRepository.class
Binary file not shown.
Binary file added
BIN
+2.47 KB
build/classes/java/main/com/sunbird/serve/need/NeedTypeDiscoveryService.class
Binary file not shown.
Binary file added
BIN
+945 Bytes
build/classes/java/main/com/sunbird/serve/need/ServletInitializer.class
Binary file not shown.
Binary file added
BIN
+3.4 KB
build/classes/java/main/com/sunbird/serve/need/models/Need/Need$NeedBuilder.class
Binary file not shown.
Binary file added
BIN
+7.72 KB
build/classes/java/main/com/sunbird/serve/need/models/Need/Need.class
Binary file not shown.
Binary file added
BIN
+3.7 KB
build/classes/java/main/com/sunbird/serve/need/models/Need/NeedType$NeedTypeBuilder.class
Binary file not shown.
Binary file added
BIN
+8.01 KB
build/classes/java/main/com/sunbird/serve/need/models/Need/NeedType.class
Binary file not shown.
Binary file added
BIN
+1.47 KB
build/classes/java/main/com/sunbird/serve/need/models/enums/NeedStatus.class
Binary file not shown.
Binary file added
BIN
+1.28 KB
build/classes/java/main/com/sunbird/serve/need/models/enums/NeedTypeStatus.class
Binary file not shown.
Binary file added
BIN
+1.24 KB
build/classes/java/main/com/sunbird/serve/need/models/enums/TaskType.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.sunbird.serve.need.NeedMicroServiceApplication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
server.port=9090 | ||
|
||
# Evean db end point | ||
spring.datasource.url=jdbc:postgresql://postgres-db.cmwxiaefrrfi.ap-south-1.rds.amazonaws.com:5432/postgres | ||
# Ekal db end point | ||
#spring.datasource.url=jdbc:postgresql://postgres-db.civ7kwpwucar.ap-south-1.rds.amazonaws.com:5432/postgres | ||
spring.datasource.username=postgres | ||
spring.datasource.password=23798ak3fr3409k58t4 | ||
|
||
spring.jpa.show-sql=true | ||
spring.jpa.database=POSTGRESQL | ||
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true | ||
|
||
server.error.include-exception=true | ||
server.error.include-stacktrace=always | ||
logging.level.com.sunbird.serve.need = TRACE | ||
server.servlet.context-path=/api/v1/ | ||
logging.pattern.console=%d [%level] %c{1.} [%t] %m%n | ||
logging.file = appLog.log | ||
logging.pattern.file=%d [%level] %c{1.} [%t] %m%n | ||
logging.level.reactor.netty.http.client.HttpClient: DEBUG |
Binary file not shown.
91 changes: 91 additions & 0 deletions
91
...java/com/sunbird/serve/need/DeliverableService/controllers/NeedDeliverableController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// NeedDeliverableController.java | ||
package com.sunbird.serve.need; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import com.sunbird.serve.need.models.Need.NeedDeliverable; | ||
import com.sunbird.serve.need.models.enums.NeedDeliverableStatus; | ||
import com.sunbird.serve.need.models.request.NeedDeliverableRequest; | ||
import org.springframework.http.HttpStatus; | ||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.*; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.Map; | ||
|
||
@RestController | ||
@CrossOrigin(origins = "*") | ||
public class NeedDeliverableController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(NeedDeliverableController.class); | ||
|
||
private final NeedDeliverableService needDeliverableService; | ||
|
||
public NeedDeliverableController(NeedDeliverableService needDeliverableService) { | ||
this.needDeliverableService = needDeliverableService; | ||
} | ||
|
||
//Fetch all needplan based on needId | ||
@Operation(summary = "Fetch Need Deliverable by providing NeedPlanId", description = "Fetch Need Deliverable by providing Need Plan Id") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Successfully Fetched Need Deliverable", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), | ||
@ApiResponse(responseCode = "400", description = "Bad Input"), | ||
@ApiResponse(responseCode = "500", description = "Server Error")} | ||
) | ||
@GetMapping("/need-deliverable/{needPlanId}") | ||
public ResponseEntity<List<NeedDeliverable>> getByNeedId(@PathVariable String needPlanId) { | ||
List<NeedDeliverable> needDeliverable = needDeliverableService.getByNeedPlanId(needPlanId); | ||
return ResponseEntity.ok(needDeliverable); | ||
} | ||
|
||
//Create Need Deliverable with Need Deliverable Request and Request Header | ||
@Operation(summary = "Create Need Deliverable", description = "Initiate the process of creating a Need Deliverable") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Successfully Created Need Deliverable", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), | ||
@ApiResponse(responseCode = "400", description = "Bad Input"), | ||
@ApiResponse(responseCode = "500", description = "Server Error")} | ||
) | ||
@PostMapping("/need-deliverable/create") | ||
public ResponseEntity<NeedDeliverable> createNeedDeliverable(@RequestBody NeedDeliverableRequest request, @RequestHeader Map<String, String> headers) { | ||
NeedDeliverable response = needDeliverableService.createNeedDeliverable(request, headers); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(response); | ||
} | ||
|
||
//Update Need Deliverable | ||
@Operation(summary = "Update a Need Deliverable with appropritate values", description = "Update an exsisting need deliverable") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "Successfully Updated Need Deliverable", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), | ||
@ApiResponse(responseCode = "400", description = "Bad Input"), | ||
@ApiResponse(responseCode = "500", description = "Server Error")} | ||
) | ||
@PutMapping("/need-deliverable/update/{needDeliverableId}") | ||
public ResponseEntity<NeedDeliverable> updateNeedDeliverable( | ||
@PathVariable UUID needDeliverableId, | ||
@RequestBody NeedDeliverableRequest request, | ||
@RequestHeader Map<String, String> headers) { | ||
|
||
NeedDeliverable updatedNeedDeliverable = needDeliverableService.updateNeedDeliverable(needDeliverableId, request, headers); | ||
return ResponseEntity.ok(updatedNeedDeliverable); | ||
} | ||
|
||
} |
Oops, something went wrong.