Skip to content

Latest commit

 

History

History
128 lines (99 loc) · 4.68 KB

File metadata and controls

128 lines (99 loc) · 4.68 KB

Auto-deploy-sh

English|简体中文

This project aims to lower deployment barriers by providing an ultra-simple configuration and minimal dependency automated Docker deployment workflow. It helps developers quickly deploy applications to cloud servers without complex environment setups.

Deployment Commands

Project-Specific Configuration

Install:

npm install auto-deploy-sh -D

Run:

  • Add to package.json:
"scripts": {
  "deploy": "auto-deploy-sh"
}
  1. Execute in terminal:
npm run deploy

Global Configuration

Install:

npm install auto-deploy-sh -g

Run (in the root directory of the project to deploy):

auto-deploy-sh

Advanced Usage

Run with a custom configuration file:

auto-deploy-sh <config-path>
# OR
auto-deploy-sh -f <config-path>

Useful for multi-environment deployment (e.g., development, staging, production).

Configuration File Reference

The configuration file is fixed as deploy-config.json. If missing, the tool will guide you to create it (stored in the command execution directory by default) and automatically add deploy-config.json to .gitignore to prevent accidental commits of sensitive data.

⚠️ Critical Note: The configuration file contains sensitive information (e.g., passwords). If creating manually, ensure deploy-config.json is added to .gitignore.

Configuration Properties

  • host: Remote server IP address or domain name.
  • port: SSH port number.
  • user: SSH username for the remote server.
  • password: Password for the SSH user.
  • beforLaunch: Pre-deployment commands (array of strings) to execute locally before starting the deployment (e.g., ["npm run build"]).
  • Dockerfile: Optional. If omitted: 1. Check dockerBuildFiles for a file named Dockerfile; 2. If not found, search for Dockerfile in the first-level directory of the current execution environment.
  • dockerBuildFiles: Files/directories to include in the Docker build context (required for Dockerfile execution).
  • imageTag: Docker image tag, formatted as [registry-url/][username/project-name]:[tag] (e.g., my-registry.com/user/my-app:v1.0).
  • containerName: Unique name for the running container (ensures no conflicts with existing containers).
  • BindPorts: Port mapping, formatted as <host-port>:<container-port> (e.g., "8080:80").
  • restart (optional): Container restart policy, controls how Docker handles container restarts. The following options are supported:
    • no(default): The container will not restart automatically after it exits. It will also remain stopped after Docker or system restarts. Suitable for one-off tasks or debugging scenarios.
    • always: The container will always restart automatically if it stops. It will also start automatically after Docker or system restarts.Even if the container is manually stopped, it will be restarted again after Docker restarts.
    • unless-stopped(recommended): The container will automatically restart on failure and start after Docker or system restarts.If the container is manually stopped, it will not be restarted again, making it suitable for long-running production services.
    • on-failure: The container will restart only if it exits with a non-zero status code. It will not restart on normal exits (exit code 0).
  • Options: Optional advanced settings (all sub-properties are optional)
    • volumes: Volume mappings (array of strings), formatted as [host-path/volume-name]:[container-path]:[optional-flags] (e.g., ["/host/data:/container/data:ro"]).
    • networks: Connect the container to a custom Docker network (created via docker network create <network-name>) for inter-container communication.

Format Introduction

{
  "host": "string",
  "port": "number | string",
  "user": "string",
  "password": "string",
  "beforLaunch": "string[]",
  "Dockerfile": "string",
  "dockerBuildFiles": "string[]",
  "imageTag": "string",
  "containerName": "string",
  "BindPorts": "string",
  "restart": "'no' | 'always' | 'unless-stopped' | 'on-failure'",
  "Options": {
    "volumes": "string[]",
    "networks": "string[]"
  }
}

Full Configuration Example

{
  "host": "your-server-ip",
  "port": 22,
  "user": "ssh-username",
  "password": "ssh-password",
  "beforLaunch": ["npm run build"],
  "Dockerfile": "./Dockerfile",
  "dockerBuildFiles": ["./dist", "./package.json"],
  "imageTag": "my-app:latest",
  "containerName": "my-app-container",
  "BindPorts": "80:80",
  "restart": "unless-stopped",
  "Options": {
    "volumes": ["/host/logs:/app/logs:rw"],
    "networks": ["my-custom-network", "my-custom-network-1"]
  }
}