Skip to content

Merge pull request #123 from seniors-project/Feature/#117 #7

Merge pull request #123 from seniors-project/Feature/#117

Merge pull request #123 from seniors-project/Feature/#117 #7

# 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
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
# JDK를 17 버전으로 세팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Gradle 캐싱-> 빌드 속도 UP
- 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-
# application.yml 파일 생성
- name: make application.yaml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
shell: bash
# Gradle로 빌드 실행
- name: Build with Gradle
run: ./gradlew bootJar
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# image 빌드 및 도커허브에 push
- name: web docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }}
docker buildx build --push -t ${{ secrets.DOCKER_REPO }}/seniors .
## docker compose up
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}/seniors
sudo docker run -d -p 8080:80 --name seniors ${{ secrets.DOCKER_REPO }}/seniors