forked from mathialm/secfit
-
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
46 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,46 @@ | ||
| name: Build Docker Images | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'frontend/Dockerfile' | ||
| - 'backend/Dockerfile' | ||
| - 'frontend/**/*' | ||
| - 'backend/**/*' | ||
|
|
||
| jobs: | ||
| build-and-deploy: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
|
|
||
| - name: Build frontend Docker image | ||
| run: | | ||
| docker build -t frontend:latest ./frontend | ||
| - name: Build backend Docker image | ||
| run: | | ||
| docker build -t backend:latest ./backend | ||
| - name: SSH to the server and deploy Docker containers | ||
| uses: appleboy/ssh-action@v0.1.7 | ||
| with: | ||
| host: ${{ secrets.SERVER_IP }} # Replace with your server IP | ||
| username: ${{ secrets.SERVER_USER }} # Replace with your server username | ||
| key: ${{ secrets.SSH_PRIVATE_KEY }} # Your private SSH key (add this in GitHub Secrets) | ||
| script: | | ||
| docker pull frontend:latest || true # In case the image is already built on the server | ||
| docker pull backend:latest || true # In case the image is already built on the server | ||
| docker stop frontend || true | ||
| docker rm frontend || true | ||
| docker stop backend || true | ||
| docker rm backend || true | ||
| docker run -d --name frontend frontend:latest | ||
| docker run -d --name backend backend:latest |