From 9eba9ba845dc966a13599827c535ec8ce893483b Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Wed, 17 Jan 2024 21:33:00 +0900 Subject: [PATCH 1/5] config: CI workflow --- .github/workflows/deploy.yml | 51 ++++++++++++++++++++++++++++ src/main/java/com/fullcar/DockerFile | 7 ++++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 src/main/java/com/fullcar/DockerFile diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..a07116d --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,51 @@ +name: Build and Push Docker Image to AWS ECR + +on: + push: + branches: [develop] + pull_request: + branches: [develop] # develop 브랜치에 push/pr 했을 때 workflow를 trigger함. + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + steps: + # 코드 내려받기 + - name: Checkout source code + uses: actions/checkout@v2 + + # 자바 버전 세팅 + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: '17' + distribution: 'temurin' + + # 빌드 + - name: Build with Gradle + run: ./gradlew build + + # AWS 자격 증명 + - 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: ap-northeast-2 + + # AWS ECR 로그인 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + # Image 빌드 및 ECR에 Push 수행 + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }} + IMAGE_TAG: ${{ github.sha }} + run: | + docker buildx build --platform=linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" \ No newline at end of file diff --git a/src/main/java/com/fullcar/DockerFile b/src/main/java/com/fullcar/DockerFile new file mode 100644 index 0000000..368e6be --- /dev/null +++ b/src/main/java/com/fullcar/DockerFile @@ -0,0 +1,7 @@ +FROM openjdk:17 + +ARG JAR_PATH=build/libs/fullcar-0.0.1-SNAPSHOT.jar + +COPY ${JAR_PATH} fullcar.jar + +ENTRYPOINT ["java","-jar","/fullcar.jar"] \ No newline at end of file From bd19a1ed980670201c6faff6dd907fab465bd9f5 Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Wed, 17 Jan 2024 21:36:24 +0900 Subject: [PATCH 2/5] add: Grant execute permission for gradlew --- .github/workflows/deploy.yml | 4 ++++ src/main/java/com/fullcar/DockerFile | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a07116d..75d81ce 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,6 +21,10 @@ jobs: java-version: '17' distribution: 'temurin' + # 빌드 권한 부여 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + # 빌드 - name: Build with Gradle run: ./gradlew build diff --git a/src/main/java/com/fullcar/DockerFile b/src/main/java/com/fullcar/DockerFile index 368e6be..44e7bce 100644 --- a/src/main/java/com/fullcar/DockerFile +++ b/src/main/java/com/fullcar/DockerFile @@ -4,4 +4,4 @@ ARG JAR_PATH=build/libs/fullcar-0.0.1-SNAPSHOT.jar COPY ${JAR_PATH} fullcar.jar -ENTRYPOINT ["java","-jar","/fullcar.jar"] \ No newline at end of file +ENTRYPOINT ["java","-jar","/fullcar.jar"] \ No newline at end of file From 999cfcdf303882a6a75288c43ee077bc79a38a1f Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Wed, 17 Jan 2024 21:37:59 +0900 Subject: [PATCH 3/5] fix: build without test --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 75d81ce..d88d099 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,7 +27,7 @@ jobs: # 빌드 - name: Build with Gradle - run: ./gradlew build + run: ./gradlew clean build -x test # AWS 자격 증명 - name: Configure AWS credentials From 2e3c1663471ea0ac85537ab2c57b732134151fcc Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Wed, 17 Jan 2024 21:40:53 +0900 Subject: [PATCH 4/5] rename: Dockfile --- src/main/java/com/fullcar/{DockerFile => Dockerfile} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/java/com/fullcar/{DockerFile => Dockerfile} (100%) diff --git a/src/main/java/com/fullcar/DockerFile b/src/main/java/com/fullcar/Dockerfile similarity index 100% rename from src/main/java/com/fullcar/DockerFile rename to src/main/java/com/fullcar/Dockerfile From 0105acc9024209d261ead1d2d837ce57d8c17a9b Mon Sep 17 00:00:00 2001 From: Seokyeong Date: Wed, 17 Jan 2024 21:44:01 +0900 Subject: [PATCH 5/5] move: Dockfile --- src/main/java/com/fullcar/Dockerfile => Dockerfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/java/com/fullcar/Dockerfile => Dockerfile (100%) diff --git a/src/main/java/com/fullcar/Dockerfile b/Dockerfile similarity index 100% rename from src/main/java/com/fullcar/Dockerfile rename to Dockerfile