Skip to content

Commit

Permalink
Merge pull request #5 from softeerbootcamp4th/feature/4-infra-cicd
Browse files Browse the repository at this point in the history
[infra] VPC, Subnet 설정 및 Github Actions 기반 CI/CD 파이프라인 구축 (#4)
  • Loading branch information
win-luck authored Jul 29, 2024
2 parents 7a81efb + ee5656f commit 310e4b8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# CI/CD workflow
name: CI/CD

on:
push:
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

permissions:
contents: read

jobs:
CI:
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

# TODO: 추후 테스트코드 작성 후 테스트 실패 시 CI 불가능하도록 수정
- 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 }}/orange .

- name: Push Docker Image
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/orange

CD:
if: github.event.pull_request.merged == true && github.ref == 'refs/heads/dev'
runs-on: self-hosted
needs: CI

steps:
- name: Remove Docker Container
run: sudo docker rm -f orange || true

- name: Run Updated Docker Container
run: sudo docker run -t --env-file ./.env -d --name orange -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/orange
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ out/
.vscode/

### project
*.sh
*.yml
*.yaml
*.properties
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", "/app.jar"]
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
annotationProcessor 'com.github.therapi:therapi-runtime-javadoc-scribe:0.13.0'
implementation 'com.github.therapi:therapi-runtime-javadoc:0.13.0'

// mysql
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
runtimeOnly 'com.mysql:mysql-connector-j'

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.data:spring-data-redis'
}

tasks.named('test') {
Expand Down

0 comments on commit 310e4b8

Please sign in to comment.