-
Notifications
You must be signed in to change notification settings - Fork 3
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
74 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,74 @@ | ||
name: Java CI/CD with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
pull_request: | ||
branches: [ "develop" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Make application-base-addi.yml | ||
run: | | ||
cd ./src/main/resources | ||
touch ./application-base-addi.yml | ||
echo "${{ secrets.BASE_ADDI }}" > ./application-base-addi.yml | ||
shell: bash | ||
|
||
- name: Make docker-compose-prod.yml | ||
run: | | ||
touch ./docker-compose-prod.yml | ||
echo "${{ secrets.DOCKER_COMPOSE }}" > ./docker-compose-prod.yml | ||
shell: bash | ||
|
||
- name: Build with Gradle | ||
run: | | ||
chmod +x ./gradlew | ||
./gradlew bootJar | ||
- name: Send docker-compose-prod.yml | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.BACKEND_HOST }} | ||
username: ${{ secrets.BACKEND_USERNAME }} | ||
key: ${{ secrets.BACKEND_PRIVATE_KEY }} | ||
port: ${{ secrets.BACKEND_PORT }} | ||
source: "./docker-compose-prod.yml" | ||
target: ${{ secrets.BACKEND_PATH }} | ||
|
||
- name: Docker build and push to docker repo | ||
run: | | ||
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | ||
docker build -t ${{ secrets.BACKEND_PROJECT_NAME }} --build-arg PROFILES=prod . | ||
docker push ${{ secrets.BACKEND_PROJECT_NAME }} | ||
- name: remote ssh commands using password | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.BACKEND_HOST }} | ||
username: ${{ secrets.BACKEND_USERNAME }} | ||
key: ${{ secrets.BACKEND_PASSWORD }} | ||
port: ${{ secrets.BACKEND_PORT }} | ||
script: | | ||
sudo docker-compose -f ${{ secrets.BACKEND_PATH }}/docker-compose-prod.yml down | ||
sudo docker rmi ${{ secrets.BACKEND_PROJECT_NAME }} | ||
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | ||
sudo docker pull ${{ secrets.BACKEND_PROJECT_NAME }} | ||
sudo docker-compose -f ${{ secrets.BACKEND_PATH }}/docker-compose-prod.yml up -d | ||
sudo docker image prune -f |