From 8eca8f36932f4f882c310d22b2a56d0a61e59d0a Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sun, 21 Jan 2024 15:02:40 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix=20:=20jdk=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - temurin -> bellsoft/liberica --- backend/core/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/core/Dockerfile b/backend/core/Dockerfile index c8b8fedfd..5da51791a 100644 --- a/backend/core/Dockerfile +++ b/backend/core/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17-jre as build +FROM bellsoft/liberica-openjdk-alpine:17 as build WORKDIR /workspace/app # Copy Gradle wrapper and other necessary files @@ -8,7 +8,7 @@ COPY build/libs/ . RUN mkdir -p target/extracted RUN java -Djarmode=layertools -jar *.jar extract --destination target/extracted -FROM eclipse-temurin:17-jre +FROM bellsoft/liberica-openjdk-alpine:17 VOLUME /tmp ARG EXTRACTED=/workspace/app/target/extracted From 19df8ec37ed94dacfc570dbcc911c27a23cc692f Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sun, 21 Jan 2024 15:03:20 +0900 Subject: [PATCH 2/5] =?UTF-8?q?fix=20:=20google=20java=20format=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/google-java-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/google-java-format.yml b/.github/workflows/google-java-format.yml index 655e94782..a9dbe5205 100644 --- a/.github/workflows/google-java-format.yml +++ b/.github/workflows/google-java-format.yml @@ -1,6 +1,6 @@ name: Format -on: [ push, pull_request ] +on: [ pull_request ] jobs: From 9e2d835e785073d3e9b19b18282f6382fd4cadbf Mon Sep 17 00:00:00 2001 From: hong seokho Date: Sun, 21 Jan 2024 15:04:06 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat=20:=20ci/cd=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - github actions -> ecr push -> ec2 pull & run Open #28 --- .github/workflows/ci-cd-flow.yml | 102 +++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .github/workflows/ci-cd-flow.yml diff --git a/.github/workflows/ci-cd-flow.yml b/.github/workflows/ci-cd-flow.yml new file mode 100644 index 000000000..5aedafa85 --- /dev/null +++ b/.github/workflows/ci-cd-flow.yml @@ -0,0 +1,102 @@ +name: ci/cd + +on: + push: + branches: + - develop_back + +jobs: + deploy-core: + name: core application deploy + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./backend/core + + permissions: + id-token: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + token: ${{ secrets.CI_PAT }} + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'liberica' + cache: gradle + + - name: grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: build gradle + run: ./gradlew clean build + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ steps.login-ecr.outputs.registry }}/${{ secrets.AWS_ECR_REPOSITORY_NAME }} + tags: | + type=raw,value=latest + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: ./backend/core + platforms: linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + provenance: false + + - name: Get Github action IP + id: ip + uses: haythem/public-ip@v1.3 + + - name: Add Github Actions IP to Security group + run: | + aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_EC2_CORE_SG_ID }} --group-name ${{secrets.AWS_EC2_CORE_SG_NAME}} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + + - name: Connect ec2 and Run Docker Container + uses: appleboy/ssh-action@v0.1.6 + env: + AWS_ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + with: + host: ${{ secrets.SSH_CORE_HOST }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_CORE_PRIVATE_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + docker ps -q --filter "name=core" | xargs -r docker stop + docker ps -aq --filter "name=core" | xargs -r docker rm + aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username ${{ secrets.AWS_DOCKER_USER }} --password-stdin ${{ secrets.AWS_USER_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com + docker pull ${{ steps.meta.outputs.tags }} + docker run -d -p 8080:8080 --name core --network test_backend ${{ steps.meta.outputs.tags }} + + - name: Remove Github Actions IP from security group + if: always() + run: | + aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_EC2_CORE_SG_ID }} --group-name ${{secrets.AWS_EC2_CORE_SG_NAME}} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 \ No newline at end of file From 80329f1005236970790d8d209bbbda32820624b1 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Mon, 22 Jan 2024 18:16:07 +0900 Subject: [PATCH 4/5] fix : github actions & parameter name --- .github/workflows/ci-cd-flow.yml | 21 +++++++++++++++++++ .../core/global/error/ErrorResponse.java | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd-flow.yml b/.github/workflows/ci-cd-flow.yml index 5aedafa85..ac942a96e 100644 --- a/.github/workflows/ci-cd-flow.yml +++ b/.github/workflows/ci-cd-flow.yml @@ -4,10 +4,31 @@ on: push: branches: - develop_back + pull_request: + branches: + - develop_back jobs: + formatting: + name: formatting + if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + steps: + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + - uses: actions/checkout@v3 + - uses: axel-op/googlejavaformat-action@v3 + with: + args: "--replace" + skip-commit: true + deploy-core: name: core application deploy + needs: formatting + if: ${{ github.event_name == 'push' }} runs-on: ubuntu-latest defaults: diff --git a/backend/core/src/main/java/site/timecapsulearchive/core/global/error/ErrorResponse.java b/backend/core/src/main/java/site/timecapsulearchive/core/global/error/ErrorResponse.java index 2bb0c0887..f70774aba 100644 --- a/backend/core/src/main/java/site/timecapsulearchive/core/global/error/ErrorResponse.java +++ b/backend/core/src/main/java/site/timecapsulearchive/core/global/error/ErrorResponse.java @@ -15,7 +15,7 @@ public record ErrorResponse( String message, @Schema(description = "에러 리스트 ex) 필드 에러들") - List errors + List result ) { public static ErrorResponse create(final ErrorCode errorCode) { From 1872e7cfa374b0c5f7dea5b827d8a39eded50fc1 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Mon, 22 Jan 2024 18:18:43 +0900 Subject: [PATCH 5/5] =?UTF-8?q?fix=20:=20formatting=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/google-java-format.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .github/workflows/google-java-format.yml diff --git a/.github/workflows/google-java-format.yml b/.github/workflows/google-java-format.yml deleted file mode 100644 index a9dbe5205..000000000 --- a/.github/workflows/google-java-format.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Format - -on: [ pull_request ] - -jobs: - - formatting: - runs-on: ubuntu-latest - steps: - - name: set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'corretto' - - uses: actions/checkout@v3 - - uses: axel-op/googlejavaformat-action@v3 - with: - args: "--replace" - skip-commit: true \ No newline at end of file