Skip to content

Commit

Permalink
Merge pull request #7 from Kusitms-29th-ASAP/chore/#5-cicd
Browse files Browse the repository at this point in the history
chore : CI/CD 구축
  • Loading branch information
tlarbals824 authored Apr 24, 2024
2 parents 27a0f37 + 0714ee6 commit 0dcd923
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
89 changes: 89 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: dev deployment

on:
push:
branches:
- develop

jobs:
application_build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: java setting
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'

- name: gradle setting
run: |
chmod +x gradlew
./gradlew build
push_to_docker_hub:
needs: application_build
runs-on: ubuntu-latest
steps:
- name: Generate Version
id: generate_version
run: |
current_date=$(date -d "9 hours" +%Y-%m-%d)
current_date_short_year=$(date -d "9 hours" +%y-%m-%d)
runs_this_month=$(curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runs?event=push&status=success&per_page=1&created=cats+created:<=$current_date"\
| jq '.total_count')
echo "new version is $current_date_short_year.$runs_this_month"
echo "runs_this_month=$current_date_short_year.$runs_this_month" >> "$GITHUB_OUTPUT"
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ secrets.DOCKER_REGISTRY }}

- name: Docker build
env:
VERSION: ${{ steps.generate_version.outputs.runs_this_month }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
run: |
docker build -t $DOCKER_REGISTRY/IMAGE_NAME:$VERSION .
docker tag $DOCKER_REGISTRY/IMAGE_NAME:$VERSION $DOCKER_REGISTRY/IMAGE_NAME:latest
docker push $DOCKER_REGISTRY/IMAGE_NAME:$VERSION
docker push $DOCKER_REGISTRY/IMAGE_NAME:latest
run_application:
runs-on: ubuntu-latest
needs: push_to_docker_hub
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run Docker container
uses: appleboy/ssh-action@master
env:
VERSION: ${{ needs.push_to_docker_hub.outputs.VERSION }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
with:
host: ${{ secrets.NCP_HOST }}
username: ${{ secrets.NCP_USERNAME }}
password: ${{ secrets.NCP_PASSWORD }}
key: ${{ secrets.NCP_SSH_KEY }}
script: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY
docker pull $DOCKER_REGISTRY/IMAGE_NAME:$VERSION
docker stop $IMAGE_NAME || true
docker rm $IMAGE_NAME || true
docker run -d --name $IMAGE_NAME -p 8080:8080 $DOCKER_REGISTRY/IMAGE_NAME:$VERSION
27 changes: 27 additions & 0 deletions .github/workflows/dev_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: dev integration

on:
pull_request:
branches:
- develop


jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: setup jdk
uses: actions/setup-java@v1
with:
java-version: '17'
distribution: 'corretto'

- name: setup gradle
run: |
chmod +x gradlew
- name: build with gradle
run: ./gradlew build
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM amazoncorretto:17-alpine
COPY /build/libs/Asap-Backend.jar /app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "com.asap"
version = "0.0.1-SNAPSHOT"
version = ""

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down

0 comments on commit 0dcd923

Please sign in to comment.