-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from ADPRO-C11/dev
Migration to Review Microservice
- Loading branch information
Showing
16 changed files
with
413 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,4 @@ | ||
PG_USER=postgres | ||
PG_PASSWORD=postgres | ||
PG_HOST=localhost | ||
PORT=8080 |
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,123 @@ | ||
name: Java CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: "temurin" | ||
java-version: "21" | ||
cache: "gradle" | ||
|
||
- name: Cache Gradle dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Make gradlew executable | ||
run: chmod +x ./gradlew | ||
- name: Build with Gradle | ||
run: | | ||
./gradlew assemble | ||
# (Optional) Add steps for running tests and generating reports | ||
|
||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: java-app | ||
path: build/libs/*.jar | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: "temurin" | ||
java-version: "21" | ||
cache: "gradle" | ||
- name: Make gradlew executable | ||
run: chmod +x ./gradlew | ||
- name: Cache Gradle dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.gradle/caches | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Test with Gradle | ||
run: | | ||
./gradlew check --info --stacktrace | ||
./gradlew test | ||
./gradlew jacocoTestReport | ||
# (Optional) Add steps for generating coverage report and other post-test tasks | ||
|
||
publish: | ||
name: Publish Docker Image | ||
runs-on: ubuntu-latest | ||
needs: test | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: check directory | ||
run: ls -al | ||
- name: Download Artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: java-app | ||
- name: check directory | ||
run: ls -al | ||
- name: Login to Docker Hub | ||
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.REGISTRY_USER }} --password-stdin docker.io | ||
- name: Set Docker BuildKit | ||
run: export DOCKER_BUILDKIT=1 | ||
- name: Build Docker Image | ||
run: | | ||
docker build --build-arg PRODUCTION=${{ secrets.PRODUCTION }} --build-arg JDBC_DATABASE_PASSWORD=${{ secrets.JDBC_DATABASE_PASSWORD }} --build-arg JDBC_DATABASE_URL=${{ secrets.JDBC_DATABASE_URL }} --build-arg JDBC_DATABASE_USERNAME=${{ secrets.JDBC_DATABASE_USERNAME }} -t ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }} . | ||
docker push ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }} | ||
deploy: | ||
name: Deploy to GCP | ||
runs-on: ubuntu-latest | ||
needs: publish | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install SSH client | ||
run: sudo apt-get install openssh-client | ||
|
||
- name: create ssh key | ||
run: echo "${{ secrets.SSH_KEY }}" > ssh-key.pem | ||
|
||
- name: update permission ssh key | ||
run: chmod 400 ssh-key.pem | ||
|
||
- name: Deploy to GCP | ||
run: | | ||
ssh -o StrictHostKeyChecking=no -i ssh-key.pem ${{ secrets.GCP_USERNAME }}@${{ secrets.GCP_STATIC_IP }} " | ||
sudo docker container rm -f ${{ secrets.CONTAINER_NAME }} || true && | ||
sudo docker image rm -f ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }} || true && | ||
sudo docker run --name ${{ secrets.CONTAINER_NAME }} -d -p 80:8080 ${{ secrets.REGISTRY_USER }}/${{ secrets.IMAGE_NAME }}:${{ secrets.IMAGE_TAG }}" |
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,16 @@ | ||
FROM gradle:jdk21-alpine | ||
ARG PRODUCTION | ||
ARG JDBC_DATABASE_PASSWORD | ||
ARG JDBC_DATABASE_URL | ||
ARG JDBC_DATABASE_USERNAME | ||
|
||
ENV PRODUCTION ${PRODUCTION} | ||
ENV JDBC_DATABASE_PASSWORD ${JDBC_DATABASE_PASSWORD} | ||
ENV JDBC_DATABASE_URL ${JDBC_DATABASE_URL} | ||
ENV JDBC_DATABASE_USERNAME ${JDBC_DATABASE_USERNAME} | ||
|
||
WORKDIR /app | ||
COPY ./review-0.0.1-SNAPSHOT.jar /app | ||
RUN ls -la | ||
EXPOSE 8080 | ||
CMD ["java","-jar","review-0.0.1-SNAPSHOT.jar"] |
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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/snackscription/review/controller/ReviewController.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,15 @@ | ||
package snackscription.review.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/") | ||
public class ReviewController { | ||
@GetMapping("") | ||
public ResponseEntity<String> reviewPage() { | ||
return ResponseEntity.ok().body("Welcome to the review service!"); | ||
} | ||
} |
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,39 @@ | ||
package snackscription.review.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.UUID; | ||
|
||
@Getter | ||
public class Review { | ||
private final String id; | ||
private int rating; | ||
@Setter | ||
private String content; | ||
@Setter | ||
private ReviewState state; | ||
private final String userId; | ||
private final String subscriptionBoxId; | ||
|
||
public Review(int rating, String content, String userId, String subscriptionBoxId) { | ||
this.id = UUID.randomUUID().toString(); | ||
this.rating = rating; | ||
this.content = content; | ||
this.state = new ReviewStatePending(this); | ||
this.userId = userId; | ||
this.subscriptionBoxId = subscriptionBoxId; | ||
} | ||
|
||
public void editReview(int rating, String content) { | ||
this.setRating(rating); | ||
this.setContent(content); | ||
} | ||
|
||
public void setRating(int rating) { | ||
if (rating < 0 || rating > 5) { | ||
throw new RuntimeException("Rating should be between 0 and 5."); | ||
} | ||
this.rating = rating; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/snackscription/review/model/ReviewState.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,13 @@ | ||
package snackscription.review.model; | ||
|
||
public abstract class ReviewState { | ||
Review review; | ||
String state; | ||
ReviewState(Review review) { | ||
this.review = review; | ||
} | ||
|
||
public abstract void approve(); | ||
|
||
public abstract void reject(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/snackscription/review/model/ReviewStateApproved.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,23 @@ | ||
package snackscription.review.model; | ||
|
||
public class ReviewStateApproved extends ReviewState { | ||
|
||
ReviewStateApproved(Review review) { | ||
super(review); | ||
} | ||
|
||
@Override | ||
public void approve() { | ||
throw new RuntimeException("Review already approved."); | ||
} | ||
|
||
@Override | ||
public void reject() { | ||
this.review.setState(new ReviewStateRejected(this.review)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Approved"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/snackscription/review/model/ReviewStatePending.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,23 @@ | ||
package snackscription.review.model; | ||
|
||
public class ReviewStatePending extends ReviewState { | ||
|
||
ReviewStatePending(Review review) { | ||
super(review); | ||
} | ||
|
||
@Override | ||
public void approve() { | ||
this.review.setState(new ReviewStateApproved(this.review)); | ||
} | ||
|
||
@Override | ||
public void reject() { | ||
this.review.setState(new ReviewStateRejected(this.review)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Pending"; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/snackscription/review/model/ReviewStateRejected.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,22 @@ | ||
package snackscription.review.model; | ||
|
||
public class ReviewStateRejected extends ReviewState { | ||
ReviewStateRejected(Review review) { | ||
super(review); | ||
} | ||
|
||
@Override | ||
public void approve() { | ||
this.review.setState(new ReviewStateApproved(this.review)); | ||
} | ||
|
||
@Override | ||
public void reject() { | ||
throw new RuntimeException("Review already rejected."); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Rejected"; | ||
} | ||
} |
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,7 @@ | ||
spring.datasource.url=jdbc:postgresql://aws-0-ap-southeast-1.pooler.supabase.com:5432/postgres | ||
spring.datasource.username=postgres | ||
spring.datasource.password=postgres | ||
spring.jpa.hibernate.ddl-auto=create-drop | ||
spring.jpa.show-sql=true | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.properties.hibernate.format_sql=true |
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,6 @@ | ||
spring.datasource.url=${JDBC_DATABASE_URL} | ||
spring.datasource.username=${JDBC_DATABASE_USERNAME} | ||
spring.datasource.password=${JDBC_DATABASE_PASSWORD} | ||
spring.jpa.hibernate.ddl-auto=update | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.properties.hibernate.format_sql=true |
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,7 @@ | ||
spring.datasource.url=jdbc:postgresql://aws-0-ap-southeast-1.pooler.supabase.com:5432/postgres | ||
spring.datasource.username=postgres | ||
spring.datasource.password=postgres | ||
spring.jpa.hibernate.ddl-auto=create | ||
spring.jpa.show-sql=true | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.properties.hibernate.format_sql=true |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
spring.application.name=review | ||
spring.profiles.active=${PRODUCTION:dev} |
Oops, something went wrong.