Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…erver-v2 into develop
  • Loading branch information
hyunihs committed Oct 21, 2024
2 parents 655de4e + dd95251 commit a378f26
Show file tree
Hide file tree
Showing 25 changed files with 418 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assignees: ''

---

# [Fix] <!--{ 작업 내용 }-->
# [Fix] <!--{ 작업 내용 }-->

### 📝 Description

Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Push to ECR

on:
push:
branches: [ "develop" ]

env:
AWS_REGION: ap-northeast-2
ECR_REGISTRY: 654654448479.dkr.ecr.ap-northeast-2.amazonaws.com
ECR_REPOSITORY: repick-repo
ZIP_FILE_NAME: deploy-package.zip

permissions:
contents: read

jobs:
build:
name: CI
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Make application-secret.yml and set secrets
run: |
mkdir -p ./src/main/resources
mkdir -p ./src/main/resources/key
if [ -f ./src/main/resources/application.yml ]; then
rm ./src/main/resources/application.yml
fi
touch ./src/main/resources/application.yml
touch ./src/main/resources/${{ secrets.APPLE_AUTH_KEY_ID }}.p8
echo "${{ secrets.APPLICATION_SECRET }}" > ./src/main/resources/application.yml
echo "${{ secrets.APPLE_AUTH_KEY }}" > ./src/main/resources/key/${{ secrets.APPLE_AUTH_KEY_ID }}.p8
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

## gradle build
- name: Build with Gradle
run: ./gradlew bootJar

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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@v2
with:
mask-password: true

- name: Build, tag, and push image to Amazon ECR
id: build-image
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY .
docker push $ECR_REGISTRY/$ECR_REPOSITORY
- name: Zip deployment files
run: |
zip -r ${{ env.ZIP_FILE_NAME }} ./aws/
- name: Upload AppSpec and scripts to S3
run: |
aws s3 cp ${{ env.ZIP_FILE_NAME }} s3://${{ secrets.S3_BUCKET }}/${{ env.ZIP_FILE_NAME }}
- name: Trigger CodeDeploy
run: |
aws deploy create-deployment \
--application-name repick-codedeploy-app \
--deployment-group-name repick-codedeploy-deployment-group \
--s3-location bucket=${{ secrets.S3_BUCKET }},bundleType=zip,key=${{ env.ZIP_FILE_NAME }} \
--file-exists-behavior OVERWRITE \
--ignore-application-stop-failures
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Push to ECR

on:
push:
branches: [ "develop" ]
branches: [ "legacy-githubactions" ]

env:
AWS_REGION: ap-northeast-2
Expand Down
20 changes: 20 additions & 0 deletions aws/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user
overwrite: yes
permissions:
- object: /home/ec2-user
pattern: "**"
owner: ec2-user
group: ec2-user
hooks:
ApplicationStop:
- location: kill_process.sh
timeout: 100
runas: ec2-user
ApplicationStart:
- location: start_process.sh
timeout: 3600
runas: ec2-user
41 changes: 41 additions & 0 deletions aws/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 0.2

env:
variables:
AWS_REGION: "ap-northeast-2"
ECR_REPOSITORY: "repick-repo:latest"

parameter-store:
ECR_REGISTRY: "ECR_REGISTRY"
APPLICATION_SECRET: "application-secrets"

phases:
install:
runtime-versions:
java: corretto17
pre_build:
commands:
- echo "Setting up resources and secrets"
- mkdir -p ./src/main/resources
- mkdir -p ./src/main/resources/key
- rm -f ./src/main/resources/application.yml
- touch ./src/main/resources/application.yml
build:
commands:
- echo "Building application with Gradle"
- ./gradlew bootJar
- echo "Building Docker image"
- docker build -t $ECR_REGISTRY/$ECR_REPOSITORY .

post_build:
commands:
- echo "Logging into Amazon ECR"
- aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
- echo "Pushing Docker image to Amazon ECR"
- docker push $ECR_REGISTRY/$ECR_REPOSITORY
artifacts:
files:
- appspec.yml
- kill_process.sh
- start_process.sh
discard-paths: yes
11 changes: 11 additions & 0 deletions aws/kill_process.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# 실행 중이거나 중지된 컨테이너 목록을 가져옴
containers=$(docker ps -qa)

