-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 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,77 @@ | ||
name: Java CD with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
env : | ||
working-directory: ./ | ||
APPLICATION: ${{ secrets.APPLICATION }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: '17' | ||
distribution: 'adopt' | ||
|
||
- name: Cache Gradle packages | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Create application.yml | ||
run: | | ||
echo "${{env.APPLICATION}}" > ./src/main/resources/application.yml | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
working-directory: ${{ env.working-directory }} | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build | ||
working-directory: ${{ env.working-directory }} | ||
|
||
- name: Cleanup Gradle Cache | ||
if: ${{ always() }} | ||
run: | | ||
rm -f ~/.gradle/caches/modules-2/modules-2.lock | ||
rm -f ~/.gradle/caches/modules-2/gc.properties | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build and Push Docker image | ||
run: | | ||
docker build -t ywj9811/postgraduate_log:latest . | ||
docker push ywj9811/postgraduate_log:latest | ||
- name: Deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SERVER_HOST }} | ||
username: ${{ secrets.SERVER_USERNAME }} | ||
key: ${{ secrets.PRIVATE_KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
docker-compose -f /home/ywj9811/config/docker-compose.yml down | ||
docker-compose -f /home/ywj9811/config/docker-compose.yml pull | ||
docker-compose -f /home/ywj9811/config/docker-compose.yml up -d --force-recreate --build | ||