Skip to content

use correct port

use correct port #6

Workflow file for this run

name: Deploy to Production Server
env:
SERVER_USER: 'swissh'
SERVER_IP: 'swis.sh'
DEPLOY_PATH: '/home/swissh/swis.sh/'
DOCKER_IMAGE: 'swissh-app'
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker image
run: |
docker build -t ${{ env.DOCKER_IMAGE }} .
- name: Set up SSH agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add SSH Key to Known Hosts
run: |
echo "$(ssh-keyscan -t rsa ${{ env.SERVER_IP }} 2>/dev/null)" >> ~/.ssh/known_hosts
- name: Save Docker image
run: docker save ${{ env.DOCKER_IMAGE }} | gzip > image.tar.gz
- name: Copy Docker image to server
run: |
scp image.tar.gz ${{ env.SERVER_USER }}@${{ env.SERVER_IP }}:${{ env.DEPLOY_PATH }}/
- name: Deploy using Docker
run: |
ssh ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} << 'EOF'
cd ${{ env.DEPLOY_PATH }}
docker load < image.tar.gz
docker stop ${{ env.DOCKER_IMAGE }} || true
docker rm ${{ env.DOCKER_IMAGE }} || true
docker run -d --name ${{ env.DOCKER_IMAGE }} \
-p 8091:80 \
--restart unless-stopped \
${{ env.DOCKER_IMAGE }}
rm image.tar.gz
EOF