name: Deploy to Production on: push: branches: - prod jobs: deploy: runs-on: [docker, host] steps: - name: Prepare workspace run: | rm -rf /tmp/olaper || true mkdir -p /tmp/olaper cd /tmp/olaper apk update && apk add openssh docker-cli mkdir -p ~/.ssh chmod 700 ~/.ssh ssh-keyscan -p 2222 10.25.100.250 >> ~/.ssh/known_hosts git clone --branch prod ssh://git@10.25.100.250:2222/serty/olaper.git . - name: Build Docker image run: | cd /tmp/olaper docker build -t olaper:latest . - name: Create volume (if not exists) run: | docker volume create olaper_data || true - name: Stop and remove old containers run: | # Stop and remove container named olaper if exists docker stop olaper || true docker rm olaper || true # Stop and remove any container using port 5005 PORT=5005 CONTAINER_IDS=$(docker ps -q --filter "publish=$PORT") if [ -n "$CONTAINER_IDS" ]; then echo "Stopping containers using port $PORT..." docker stop $CONTAINER_IDS docker rm $CONTAINER_IDS fi - name: Run new container run: | docker run -d \ --name olaper \ --restart always \ -p 5005:5005 \ -e SECRET_KEY=${{ secrets.SECRET_KEY }} \ -e ENCRYPTION_KEY=${{ secrets.ENCRYPTION_KEY }} \ -v olaper_data:/opt/olaper/data \ olaper:latest - name: Cleanup run: rm -rf /tmp/olaper || true