diff --git a/README.md b/README.md index 90e11fe..4c89ea4 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,26 @@ Robustly deploy your Docker Compose files to Docker Swarm or regular Docker Comp - ๐Ÿ” **Remote validation of Docker Compose files** - ๐Ÿงน **Automatic cleanup of temporary files** - ๐Ÿ“‹ **Detailed debug logs for easy troubleshooting** +- ๐Ÿ“‚ **Optional copying of Docker build context** +- ๐Ÿ“„ **Optional copying of `.env` files** --- ## ๐Ÿ“ฅ Inputs -| Input | Description | Required | Default | -|--------------------|--------------------------------------------------|----------|---------| -| `stack_name` | Docker stack or compose project name | โœ… Yes | - | -| `ssh_host` | SSH host | โœ… Yes | - | -| `ssh_user` | SSH username | โœ… Yes | - | -| `ssh_key` | SSH private key | โœ… Yes | - | -| `deploy_file` | Path to the processed deployment file | โœ… Yes | - | -| `deploy_mode` | Deployment mode: `swarm` or `compose` | โŒ No | `swarm` | -| `remote_temp_dir` | Remote temporary directory for deployment files | โŒ No | `/tmp` | +| Input | Description | Required | Default | +|-----------------------|----------------------------------------------------------------|----------|------------------| +| `stack_name` | Docker stack or compose project name | โœ… Yes | - | +| `ssh_host` | SSH host | โœ… Yes | - | +| `ssh_user` | SSH username | โœ… Yes | - | +| `ssh_key` | SSH private key | โœ… Yes | - | +| `deploy_file` | Path to the processed deployment file | โœ… Yes | - | +| `deploy_mode` | Deployment mode: `swarm` or `compose` | โŒ No | `swarm` | +| `remote_temp_dir` | Remote temporary directory for deployment files | โŒ No | `/tmp` | +| `copy_build_context` | Whether to copy Docker build context to remote host | โŒ No | `false` | +| `build_context_path` | Local path to Docker build context | โŒ No | `build-context` | +| `copy_env_file` | Whether to copy `.env` file to remote host | โŒ No | `false` | +| `env_file_path` | Local path to `.env` file | โŒ No | `.env` | --- @@ -56,7 +62,7 @@ This action supports two deployment modes: deploy_mode: swarm ``` -### Deploying with Docker Compose ๐Ÿณ +### Deploying with Docker Compose ๐Ÿณ (including build context and `.env` file) ```yaml - name: Deploy using Docker Compose ๐Ÿณ @@ -68,6 +74,10 @@ This action supports two deployment modes: ssh_key: ${{ secrets.SSH_KEY }} deploy_file: docker-compose.processed.yml deploy_mode: compose + copy_build_context: true + build_context_path: ./docker-context + copy_env_file: true + env_file_path: ./production.env ``` --- @@ -79,9 +89,11 @@ This action performs the following steps: 1. ๐Ÿ”‘ **Securely creates a temporary SSH key file** for authentication. 2. ๐Ÿ“ **Creates a secure temporary directory** on the remote host. 3. ๐Ÿ“ค **Copies your processed Docker Compose file** to the remote host. -4. ๐Ÿ” **Validates the Docker Compose file remotely** to ensure correctness. -5. ๐Ÿšข๐Ÿณ **Deploys your stack/project** based on the selected deployment mode. -6. ๐Ÿงน **Cleans up temporary files** both locally and remotely. +4. ๐Ÿ“‚ **Optionally copies Docker build context** to the remote host. +5. ๐Ÿ“„ **Optionally copies `.env` file** to the remote host. +6. ๐Ÿ” **Validates the Docker Compose file remotely** to ensure correctness. +7. ๐Ÿšข๐Ÿณ **Deploys your stack/project** based on the selected deployment mode. +8. ๐Ÿงน **Cleans up temporary files** both locally and remotely. --- diff --git a/action.yml b/action.yml index 918b358..7a884be 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,15 @@ inputs: description: 'Local path to Docker build context (directory containing Dockerfile). Defaults to ./build-context' required: false default: 'build-context' + copy_env_file: + description: 'Whether to copy .env file to remote host' + required: false + default: 'false' + env_file_path: + description: 'Local path to .env file' + required: false + default: '.env' + runs: using: 'composite' @@ -97,6 +106,21 @@ runs: "ls -lha '$REMOTE_TEMP_DIR'" fi + # Optionally copy env file + COPY_ENV_FILE="${{ inputs.copy_env_file }}" + ENV_FILE_PATH="${{ inputs.env_file_path }}" + + if [ "$COPY_ENV_FILE" == "true" ]; then + if [ ! -f "$ENV_FILE_PATH" ]; then + echo "โŒ ERROR: .env file '$ENV_FILE_PATH' does not exist." + exit 1 + fi + echo "๐Ÿ“„ DEBUG: Copying .env file from '$ENV_FILE_PATH' to remote host" + scp -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" \ + "$ENV_FILE_PATH" \ + "$SSH_USER@$SSH_HOST:$REMOTE_TEMP_DIR/.env" + fi + # Validate docker-compose file remotely before deploying echo "๐Ÿ” DEBUG: Validating Docker Compose file remotely" ssh -o StrictHostKeyChecking=no -i "$SSH_KEY_FILE" \