Skip to content

Commit

Permalink
v1.0.0 (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
uwoobeat authored Feb 26, 2024
2 parents 59caaab + 4ce6dde commit 4f61cbc
Show file tree
Hide file tree
Showing 147 changed files with 4,799 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @GDSC-Hongik/backend-dev
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/♻️-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "♻️ refactor"
about: 리팩토링 이슈 템플릿
title: "♻️ "
labels: "♻️ refactor"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/⚙️-chore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "⚙️ chore"
about: 빌드 및 CI/CD 이슈 템플릿
title: "⚙️ "
labels: "⚙️ chore"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/✅-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "✅ test"
about: 테스트 이슈 템플릿
title: ""
labels: "✅ test"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/✨-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "✨ feature"
about: 기능 추가 이슈 템플릿
title: ""
labels: "✨ feature"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/🐛-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "🐛 fix"
about: 버그 및 에러 이슈 템플릿
title: "🐛 "
labels: "🐛 bug/error"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/📝-documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "📝 documentation"
about: 문서화 이슈 템플릿
title: "📝 "
labels: "📝 documentation"
assignees: ''

---

## 📌 Description
-
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 🌱 관련 이슈
- close #

## 📌 작업 내용 및 특이사항
-

## 📝 참고사항
-

## 📚 기타
-
129 changes: 129 additions & 0 deletions .github/workflows/develop_build_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Build and Deploy to Develop

on:
push:
branches: [ "develop" ]

permissions:
id-token: write
pull-requests: write

env:
IMAGE_NAME: gdsc-server

jobs:
build-deploy:
runs-on: ubuntu-latest
environment: develop
strategy:
matrix:
java-version: [ 17 ]
distribution: [ 'temurin' ]
steps:
# 체크아웃
- name: Checkout
uses: actions/checkout@v4

# JDK 17 버전으로 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: ${{ matrix.distribution }}

# Gradlew 실행 허용
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew

# Redis 컨테이너 실행
- name: Start containers
run: docker-compose -f ./docker-compose-test.yaml up -d

# Gradle 빌드
- name: Build with Gradle
id: gradle
uses: gradle/actions/setup-gradle@v3
with:
arguments: |
build
--configuration-cache
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} # feature 브랜치는 캐시를 읽기 전용으로 설정
cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }}
add-job-summary-as-pr-comment: always
build-scan-publish: true
build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-service-agree: "yes"

# Dockerhub 로그인
- name: Login to Dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Docker 메타데이터 추출
- name: Extract Docker metadata
id: metadata
uses: docker/[email protected]
env:
DOCKERHUB_IMAGE_FULL_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
with:
images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }}
tags: |
type=sha,prefix=
# 이미지 빌드 및 Dockerhub에 푸시
- name: Docker Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.metadata.outputs.tags }}

# AWS 로그인
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ap-northeast-2
output-config: true

# 복사 경로 환경변수 설정
- name: Set up S3 copy path
env:
S3_DEPLOY_BUCKET_NAME: ${{ secrets.S3_DEPLOY_BUCKET_NAME }}
run: echo "S3_COPY_PATH=$(echo s3://${S3_DEPLOY_BUCKET_NAME}/gdsc/docker-compose-dev.yml)" >> $GITHUB_ENV

# S3로 docker-compose 파일 전송
- name: Copy docker-compose file to S3
run: aws s3 cp docker-compose.yml ${{ env.S3_COPY_PATH }}

# 디스코드 둘기봇으로 gradle build scan 결과 발송
- name: Send Gradle Build Scan Result to Discord
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_EMBEDS: '[
{
"title": "푸드덕푸드덕푸드덕",
"description": "구구구구국 구구...: ${{ steps.gradle.outputs.build-scan-url }}"
}
]'

# EC2로 배포
- name: Deploy to EC2 Server
uses: appleboy/ssh-action@master
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }}
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: IMAGE_FULL_URL # docker-compose.yml 에서 사용할 환경 변수
script: |
aws s3 cp ${{ env.S3_COPY_PATH }} docker-compose.yml
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
docker pull ${{ env.IMAGE_FULL_URL }}
docker compose up -d
docker image prune -a -f
29 changes: 29 additions & 0 deletions .github/workflows/develop_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy to Develop

