Skip to content

Commit

Permalink
Merge pull request #26 from win-luck/feature/11-cicd
Browse files Browse the repository at this point in the history
[infra] 배포 및 CI/CD 환경 구축 (#11)
  • Loading branch information
win-luck authored Aug 10, 2024
2 parents 16cc076 + 4625566 commit 0d9c02f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CD

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [closed]
workflow_dispatch:

permissions:
contents: read

jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: self-hosted

steps:
- uses: actions/checkout@v4

- name: Docker Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Pull Docker Image
run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/puang

- name: Remove Old Docker Container
run: sudo docker rm -f puang || true

- name: Run Updated Docker Container
run: sudo docker run -t -d --name puang -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/puang
51 changes: 51 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0

- name: make application.yml
run: |
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application.yml
touch ./application-prod.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
echo "${{ secrets.PROD }}" > ./application-prod.yml
- name: Build with Gradle
run: ./gradlew build -x test

- name: Docker Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build Docker Image
run: docker build --platform linux/amd64 -t ${{ secrets.DOCKERHUB_USERNAME }}/puang .

- name: Push Docker Image
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/puang
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use OpenJDK 17 as the base image
FROM openjdk:17

# Specify the build argument for the JAR file
ARG JAR_FILE=build/libs/*.jar

# Copy the JAR file into the container
COPY ${JAR_FILE} app.jar

# Set the entry point to run the JAR file
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "/app.jar"]
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ tasks.named('test') {
bootJar {
archiveFileName = 'app.jar'
}

jar {
enabled = false
}

0 comments on commit 0d9c02f

Please sign in to comment.