Merge pull request #295 from Myongji-Graduate/develop #44
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
name: Dev | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '11' | |
- 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- | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with gradle | |
run : ./gradlew build -x test | |
- name: Build Docker image | |
run: | | |
docker login -u ${{ secrets.DOCKERHUB_ID }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mju-graduate-server:v2 \ | |
--build-arg DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ | |
--build-arg DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ | |
--build-arg DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ | |
--build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} . | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/mju-graduate-server:v2 | |
- name: Docker Deploy executing remote ssh commands using ssh_key | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.WAS_HOST }} | |
username: ${{ secrets.WAS_USERNAME }} | |
key: ${{ secrets.WAS_KEY }} | |
script : | | |
cd ~/mju-graduate-server | |
docker stop $(docker ps -a -q) | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/mju-graduate-server:v2 | |
docker rm -f $(docker ps -a -q) | |
docker run -d --name mju-graduate-server -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/mju-graduate-server:v2 | |
docker image prune -f |