on:
workflow_dispatch:
inputs:
commit_hash:
description: 'commit_hash'
required: true

jobs:
deploy:
runs-on: ubuntu-latest
environment: develop
steps:
- name: Deploy to EC2 Server
uses: appleboy/ssh-action@master
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_IMAGE_TAG: ${{ github.event.inputs.commit_hash }}
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: DOCKERHUB_USERNAME,DOCKERHUB_IMAGE_TAG # docker-compose.yml 에서 사용할 환경 변수
script: |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
docker pull ${{ env.DOCKERHUB_USERNAME }}/gdsc-server:${{ env.DOCKERHUB_IMAGE_TAG }}
docker compose -f /home/ubuntu/docker-compose.yml up -d
docker image prune -a -f
133 changes: 133 additions & 0 deletions .github/workflows/production_build_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Build and Deploy to Production

on:
push:
tags:
- v*.*.*

permissions:
id-token: write

env:
IMAGE_NAME: gdsc-server

jobs:
build-deploy:
runs-on: ubuntu-latest
environment: production
strategy:
matrix:
java-version: [ 17 ]
distribution: [ 'temurin' ]
steps:
# 체크아웃
- name: Checkout
uses: actions/checkout@v4

# Docker 이미지 태그 세팅
- name: Set up image-tag by GITHUB_SHA
id: image-tag
run: echo "value=$(cut -d'v' -f2 <<< ${GITHUB_REF#refs/*/})" >> $GITHUB_OUTPUT

# JDK 17 버전으로 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: ${{ matrix.distribution }}

# Gradlew 실행 허용
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew

# Redis 컨테이너 실행
- name: Start containers
run: docker-compose -f ./docker-compose-test.yaml up -d

# Gradle 빌드
- name: Build with Gradle
id: gradle
uses: gradle/actions/setup-gradle@v3
with:
arguments: |
build
--configuration-cache
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} # feature 브랜치는 캐시를 읽기 전용으로 설정
cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }}
add-job-summary-as-pr-comment: always
build-scan-publish: true
build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-service-agree: "yes"

# Dockerhub 로그인
- name: Login to Dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Docker 메타데이터 추출
- name: Extract Docker metadata
id: metadata
uses: docker/[email protected]
env:
DOCKERHUB_IMAGE_FULL_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
with:
images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }}
tags: |
type=semver,pattern={{version}}
# 이미지 빌드 및 Dockerhub에 푸시
- name: Docker Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/gdsc-server:${{ steps.image-tag.outputs.value }}

# AWS 로그인
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: ap-northeast-2
output-config: true

# 복사 경로 환경변수 설정
- name: Set up S3 copy path
env:
S3_DEPLOY_BUCKET_NAME: ${{ secrets.S3_DEPLOY_BUCKET_NAME }}
run: echo "S3_COPY_PATH=$(echo s3://${S3_DEPLOY_BUCKET_NAME}/gdsc/docker-compose-dev.yml)" >> $GITHUB_ENV

# S3로 docker-compose 파일 전송
- name: Copy docker-compose file to S3
run: aws s3 cp docker-compose.yml ${{ env.S3_COPY_PATH }}

# 디스코드 둘기봇으로 gradle build scan 결과 발송
- name: Send Gradle Build Scan Result to Discord
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_EMBEDS: '[
{
"title": "푸드덕푸드덕푸드덕",
"description": "구구구구국 구구...: ${{ steps.gradle.outputs.build-scan-url }}"
}
]'

- name: Deploy to EC2 Server
uses: appleboy/ssh-action@master
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }}
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: IMAGE_FULL_URL # docker-compose.yml 에서 사용할 환경 변수
script: |
aws s3 cp ${{ env.S3_COPY_PATH }} docker-compose.yml
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
docker pull ${{ env.IMAGE_FULL_URL }}
docker compose up -d
docker image prune -a -f
Loading

0 comments on commit 4f61cbc

Please sign in to comment.