Skip to content

Commit

Permalink
refactor: cd 프로세스 최적화 #19
Browse files Browse the repository at this point in the history
  • Loading branch information
masiljangajji committed Dec 3, 2024
1 parent 7e16a63 commit 29b0112
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
38 changes: 12 additions & 26 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ env:
PROJECT_NAME: back
CODE_DEPLOY_APP_NAME: back-app
DEPLOYMENT_GROUP_NAME: back-deploy
AWS_REGION: ap-northeast-2

jobs:
build-with-gradle:
runs-on: ubuntu-20.04
build-and-deploy:
runs-on: ubuntu-latest
steps:

- name: Checkout PR
uses: actions/checkout@v3
with:
Expand All @@ -25,29 +25,13 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: 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


- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: Build with Gradle
run: ./gradlew build
shell: bash

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -57,21 +41,23 @@ jobs:
username: masiljangajji
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/arm64
tags: |
masiljangajji/back-app:latest
masiljangajji/back-app:${{ github.sha }}
# cache-from: type=inline
# cache-to: type=inline

- name: Zip artifact for CodeDeploy
- name: Deploy via CodeDeploy
run: |
zip -r $GITHUB_SHA.zip appspec.yml scripts/
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APP_NAME }} \
--deployment-config-name CodeDeployDefault.OneAtATime \
--deployment-group-name ${{ env.DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=${{ secrets.BUCKET_NAME }},bundleType=zip,key=${{ env.PROJECT_NAME }}/deployment.zip
- name: S3 Upload zip
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://${{ secrets.BUCKET_NAME }}/${{ env.PROJECT_NAME }}/$GITHUB_SHA.zip
- name: CodeDeploy
run: aws deploy create-deployment --application-name $CODE_DEPLOY_APP_NAME --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name $DEPLOYMENT_GROUP_NAME --s3-location bucket=${{ secrets.BUCKET_NAME }},bundleType=zip,key=${{ env.PROJECT_NAME }}/$GITHUB_SHA.zip
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
FROM openjdk:17 AS builder
FROM eclipse-temurin:17 AS build-stage

WORKDIR /app

# copy gradle config
COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .
COPY src src
RUN chmod +x ./gradlew
RUN microdnf install findutils

# copy source code
COPY src src

# Build
RUN ./gradlew build -x test

# base-image
FROM openjdk:17
FROM eclipse-temurin:17-jre
# build file path
RUN mkdir /opt/app
WORKDIR /opt/app
# copy jar file to container
COPY --from=builder build/libs/*.jar /opt/app/spring-boot-application.jar
COPY --from=build-stage /app/build/libs/*.jar spring-boot-application.jar
EXPOSE 8080
# run jar file
ENTRYPOINT ["java","-jar","/opt/app/spring-boot-application.jar"]

0 comments on commit 29b0112

Please sign in to comment.