From 8d533c731131cbfe38278ad660b9c675adc47c1b Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Sat, 15 Mar 2025 20:07:36 -0700 Subject: [PATCH 1/4] Minor Fixes and Improvements --- README.md | 59 ++++++++++++++++++++++++++++------------------------- src/main.sh | 38 ++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 730e6e5..879a0ae 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ - [Contributing](#Contributing) > [!TIP] -> 💡 Now works with vanilla Docker hosts using **Compose. No Swarm Required!** -> Just set `mode: compose`. See the [Inputs](#Inputs) for more details... +> Now works with Docker **Compose. No Swarm Required!** +> ▶️ Simply set `mode: compose`. See [Inputs](#Inputs) for more details. This action deploys a docker stack from a compose file to a remote docker host using SSH Password or Key File Authentication. You can also optionally authenticate against a private registry using a username and password. @@ -41,30 +41,30 @@ For more details see [action.yaml](action.yaml) and [src/main.sh](src/main.sh). ## Inputs -| Input | Required | Default | Description | -| :------------------- | :----------: | :---------------------------------- | :---------------------------------------- | -| `name` | **Yes** | - | Docker Stack/Project Name \* | -| `file` | - | `docker-compose.yaml` | Docker Stack/Compose File | -| `mode`**¹** | - | `swarm` | Deploy Mode: [`swarm`, `compose`] \* | -| `args`**¹** | - | `--remove-orphans --force-recreate` | Additional Arguments for **Compose** \* | -| `host` | **Yes** | - | Remote Docker Hostname or IP \* | -| `port` | - | `22` | Remote Docker Port | -| `user` | **Yes** | - | Remote Docker Username | -| `pass` | or `ssh_key` | - | Remote Docker Password \* | -| `ssh_key` | or `pass` | - | Remote SSH Key File \* | -| `env_file` | - | - | Docker Environment File \* | -| `detach`**²** | - | `true` | Detach Flag, `false`, to disable \* | -| `prune`**²** | - | `false` | Prune Flag, `true`, to enable | -| `resolve_image`**²** | - | `always` | Resolve [`always`, `changed`, `never`] \* | -| `registry_auth`**²** | - | - | Enable Registry Authentication \* | -| `registry_host` | - | - | Registry Authentication Host \* | -| `registry_user` | - | - | Registry Authentication Username \* | -| `registry_pass` | - | - | Registry Authentication Password \* | -| `summary` | - | `true` | Add Job Summary \* | - -> **¹** Compose Only. View the [Docs](https://docs.docker.com/reference/cli/docker/compose/up/). -> **²** Swarm Only. View the [Docs](https://docs.docker.com/reference/cli/docker/stack/deploy/). -> \* See Below for more details... +| Input Name | Is Required | Default Value | Short Description | +| :------------------- | :--------------: | :---------------------------------- | :---------------------------------------- | +| `name` | **Yes** | - | Docker Stack/Project Name \* | +| `file` | - | `docker-compose.yaml` | Docker Stack/Compose File | +| `mode`**¹** | - | `swarm` | Deploy Mode: [`swarm`, `compose`] \* | +| `args`**¹** | - | `--remove-orphans --force-recreate` | Additional Arguments for **Compose** \* | +| `host` | **Yes** | - | Remote Docker Hostname or IP \* | +| `port` | - | `22` | Remote Docker Port | +| `user` | **Yes** | - | Remote Docker Username | +| `pass` | or `ssh_key` | - | Remote Docker Password \* | +| `ssh_key` | or `pass` | - | Remote SSH Key File \* | +| `env_file` | - | - | Docker Environment File \* | +| `detach`**²** | - | `true` | Detach Flag, `false`, to disable \* | +| `prune`**²** | - | `false` | Prune Flag, `true`, to enable | +| `resolve_image`**²** | - | `always` | Resolve [`always`, `changed`, `never`] \* | +| `registry_auth`**²** | - | - | Enable Registry Authentication \* | +| `registry_host` | - | - | Registry Authentication Host \* | +| `registry_user` | - | - | Registry Authentication Username \* | +| `registry_pass` | - | - | Registry Authentication Password \* | +| `summary` | - | `true` | Add Job Summary \* | + +> **¹** Compose Only, view the [Docs](https://docs.docker.com/reference/cli/docker/compose/up/). +> **²** Swarm Only, view the [Docs](https://docs.docker.com/reference/cli/docker/stack/deploy/). +> \* More details below...
📟 Click Here to see how the deployment command is generated @@ -92,7 +92,7 @@ Use an empty string to override. For more details, see the compose **host:** The hostname or IP address of the remote docker server to deploy too. If your hostname is behind a proxy like Cloudflare you will need to use the IP address. -**pass/ssh_key:** You must provide either a `pass` or `ssh_key`, but not both. +**pass/ssh_key:** You must provide either a `pass` or `ssh_key`, not both. **env_file:** Variables in this file are exported before running stack deploy. To use a docker `env_file` specify it in your compose file and make it available in a previous step. @@ -122,7 +122,7 @@ To view a workflow run, click on a recent [Test](https://github.com/cssnr/stack- 🚀 Swarm Stack `test_stack-deploy` Successfully Deployed. ```text -docker stack deploy --detach=false --resolve-image=changed -c docker-compose.yaml test_stack-deploy +docker stack deploy -c docker-compose.yaml --detach=false --resolve-image=changed test_stack-deploy ```
Results @@ -469,6 +469,9 @@ The following rolling [tags](https://github.com/cssnr/stack-deploy-action/tags) You can view the release notes for each version on the [releases](https://github.com/cssnr/stack-deploy-action/releases) page. +The Major tag is recommended. It is the most up-to-date and always backwards compatible. +Breaking changes will always result in a major version bump. At a minimum you should use a Minor tag. + ## Features - Deploy to a remote host using SSH or Password authentication. diff --git a/src/main.sh b/src/main.sh index bfd5220..791ff34 100644 --- a/src/main.sh +++ b/src/main.sh @@ -22,12 +22,14 @@ function cleanup_trap() { ## Check Variables +INPUT_MODE=$(echo "${INPUT_MODE}" | xargs | tr '[:upper:]' '[:lower:]') +echo "::debug::INPUT_MODE: ${INPUT_MODE}" + if [[ "${INPUT_MODE}" == "swarm" ]];then if [[ "${INPUT_ARGS}" != "--remove-orphans --force-recreate" ]];then echo "::warning::You set compose args but mode is swarm!" fi -else -#elif [[ "${INPUT_MODE}" == "compose" ]];then +elif [[ "${INPUT_MODE}" == "compose" ]];then if [[ "${INPUT_DETACH}" != "true" ]];then echo "::warning::You set detach but mode is compose!" fi @@ -37,9 +39,10 @@ else if [[ "${INPUT_RESOLVE_IMAGE}" != "always" ]];then echo "::warning::You set resolve_image but mode is compose!" fi -#else -# echo "::error::Input mode must be set to swarm or compose!" -# exit 1 +else + echo "::error::Input mode must be set to swarm or compose!" + echo "⛔ Input Parsing Failed. The mode must be set to swarm or compose." + exit 1 fi ## Setup Script @@ -52,6 +55,7 @@ echo "Script: ${0}" echo "Current Directory: $(pwd)" echo "Home Directory: ${HOME}" echo "SSH Directory: ${SSH_DIR}" +echo "Deploy Mode: ${INPUT_MODE}" mkdir -p "${SSH_DIR}" ~/.ssh chmod 0700 "${SSH_DIR}" ~/.ssh @@ -93,13 +97,18 @@ echo "::endgroup::" ## Export Environment File -if [[ -f "${INPUT_ENV_FILE}" ]];then - echo -e "::group::Sourcing Environment File: \u001b[36;1m${INPUT_ENV_FILE}" - stat "${INPUT_ENV_FILE}" - set -a - # shellcheck disable=SC1090 - source "${INPUT_ENV_FILE}" -echo "::endgroup::" +if [[ -n "${INPUT_ENV_FILE}" ]];then + if [[ -f "${INPUT_ENV_FILE}" ]];then + echo -e "::group::Sourcing Environment File: \u001b[36;1m${INPUT_ENV_FILE}" + set -a + # shellcheck disable=SC1090 + source "${INPUT_ENV_FILE}" + echo "::endgroup::" + else + echo "::error::Environment File Not Found: ${INPUT_ENV_FILE}" + fi +else + echo "::debug::No environment file specified, skipping export file..." fi ## Docker Login @@ -110,6 +119,8 @@ if [[ -n "${INPUT_REGISTRY_USER}" && -n "${INPUT_REGISTRY_PASS}" ]];then docker login --username "${INPUT_REGISTRY_USER}" --password-stdin "${INPUT_REGISTRY_HOST}" INPUT_REGISTRY_AUTH="true" echo "::endgroup::" +else + echo "::debug::No registry user or password, skipping docker login..." fi ## Collect Arguments @@ -143,6 +154,7 @@ else read -r -a args <<< "${INPUT_ARGS}" EXTRA_ARGS+=("${args[@]}") fi +echo "::debug::EXTRA_ARGS: ${EXTRA_ARGS[*]}" ## Deploy Stack @@ -169,7 +181,7 @@ echo "::endgroup::" if [[ "${INPUT_SUMMARY}" == "true" ]];then echo "📝 Writing Job Summary" # shellcheck source=/src/summary.sh - source /src/summary.sh >> "${GITHUB_STEP_SUMMARY}" ||\ + source /src/summary.sh >> "${GITHUB_STEP_SUMMARY}" || echo "::error::Failed to Write Job Summary!" fi From b219a42f1af32ae6cd0b9ae5c55d5f68bebb4b85 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Sat, 15 Mar 2025 20:32:03 -0700 Subject: [PATCH 2/4] Updates --- .github/workflows/release.yaml | 1 + README.md | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 379c315..40ea754 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,6 +18,7 @@ jobs: uses: cssnr/update-version-tags-action@v1 - name: "Debug Tags" + continue-on-error: true run: | echo "github.ref_name: ${{ github.ref_name }}" echo "steps.tags.outputs.tags: ${{ steps.tags.outputs.tags }}" diff --git a/README.md b/README.md index 879a0ae..d9284c2 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ - [Contributing](#Contributing) > [!TIP] -> Now works with Docker **Compose. No Swarm Required!** -> ▶️ Simply set `mode: compose`. See [Inputs](#Inputs) for more details. +> Now works with Docker **Compose. No Swarm Required!** +> ▶️ Set `mode: compose`. See [Inputs](#Inputs) for more details... This action deploys a docker stack from a compose file to a remote docker host using SSH Password or Key File Authentication. You can also optionally authenticate against a private registry using a username and password. @@ -461,16 +461,16 @@ https://github.com/cssnr/stack-deploy-action/network/dependents The following rolling [tags](https://github.com/cssnr/stack-deploy-action/tags) are maintained. -| Version Tag | Rolling | Bugs | Feat. | Target | Example | -| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----: | :--: | :---: | :------- | :------- | -| [![GitHub Tag Major](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*&style=for-the-badge&label=%20&color=44cc10)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ✅ | `vN.x.x` | `vN` | -| [![GitHub Tag Minor](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*.*&style=for-the-badge&label=%20&color=blue)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ❌ | `vN.N.x` | `vN.N` | -| [![GitHub Release](https://img.shields.io/github/v/release/cssnr/stack-deploy-action?style=for-the-badge&label=%20&color=red)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ❌ | ❌ | ❌ | `vN.N.N` | `vN.N.N` | +| Version Tag | Rolling | Bugs | Feat. | Name | Target | Example | +| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----: | :--: | :---: | :-------: | :------: | :------- | +| [![GitHub Tag Major](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*&style=for-the-badge&label=%20&color=44cc10)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ✅ | **Major** | `vN.x.x` | `vN` | +| [![GitHub Tag Minor](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*.*&style=for-the-badge&label=%20&color=blue)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ✅ | ✅ | ❌ | **Minor** | `vN.N.x` | `vN.N` | +| [![GitHub Release](https://img.shields.io/github/v/release/cssnr/stack-deploy-action?style=for-the-badge&label=%20&color=red)](https://github.com/cssnr/stack-deploy-action/releases/latest) | ❌ | ❌ | ❌ | **Micro** | `vN.N.N` | `vN.N.N` | You can view the release notes for each version on the [releases](https://github.com/cssnr/stack-deploy-action/releases) page. -The Major tag is recommended. It is the most up-to-date and always backwards compatible. -Breaking changes will always result in a major version bump. At a minimum you should use a Minor tag. +The **Major** tag is recommended. It is the most up-to-date and always backwards compatible. +Breaking changes would result in a **Major** version bump. At a minimum you should use a **Minor** tag. ## Features From c687f1a9a8f94b6320eca8abfcc3dc1ca89fd925 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Sun, 16 Mar 2025 01:05:43 -0700 Subject: [PATCH 3/4] Updates --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9284c2..9c14732 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ For more details see [action.yaml](action.yaml) and [src/main.sh](src/main.sh). ## Inputs -| Input Name | Is Required | Default Value | Short Description | +| Input Name | Is Required | Default Value | Input Description | | :------------------- | :--------------: | :---------------------------------- | :---------------------------------------- | | `name` | **Yes** | - | Docker Stack/Project Name \* | | `file` | - | `docker-compose.yaml` | Docker Stack/Compose File | From cd8d8d112f0ae99c2e0e0bc9694ff063dea9b762 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Mon, 17 Mar 2025 20:08:03 -0700 Subject: [PATCH 4/4] Update README.md --- CONTRIBUTING.md | 4 ++-- README.md | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8bd3e0b..8b712cc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,7 @@ > [!WARNING] > This guide is a work in progress and may not be complete. -Note: This guide is not updated for Compose but those tests work the same way. +Note: This guide is not updated for Compose but those tests work similar. ## Workflow @@ -52,7 +52,7 @@ act -j test -e event.json The flag `-e event.json` disabled test #2 which tests SSH auth and registry auth. -To test both SSH and authb and registry auth (run test #2) do the following. +To test both SSH and registry auth (run test #2) do the following. 1. Create a `.vars` file and add the vars and secrets from test #2 under [GitHub](#GitHub). diff --git a/README.md b/README.md index 9c14732..106708f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ [![Workflow Lint](https://img.shields.io/github/actions/workflow/status/cssnr/stack-deploy-action/lint.yaml?logo=github&label=lint)](https://github.com/cssnr/stack-deploy-action/actions/workflows/lint.yaml) [![GitHub Last Commit](https://img.shields.io/github/last-commit/cssnr/stack-deploy-action?logo=github&label=updated)](https://github.com/cssnr/stack-deploy-action/graphs/commit-activity) [![Codeberg Last Commit](https://img.shields.io/gitea/last-commit/cssnr/stack-deploy-action/master?gitea_url=https%3A%2F%2Fcodeberg.org%2F&logo=codeberg&logoColor=white&label=updated)](https://codeberg.org/cssnr/stack-deploy-action) -[![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/stack-deploy-action?logo=htmx)](https://github.com/cssnr/stack-deploy-action) +[![GitHub Top Language](https://img.shields.io/github/languages/top/cssnr/stack-deploy-action?logo=sharp&logoColor=white)](https://github.com/cssnr/stack-deploy-action) +[![GitHub repo size](https://img.shields.io/github/repo-size/cssnr/stack-deploy-action?logo=bookstack&logoColor=white&label=size)](https://github.com/cssnr/stack-deploy-action) [![GitHub Discussions](https://img.shields.io/github/discussions/cssnr/stack-deploy-action)](https://github.com/cssnr/stack-deploy-action/discussions) [![GitHub Forks](https://img.shields.io/github/forks/cssnr/stack-deploy-action?style=flat&logo=github)](https://github.com/cssnr/stack-deploy-action/forks) [![GitHub Repo Stars](https://img.shields.io/github/stars/cssnr/stack-deploy-action?style=flat&logo=github)](https://github.com/cssnr/stack-deploy-action/stargazers)