Skip to content

Commit

Permalink
Create 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 2e0cd10 commit 649c149
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yaml
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

0 comments on commit 649c149

Please sign in to comment.