-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
7c6b3f1
commit 793823a
Showing
2 changed files
with
65 additions
and
3 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 @@ | ||
name: Deploy to Ubuntu Server | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' && contains(github.event.head_commit.message, '[deploy]') == true | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '21' | ||
|
||
- name: Build with Maven | ||
run: mvn clean package | ||
env: | ||
DB_URL: ${{ secrets.DB_URL }} | ||
DB_USERNAME: ${{ secrets.DB_USERNAME }} | ||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }} | ||
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }} | ||
|
||
- name: Build Docker image | ||
run: docker build -t ci-cd:latest . | ||
env: | ||
DB_URL: ${{ secrets.DB_URL }} | ||
DB_USERNAME: ${{ secrets.DB_USERNAME }} | ||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | ||
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }} | ||
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }} | ||
|
||
- name: Save Docker image to file | ||
run: docker save ci-cd:latest -o ci-cd-latest.tar | ||
|
||
- name: Copy Docker image to server | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SERVER_HOST }} | ||
username: ${{ secrets.SERVER_USER }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
source: "ci-cd-latest.tar" | ||
target: "~/" | ||
|
||
- name: Deploy to server | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SERVER_HOST }} | ||
username: ${{ secrets.SERVER_USER }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
script: | | ||
sudo docker load -i ~/ci-cd-latest.tar | ||
sudo docker stop ci-cd-container || true | ||
sudo docker rm ci-cd-container || true | ||
sudo docker run -d --name ci-cd-container -p 80:80 ci-cd:latest |
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