name: Build and Deploy to Server on: push: branches: [ main ] jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Build backend image run: | cd backend docker build -t hetianci/studyingspace-backend:TEST . - name: Build frontend image run: | cd frontend docker build -t hetianci/studyingspace-frontend:TEST . - name: Save backend image to tar run: | docker save -o studyingspace-backend.tar hetianci/studyingspace-backend:TEST - name: Save frontend image to tar run: | docker save -o studyingspace-frontend.tar hetianci/studyingspace-frontend:TEST - name: Copy images to server uses: appleboy/scp-action@v0.1.4 with: host: ${{ secrets.SERVER_HOST }} username: ${{ secrets.SERVER_USER }} key: ${{ secrets.SERVER_SSH_PRIVATE_KEY }} source: "studyingspace-backend.tar,studyingspace-frontend.tar" target: "my_project/StudyingSpace/" - name: Deploy to server uses: appleboy/ssh-action@v1.0.3 with: host: ${{ secrets.SERVER_HOST }} username: ${{ secrets.SERVER_USER }} key: ${{ secrets.SERVER_SSH_PRIVATE_KEY }} script: | cd my_project/StudyingSpace git pull docker load -i studyingspace-backend.tar docker load -i studyingspace-frontend.tar docker compose up -d rm -f studyingspace-backend.tar studyingspace-frontend.tar