Skip to content

Commit

Permalink
Update build.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jifollan authored and GitHub Enterprise committed Mar 3, 2025
1 parent 649c149 commit cbe7bd3
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Build Docker Images
name: Build Docker Images and Deploy

on:
push:
branches:
- main
paths:
- 'frontend/Dockerfile'
- 'backend/Dockerfile'
- 'frontend/**/*'
- 'backend/**/*'
- 'frontend/Dockerfile'
- 'backend/Dockerfile'
- 'frontend/**/*'
- 'backend/**/*'

jobs:
build-and-deploy:
Expand All @@ -24,20 +24,31 @@ jobs:
- name: Build frontend Docker image
run: |
docker build -t frontend:latest ./frontend
docker save -o frontend.tar frontend:latest
- name: Build backend Docker image
run: |
docker build -t backend:latest ./backend
docker save -o backend.tar backend:latest
- name: SSH to the server and deploy Docker containers
- name: Copy Docker images to the server
uses: appleboy/scp-action@v0.1.0
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "frontend.tar,backend.tar"
target: "~/"

- name: SSH to the server and load Docker images
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)
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
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 load -i ~/frontend.tar
docker load -i ~/backend.tar
docker stop frontend || true
docker rm frontend || true
docker stop backend || true
Expand Down

0 comments on commit cbe7bd3

Please sign in to comment.