-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from woogieon8on/script
#3 Feat: add github-action script
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# This workflow will build a Java project with Gradle | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | ||
|
||
# Repo Action 페이지에 나타날 이름 | ||
name: Spring Boot & Gradle CI/CD | ||
|
||
# Event Trigger | ||
# master branch에 push 또는 pull request가 발생할 경우 동작 | ||
# branch 단위 외에도, tag나 cron 식 등을 사용할 수 있음 | ||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
# 실행 환경 지정 | ||
runs-on: ubuntu-24.04 | ||
|
||
# Task의 sequence를 명시한다. | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 17 | ||
## create application.yaml | ||
- name: make application.yml | ||
run: | | ||
## create application.yml | ||
cd ./src/main/resources | ||
# application.yml 파일 생성 | ||
touch ./application.yml | ||
# GitHub-Actions 에서 설정한 값을 application.yaml 파일에 쓰기 | ||
echo "${{ secrets.DATABASE }}" >> ./application.yml | ||
shell: bash | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
# Build | ||
- name: Build with Gradle | ||
run: ./gradlew clean build | ||
|
||
## 웹 이미지 빌드 및 도커허브에 push | ||
- name: web docker build and push | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -t ${{ secrets.DOCKER_REPO }}/kahlua-web . | ||
docker push ${{ secrets.DOCKER_REPO }}/kahlua-web | ||
## docker compose up | ||
- name: executing remote ssh commands using password | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST_ID }} | ||
username: ec2-user | ||
key: ${{ secrets.PRIVATE_KEY }} | ||
script: | | ||
sudo docker rm -f $(docker ps -qa) | ||
sudo docker pull ${{ secrets.DOCKER_REPO }}/kahlua-web | ||
docker-compose up -d | ||
docker image prune -f |