# 컨테이너가 존재하면 삭제
if [ -n "$containers" ]; then
sudo docker rm -f $containers
else
echo "No containers to remove."
fi
15 changes: 15 additions & 0 deletions aws/start_process.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

ECR_REGISTRY=$(aws ssm get-parameter --name "ECR_REGISTRY" --with-decryption --region ap-northeast-2 --query "Parameter.Value" --output text)
ECR_DOCKER_TAG=latest

echo $ECR_REGISTRY
aws ecr get-login-password --region ap-northeast-2 | sudo docker login --username AWS --password-stdin $ECR_REGISTRY

sudo docker pull $ECR_REGISTRY:$ECR_DOCKER_TAG

sudo docker run -d --name dc -p 8080:8080 $ECR_REGISTRY:$ECR_DOCKER_TAG

sudo docker image prune -f
3 changes: 2 additions & 1 deletion dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM openjdk:17
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","/app.jar"]
ENTRYPOINT ["java","-jar","-Duser.timezone=Asia/Seoul","/app.jar"]

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ClothingSalesScheduler {
private final BagCollectRepository bagCollectRepository;
private final PushNotificationService pushNotificationService;

@Scheduled(cron = "0 0 5 * * *", zone = "Asia/Seoul")
@Scheduled(cron = "0 0 14 * * *", zone = "Asia/Seoul")
public void checkNotProcessedBagInit() {
List<BagCollect> bagCollects = bagCollectRepository.findNotProcessedBagCollects();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record ProductFilter(
@Schema(description = "스타일") List<String> styles,
@Schema(description = "최소 가격") Long minPrice,
@Schema(description = "최대 가격") Long maxPrice,
@Schema(description = "브랜드") String brandName,
@Schema(description = "브랜드") List<String> brandNames,
@Schema(description = "상품등급") List<String> qualityRates,
@Schema(description = "사이즈") List<String> sizes,
@Schema(description = "내 사이즈 여부") Boolean isMySize,
Expand All @@ -28,7 +28,7 @@ public ProductFilter withMySize(List<String> sizes) {
this.styles,
this.minPrice,
this.maxPrice,
this.brandName,
this.brandNames,
this.qualityRates,
sizes,
this.isMySize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -36,8 +37,9 @@ public class Payment extends BaseEntity {
@Embedded
private Address address;

private LocalDateTime deletedAt;
@Builder
public Payment(Long userId, PaymentStatus paymentStatus, String iamportUid, String merchantUid, BigDecimal amount, String userName, String phoneNumber, Address address) {
public Payment(Long userId, PaymentStatus paymentStatus, String iamportUid, String merchantUid, BigDecimal amount, String userName, String phoneNumber, Address address, LocalDateTime deletedAt) {
this.userId = userId;
this.paymentStatus = paymentStatus;
this.iamportUid = iamportUid;
Expand All @@ -46,6 +48,7 @@ public Payment(Long userId, PaymentStatus paymentStatus, String iamportUid, Stri
this.userName = userName;
this.phoneNumber = phoneNumber;
this.address = address;
this.deletedAt = deletedAt;
}

public static Payment of(Long userId, String merchantUid, BigDecimal amount, String userName, String phoneNumber, Address address) {
Expand All @@ -59,6 +62,13 @@ public static Payment of(Long userId, String merchantUid, BigDecimal amount, Str
.address(address)
.build();
}
public void setDeletedAt(LocalDateTime deletedAt) {
this.deletedAt = deletedAt;
}

public void deleteAddress() {
this.address = null;
}

public void updatePaymentStatus(PaymentStatus paymentStatus) {
this.paymentStatus = paymentStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import com.example.repick.domain.product.entity.Payment;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface PaymentRepository extends JpaRepository<Payment, Long> {
Optional<Payment> findByIamportUid(String iamportUid);

Optional<Payment> findByMerchantUid(String merchantUid);

List<Payment> findAllByUserId(Long userId);

List<Payment> findAllByDeletedAtBefore(LocalDateTime dateTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ Page<GetProductThumbnail> findHighestDiscountProducts(

List<GetProductByClothingSalesDto> findProductDtoByClothingSalesId(long clothingSalesId);

List<Product> findByProductSellingStateType(ProductStateType productStateType);

List<GetBrandList> getBrandList();

List<Product> findRecommendation(Long userId);
Expand Down
Loading

0 comments on commit a378f26

Please sign in to comment.