CI test
All checks were successful
Build, Push and Deploy / build-and-deploy (push) Successful in 17s
All checks were successful
Build, Push and Deploy / build-and-deploy (push) Successful in 17s
This commit is contained in:
@@ -39,22 +39,34 @@ jobs:
|
|||||||
- name: Deploy to Remote Server
|
- name: Deploy to Remote Server
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SSH_HOST }}
|
host: ${{ secrets.DEPLOY_HOST }}
|
||||||
username: ${{ secrets.SSH_USERNAME }}
|
username: ${{ secrets.DEPLOY_USER }}
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
|
||||||
port: ${{ secrets.SSH_PORT }}
|
port: ${{ secrets.DEPLOY_SSH_PORT || '22' }}
|
||||||
script: |
|
script: |
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "=== Starting deployment ==="
|
||||||
|
|
||||||
# Login to Container Registry
|
# Login to Container Registry
|
||||||
|
echo "Logging in to registry..."
|
||||||
echo "${{ secrets.CI_GITEA_TOKEN }}" | docker login ${{ vars.REGISTRY_URL }} -u ${{ secrets.CI_GITEA_USER }} --password-stdin
|
echo "${{ secrets.CI_GITEA_TOKEN }}" | docker login ${{ vars.REGISTRY_URL }} -u ${{ secrets.CI_GITEA_USER }} --password-stdin
|
||||||
|
|
||||||
# Pull new image
|
# Pull new image
|
||||||
|
echo "Pulling new image..."
|
||||||
docker pull ${{ vars.REGISTRY_URL }}/${{ vars.NAMESPACE }}/${{ vars.REPO_NAME }}:${{ github.sha }}
|
docker pull ${{ vars.REGISTRY_URL }}/${{ vars.NAMESPACE }}/${{ vars.REPO_NAME }}:${{ github.sha }}
|
||||||
|
|
||||||
# Stop and remove old container
|
# Stop and remove old container (with retry logic)
|
||||||
|
echo "Stopping old container..."
|
||||||
|
if docker ps -a --format '{{.Names}}' | grep -q "^skamp-app$"; then
|
||||||
docker stop skamp-app || true
|
docker stop skamp-app || true
|
||||||
docker rm skamp-app || true
|
sleep 2
|
||||||
|
docker rm -f skamp-app || true
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Start new container with environment variables
|
# Start new container with environment variables
|
||||||
|
echo "Starting new container..."
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name skamp-app \
|
--name skamp-app \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
@@ -73,8 +85,22 @@ jobs:
|
|||||||
-e JAVA_OPTS="${{ secrets.JAVA_OPTS }}" \
|
-e JAVA_OPTS="${{ secrets.JAVA_OPTS }}" \
|
||||||
${{ vars.REGISTRY_URL }}/${{ vars.NAMESPACE }}/${{ vars.REPO_NAME }}:${{ github.sha }}
|
${{ vars.REGISTRY_URL }}/${{ vars.NAMESPACE }}/${{ vars.REPO_NAME }}:${{ github.sha }}
|
||||||
|
|
||||||
# Clean up old images
|
# Wait for container to start
|
||||||
docker image prune -af --filter "until=168h"
|
echo "Waiting for container to start..."
|
||||||
|
sleep 3
|
||||||
|
|
||||||
# Show running container
|
# Check if container is running
|
||||||
|
if docker ps --filter name=skamp-app --format '{{.Names}}' | grep -q "skamp-app"; then
|
||||||
|
echo "✓ Container started successfully"
|
||||||
docker ps --filter name=skamp-app
|
docker ps --filter name=skamp-app
|
||||||
|
else
|
||||||
|
echo "✗ Container failed to start"
|
||||||
|
docker logs skamp-app
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up old images
|
||||||
|
echo "Cleaning up old images..."
|
||||||
|
docker image prune -af --filter "until=168h" || true
|
||||||
|
|
||||||
|
echo "=== Deployment completed ==="
|
||||||
|
|||||||
Reference in New Issue
Block a user