Update rebuild_app.yml #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Arena App with Docker | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Step 2: Add SSH key for remote server access | |
- name: Add SSH key | |
uses: webfactory/ssh-agent@v0.9.0 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# Step 3: Clone repository and build the new Docker container on the remote server | |
- name: Build new Docker container on the remote server | |
run: | | |
ssh -t -o StrictHostKeyChecking=no ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} -p ${{ secrets.REMOTE_PORT }} << 'EOF' | |
cd /home/${{ secrets.REMOTE_USER }} | |
cd /arena | |
docker build -t arena-app-new . | |
EOF | |
# Step 4: Stop old container and run new Docker container on the server | |
- name: Stop old container and run new Docker container on the server | |
run: | | |
ssh -t -o StrictHostKeyChecking=no ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} -p ${{ secrets.REMOTE_PORT }} << 'EOF' | |
if [ "$(docker ps -q -f name=arena-app)" ]; then | |
docker stop arena-app | |
docker rm arena-app | |
fi | |
docker run -d --name arena-app -p 7777:7860 arena-app-new | |
EOF |