8000 Minor Fixes and Improvements by smashedr · Pull Request #27 · cssnr/stack-deploy-action · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Minor Fixes and Improvements #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).

Expand Down
72 changes: 38 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,8 +24,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!**
> ▶️ 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.
Expand All @@ -41,30 +42,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 | Input 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...

<details><summary>📟 Click Here to see how the deployment command is generated</summary>

Expand Down Expand Up @@ -92,7 +93,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.
Expand Down Expand Up @@ -122,7 +123,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
```

<details><summary>Results</summary>
Expand Down Expand Up @@ -461,14 +462,17 @@ https://github.com/cssnr/stack-deploy-action/network/dependents

The following rolling [tags](https://github.com/cssnr/stack-deploy-action/tags) are maintained.

| Version&nbsp;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) | ❌ | ❌ | ❌ 8000 | `vN.N.N` | `vN.N.N` |
| Version&nbsp;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 would 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.
Expand Down
38 changes: 25 additions & 13 deletions src/main.sh
9E81
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -143,6 +154,7 @@ else
read -r -a args <<< "${INPUT_ARGS}"
EXTRA_ARGS+=("${args[@]}")
fi
echo "::debug::EXTRA_ARGS: ${EXTRA_ARGS[*]}"

## Deploy Stack

Expand All @@ -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

Expand Down
Loading
0