Skip to content

Commit

Permalink
Update deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-ruby authored May 23, 2024
1 parent 7f036b5 commit b4befd5
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,47 @@
name: Deploy Frontend
name: Deploy Frontend and Backend

on:
push:
branches:
- main

jobs:
build:
build-and-deploy:
runs-on: ubuntu-latest

strategy:
matrix:
service: [frontend, backend]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
run: |
docker build -t devruby/l2s-frontend:latest ./frontend
docker build -t devruby/l2s-backend:latest ./backend
docker push devruby/l2s-frontend:latest
docker push devruby/l2s-backend:latest
deploy:
runs-on: ubuntu-latest
needs: build
docker build -t devruby/l2s-${{ matrix.service }}:latest ./${{ matrix.service }}
docker push devruby/l2s-${{ matrix.service }}:latest
steps:
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_PRIVATE_KEY }}
script: |
sudo docker stop l2s-frontend || true
sudo docker rm l2s-frontend || true
sudo docker image rm devruby/l2s-frontend || true
sudo docker pull devruby/l2s-frontend:latest
sudo docker run -d --name l2s-frontend -p 3001:3000 devruby/l2s-frontend:latest
sudo docker stop l2s-backend || true
sudo docker rm l2s-backend || true
sudo docker image rm devruby/l2s-backend || true
sudo docker pull devruby/l2s-backend:latest
sudo docker run -d --name l2s-backend -v l2s-data:/workspace/data -p 8001:8000 devruby/l2s-backend:latest
sudo docker stop l2s-${{ matrix.service }} || true
sudo docker rm l2s-${{ matrix.service }} || true
sudo docker image rm devruby/l2s-${{ matrix.service }} || true
sudo docker pull devruby/l2s-${{ matrix.service }}:latest
if [ "${{ matrix.service }}" = "frontend" ]; then
sudo docker run -d --name l2s-frontend -p 3001:3000 devruby/l2s-frontend:latest
else
sudo docker run -d --name l2s-backend -v l2s-data:/workspace/data -p 8001:8000 devruby/l2s-backend:latest
fi

0 comments on commit b4befd5

Please sign in to comment.