Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
YounCheEun committed Jan 8, 2024
2 parents a5ac9f0 + 6d5f138 commit 2dc3b95
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 20 deletions.
117 changes: 98 additions & 19 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,113 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle
#github repository Actions 페이지에 나타낼 이름
name: CI/CD

# event trigger
on:
push:
branches: [ "main" ]
branches:
["main", "develop"]
pull_request:
branches: [ "main" ]
branches:
["main", "develop"]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

CI-CD:
runs-on: ubuntu-22.04
steps:

## jdk setting
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
java-version: '17'
distribution: 'temurin' # https://github.com/actions/setup-java

## gradle caching
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.yml') }}
restore-keys: |
${{ runner.os }}-gradle-
## create application-prod.yml
- name: make application-prod.yml
if: contains(github.ref, 'main')
run: |
cd ./src/main
mkdir resources
cd ./resources
touch ./application.yml
echo "${{ secrets.YML_PROD }}" >> ./application.yml
shell: bash

- name: Set up permissions for Gradle
run: chmod +x ./gradlew

## gradle build
- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
run: |
./gradlew build -x test
ls -l build/libs
## copy jar file
- name: Copy jar file
run: cp build/libs/*-0.0.1-SNAPSHOT.jar .

- name: List directory
run: ls -R

## docker build & push to production
- name: Checkout code
uses: actions/checkout@v2

- name: Docker login
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Docker build
run: |
docker build -t ${{ secrets.DOCKER_REPO }} .
- name: Docker push
run: |
docker push ${{ secrets.DOCKER_REPO }}
## deploy to production
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
if: contains(github.ref, 'main')
with:
arguments: build
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}
docker-compose up -d
docker image prune -f
## time
current-time:
needs: CI-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
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

0 comments on commit 2dc3b95

Please sign in to comment.