diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2f76fcb..10a5397 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,44 +1,31 @@ -name: Deploy Nginx +name: Deploy to NAS (rsync) on: push: - branches: [ main ] - workflow_dispatch: + branches: + - main jobs: deploy: runs-on: ubuntu-latest - + steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and push Nginx - uses: docker/build-push-action@v5 - with: - context: ./nginx - push: true - tags: | - ${{ secrets.DOCKER_USERNAME }}/robeing-nginx:latest - ${{ secrets.DOCKER_USERNAME }}/robeing-nginx:${{ github.sha }} - - - name: Update docker-compose.yml - run: | - sed -i "s|image: .*/robeing-nginx:.*|image: ${{ secrets.DOCKER_USERNAME }}/robeing-nginx:${{ github.sha }}|g" docker-compose.yml - - - name: Commit and push changes - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add docker-compose.yml - git commit -m "Update nginx image to ${{ github.sha }}" || exit 0 - git push \ No newline at end of file + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup SSH key + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.NAS_SSH_KEY_ADMIN }} + + - name: Rsync to NAS + run: | + rsync -avz -e "ssh -o StrictHostKeyChecking=no -p ${{ secrets.NAS_PORT }}" ./ \ + ${{ secrets.NAS_USER }}@${{ secrets.NAS_HOST }}:/volume1/homes/admin/nginx-infra/ + + - name: Remote docker-compose up + run: | + ssh -o StrictHostKeyChecking=no -p ${{ secrets.NAS_PORT }} ${{ secrets.NAS_USER }}@${{ secrets.NAS_HOST }} << 'EOF' + cd /volume1/homes/admin/nginx-infra + docker-compose up -d --build + EOF \ No newline at end of file