Skip to content

Commit

Permalink
ci: github action, docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
umi0410 committed Mar 6, 2022
1 parent 9c76ce1 commit 17eb567
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

before.json
after.json
.gradle
.mvn

**/resources/*.properties
!**/resources/application.properties
95 changes: 95 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Automated CI
on:
push:
branches: ["*"]
workflow_dispatch:

jobs:
ci:
runs-on: ubuntu-latest
env:
IMAGE_NAME: umi0410/khumu-community
steps:
- name: 배포 환경 설정
run: |
# master 혹은 main 브랜치의 경우 prd 환경에 배포합니다.
# 그 외의 브랜치는 dev로
environment="dev"
if [ ${GITHUB_REF#refs/heads/} == "master" ]; then
environment="prd"
elif [ ${GITHUB_REF#refs/heads/} == "main" ]; then
environment="prd"
fi
echo "현재 ref: ${GITHUB_REF#refs/heads/}"
echo "설정된 배포 환경 ${environment}"
echo "environment=${environment}" >> $GITHUB_ENV
- name: 🛎️ Checkout
uses: actions/[email protected] # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
token: ${{ secrets.GITHUB_TOKEN }}
submodules: true

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: 🍦 Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: 🏗️ Build images
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: false # buildkit을 쓰면 auto push가 안되는듯?
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.run_id }}
- name: 🏗️ Push images
run: |
docker push ${{ env.IMAGE_NAME }}:latest
docker push ${{ env.IMAGE_NAME }}:${{ github.run_id }}
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v1
with:
kustomize-version: "3.8.6"

- name: 🛎 Clone the devops repository
uses: actions/checkout@v2
with:
repository: khu-dev/khumu-devops
token: ${{ secrets.PUSH_TO_OTHER_REPO }}
path: 'khumu-devops'

- name: Edit Kustomization.yaml
working-directory: khumu-devops/khumu-community/${{ env.environment }}
run: |
kustomize version
kustomize edit set image ${{ env.IMAGE_NAME }}=${{ env.IMAGE_NAME }}:${{ github.run_id }}
- name: Push to another repository
uses: cpina/github-action-push-to-another-repository@master
env:
API_TOKEN_GITHUB: ${{ secrets.PUSH_TO_OTHER_REPO }}
with:
source-directory: khumu-devops
destination-github-username: 'khu-dev'
destination-repository-name: 'khumu-devops'

- name: 슬랙 알림
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
author_name: Github Action # default: 8398a7@action-slack
# fields: repo,message,commit,author,action,eventName,ref,workflow,job,took
fields: repo,message,commit,author,ref,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM openjdk:11-jdk-slim as build
WORKDIR /khumu

COPY gradle gradle
COPY build.gradle gradlew gradlew.bat ./
COPY src src

RUN ./gradlew build -x test

FROM openjdk:11-jre-slim
WORKDIR /khumu
COPY --from=build /khumu/src/main/resources resources
COPY --from=build /khumu/build/libs/*.jar community.jar
# java -Dspring.profiles.active=dev -jar community.jar --spring.config.location=resources/
ENTRYPOINT ["java", "-Dspring.profiles.active=dev", "-jar", "community.jar", "--spring.config.location=resources/"]
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

// gradle로 빌드 시 plain jar를 생성하지 않기 위함
// spring boot 2.5부터 변경됐음.
// https://earth-95.tistory.com/132
jar {
enabled = false
}
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
server.port=9003
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/database_name?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Seoul
spring.datasource.username=username
spring.datasource.password=password
Expand All @@ -26,4 +25,5 @@ spring.data.web.pageable.one-indexed-parameters=true

cloud.aws.region.static=ap-northeast-2
cloud.aws.region.auto=false
cloud.aws.stack.auto=false
cloud.aws.stack.auto=false
logging.level.com.amazonaws.util.EC2MetadataUtils: error

0 comments on commit 17eb567

Please sign in to comment.