Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ci cd: Docker, CI/CD 환경 셋팅 #33

Merged
merged 5 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Java CI with Gradle

on:
push:
paths-ignore:
- '*.md'
branches: [ "develop", "feature/ci-cd" ] # feature/ci-cd 브랜치 후에 삭제
pull_request:
branches: [ "develop" ]
permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
# gradle 의존성 캐싱
- name: gradle caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# 권한 설정
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# 빌드 - 테스트 제외 - !! 필요시 테스트 포함하도록 변경하기
- name: Build with Gradle
run: ./gradlew build -x test
# Buildx 설정
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# 도커 허브 로그인
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# 도커 빌드 및 푸시
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/pyonsnalcolor:latest # !! 필요시 tag명 수정
cache-from: type=gha # 캐시 적용
cache-to: type=gha,mode=max

deploy:
needs: [ build ]
runs-on: ubuntu-latest
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/pyonsnalcolor:latest
sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/pyonsnalcolor:latest pyonsnalcolor
sudo docker-compose up -d
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,5 @@ hs_err_pid*
replay_pid*

# End of https://www.toptal.com/developers/gitignore/api/intellij,java
*.idea
*.iml
36 changes: 0 additions & 36 deletions .idea/compiler.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/encodings.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/jarRepositories.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .idea/misc.xml

This file was deleted.

13 changes: 0 additions & 13 deletions .idea/modules.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:11
COPY pyonsnalcolor-member/build/libs/pyonsnalcolor-member-1.0-SNAPSHOT.jar member.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/member.jar"]

RUN echo "pyonsnalcolor-member start"
45 changes: 45 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
buildscript {
ext {
springBootVersion = '2.7.12'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
}
}

allprojects {}

subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.pyonsnalcolor'
version = '1.0'
sourceCompatibility = '11'

repositories {
mavenCentral()
}

dependencies {
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}

jar {
enabled = false
}
bootJar {
enabled = true
}
}
13 changes: 13 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
// Support convention plugins written in Groovy. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
id 'groovy-gradle-plugin'
}

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
}
38 changes: 38 additions & 0 deletions buildSrc/src/main/groovy/com.pyonsnalcolor.java-conventions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file was generated by the Gradle 'init' task.
*/

plugins {
id 'java-library'
id 'maven-publish'
}

repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:2.7.12'
implementation 'org.projectlombok:lombok:1.18.26'
runtimeOnly 'org.springframework.boot:spring-boot-devtools:2.7.12'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.12'
}

group = 'com.pyonsnalcolor'
version = '1.0-SNAPSHOT'
java.sourceCompatibility = JavaVersion.VERSION_11

publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3"

services:
application:
image: pyonsnalcolor
environment:
SPRING_DATASOURCE_URL: ${DB_URL}
SPRING_DATASOURCE_USERNAME: admin
SPRING_DATASOURCE_PASSWORD: ${DB_PASSWORD}
JWT_ISSUER: ${JWT_ISSUER}
JWT_SECRET: ${JWT_SECRET}
JWT_ACCESS-TOKEN_VALIDITY: ${JWT_ACCESS_TOKEN_VALIDITY}
JWT_REFRESH-TOKEN_VALIDITY: ${JWT_REFRESH_TOKEN_VALIDITY}
SPRING_SECURITY_OAUTH2_APPLE_CLIENT_ID: ${APPLE_CLIENT_ID}
restart: always
ports:
- "8080:8080"
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading