Skip to content

Commit

Permalink
Merge pull request #227 from ShallWeProject/infra/226-deploy-prod
Browse files Browse the repository at this point in the history
infra: prod deploy script 작성
  • Loading branch information
hyunw9 authored Jan 21, 2024
2 parents 1b70ce9 + ac3b271 commit 950f78f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ jobs:
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
#password: ${{ secrets.PASSWORD }}
port: 22
key: ${{ secrets.PRIVATE_KEY }}
script: |
Expand All @@ -104,4 +103,4 @@ jobs:

- name: Print Current Time
run: echo "Current Time=${{steps.current-time.outputs.formattedTime}}" # current-time 에서 지정한 포맷대로 현재 시간 출력
shell: bash
shell: bash
106 changes: 106 additions & 0 deletions .github/workflows/prod-cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# github repository Actions 페이지에 나타낼 이름
name: CI/CD

# event trigger
on:
push:
branches:
- main

permissions:
contents: read

jobs:
CI:
runs-on: ubuntu-latest

## jdk setting
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

## gradle caching
- 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-
## create application-prod.yml
- name: make application-prod.yml
if: contains(github.ref, 'main')
run: |
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application-prod.yml
echo "${{ secrets.PROPERTIES_PROD }}" > ./application-prod.yml
shell: bash

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

# Spring Boot 애플리케이션 빌드
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: clean bootJar

# DockerHub 로그인
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Docker 이미지 빌드
- name: docker image build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile-prod
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/shallwe-prod

CD:
needs: CI
runs-on: ubuntu-latest
## deploy to prod
steps:
- name: Deploy to prod
uses: appleboy/[email protected]
id: deploy-prod
if: contains(github.ref, 'main')
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
key: ${{ secrets.PRIVATE_KEY }}
script: |
ssh prod sudo docker rm -f $(ssh prod sudo docker ps -qa)
ssh prod sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_PROD }}
ssh prod sudo docker run -dp 80:8080 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_PROD }}
## time ##
current-time:
needs: CD
runs-on: ubuntu-latest
steps:
- name: Get Current Time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DDTHH:mm:ss
utcOffset: "+09:00" # 기준이 UTC이기 때문에 한국시간인 KST를 맞추기 위해 +9시간 추가

- name: Print Current Time
run: echo "Current Time=${{steps.current-time.outputs.formattedTime}}" # current-time 에서 지정한 포맷대로 현재 시간 출력
shell: bash
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ out/
.vscode/

/src/main/resources/application-dev.yml
/src/main/resources/application-local.yml
/src/main/resources/application-local.yml
/src/main/resources/application-prod.yml

0 comments on commit 950f78f

Please sign in to comment.