Loading repository data…
Loading repository data…
jefferyjob / repository
该项目是一个自动化部署脚本,通过 SSH 管理 Docker 容器,实现备份、更新、回滚、故障恢复,确保服务稳定和高可用性。This project is an automated deployment script that manages Docker containers through SSH to implement backup, update, rollback, and fault recovery to ensure service stability and high availability.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
English | 简体中文
This project is a neat CD (Continuous Deployment) automated deployment script designed for connecting to remote servers via SSH. It can efficiently perform operations such as backup, update, rollback and failure recovery of Docker containers. The project aims to simplify the application deployment process and ensure automatic rollback to the previous stable version when a failure occurs, thereby ensuring the stability and high availability of services. By using this script, users can not only improve their work efficiency, but also significantly reduce the risk of errors caused by manual operations.
| Variable Name | Required | Description |
|---|---|---|
| DOCKER_IMAGE | Yes | Docker image address used to pull and start the specified application container. (Example: example_ns/myapp or private configuration registry.cn-hangzhou.aliyuncs.com/example_ns/myapp) |
| CONTAINER_NAME | Yes | Docker container name, ensuring it doesn't conflict with other containers. (Example: my_container) |
| DOCKER_IMAGE_TAG | No | Version tag for image and container deployment, used to specify the Docker image version, defaults to latest. |
| DOCKER_STOP_GRACE_PERIOD | No | Graceful wait time (in seconds) when the container terminates (docker stop), defaults to 10. (Example: 30) |
| DOCKER_RUN_PARAMS | No | Additional runtime parameters passed when starting the container, which may include environment variables, port mappings, folder mappings, etc. (Example: -e ENV=prod -e TZ=Asia/Shanghai) |
| HEALTH_URL | No | Health check (Readiness) URL, used to determine whether a newly started container has completed initialization and is capable of providing services. (Example: ) |
http://127.0.0.1/health| DOCKER_REGISTRY_URL | No | The URL of the Docker private repository. If empty, the official DockerHub is used by default. (Example: registry.cn-hangzhou.aliyuncs.com) |
| DOCKER_USERNAME | No | The login account for the Docker private repository, used to pull images from the private image repository. |
| DOCKER_PASSWORD | No | The login password for the Docker private repository, used for authenticating private images. |
| BEFORE_FUNC | No | A pre-deployment hook function used to execute certain shell commands before deployment. (e.g., creating a log directory, pausing traffic, entering maintenance mode) |
| AFTER_FUNC | No | A post-deployment hook function used to execute certain shell commands after deployment. (e.g., restoring traffic, preheating cache, notifying the team) |
| SERVER_HOST | No | The server's hostname or IP address, used to connect to the target server via SSH. Required when AUTH_METHOD is pwd or key. (Example: 192.168.1.100) |
| SERVER_USER | No | The server login username. Ensure this user has permission to operate Docker. Required when AUTH_METHOD is pwd or key. (Example: root) |
| SERVER_PASSWORD | No | The server login password. Required when AUTH_METHOD is pwd. (Example: mypassword) |
| SERVER_SSH_PRIVATE_KEY | No | The server's SSH private key, used for key-based login to the server. Required when AUTH_METHOD is a key. (Example: -----BEGIN PRIVATE KEY----- xxx) |
BEFORE_FUNC and AFTER_FUNC example code
BEFORE_FUNC=$(cat <<'EOF'
echo "I am before function"
EOF
)
Method 1: Run the deployment script directly without downloading
curl -fsSL https://raw.githubusercontent.com/jefferyjob/deployments/refs/tags/v1.1.0/scripts/deploy.docker.sh | bash -s -- <AUTH_METHOD> <ACTION>
This method is suitable for temporary execution. It does not need to save the script file locally and directly passes it to bash for execution through the curl pipeline.
Method 2: Run the deployment script after downloading (recommended)
curl -o deploy.sh https://raw.githubusercontent.com/jefferyjob/deployments/refs/tags/v1.1.0/scripts/deploy.docker.sh
chmod +x deploy.sh
./deploy.sh <AUTH_METHOD> <ACTION>
This method is more recommended. After the script file is downloaded, it can be viewed or modified and can be executed repeatedly.
Tips:
AUTH_METHOD
ACTION
Docker pull command and starts the container.This library is licensed under the MIT. See the LICENSE file for details.