Skip to content

Commit

Permalink
add deployment pipeline [deploy]
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelhak-zaaim committed Nov 2, 2024
1 parent 7c6b3f1 commit 793823a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/deploy.yaml
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
6 changes: 3 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
spring.application.name=SuiviColis


spring.datasource.url=jdbc:mysql://localhost:3306/delix_database?createDatabaseIfNotExist=true&useSSL=false&useTimezone=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}


spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Expand Down

0 comments on commit 793823a

Please sign in to comment.