Skip to content

Commit 006846d

Browse files
committed
Test Context on Dockerfile Action
1 parent 66725ea commit 006846d

8 files changed

Lines changed: 202 additions & 109 deletions

File tree

.github/disabled/test.yaml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: "Test"
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "18 18 * * 1,3,5"
7+
push:
8+
branches: ["**"]
9+
paths:
10+
- "dist/**"
11+
- "src/**"
12+
- ".github/workflows/test.yaml"
13+
- "Dockerfile"
14+
- "package*.json"
15+
- "requirements*.txt"
16+
- "action.yaml"
17+
18+
env:
19+
PRIVATE_IMAGE: ${{ vars.PRIVATE_IMAGE || 'smashedr/alpine-private:latest' }}
20+
21+
concurrency:
22+
group: ${{ github.workflow }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
test:
27+
name: "Test"
28+
if: ${{ !contains(github.event.head_commit.message, '#notest') }}
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 5
31+
32+
steps:
33+
- name: "Checkout"
34+
uses: actions/checkout@v5
35+
36+
#- name: "Debug event.json"
37+
# run: |
38+
# cat "${GITHUB_EVENT_PATH}"
39+
40+
- name: "1: Write YAML"
41+
if: ${{ !cancelled() }}
42+
uses: teunmooij/yaml@v1
43+
with:
44+
to-file: "docker-compose.yaml"
45+
data: |
46+
{"version":"3.8","services":{"alpine":{"image":"alpine:latest","command":"tail -f /dev/null"}}}
47+
48+
- name: "1: Test Password"
49+
if: ${{ !cancelled() }}
50+
uses: ./
51+
with:
52+
name: test_stack-deploy
53+
file: docker-compose.yaml
54+
host: ${{ secrets.DOCKER_HOST }}
55+
port: ${{ secrets.DOCKER_PORT }}
56+
user: ${{ secrets.DOCKER_USER }}
57+
pass: ${{ secrets.DOCKER_PASS }}
58+
#ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
59+
detach: false
60+
resolve_image: "changed"
61+
62+
- name: "2: Write YAML"
63+
if: ${{ !cancelled() && !github.event.act }}
64+
uses: teunmooij/yaml@v1
65+
with:
66+
to-file: "docker-compose.yaml"
67+
data: |
68+
{"version":"3.8","services":{"alpine":{"image":"${{ env.PRIVATE_IMAGE }}","command":"tail -f /dev/null"}}}
69+
70+
- name: "2: Test SSH and Auth"
71+
if: ${{ !cancelled() && !github.event.act }}
72+
uses: ./
73+
with:
74+
name: test_stack-deploy
75+
file: docker-compose.yaml
76+
host: ${{ secrets.DOCKER_HOST }}
77+
port: ${{ secrets.DOCKER_PORT }}
78+
user: ${{ secrets.DOCKER_USER }}
79+
#pass: ${{ secrets.DOCKER_PASS }}
80+
ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
81+
prune: true
82+
registry_user: ${{ vars.DOCKER_HUB_USER }}
83+
registry_pass: ${{ secrets.DOCKER_HUB_PASS }}
84+
summary: false
85+
86+
- name: "3: Write YAML"
87+
if: ${{ !cancelled() && !github.event.act }}
88+
uses: teunmooij/yaml@v1
89+
with:
90+
to-file: "docker-compose.yaml"
91+
data: |
92+
{"version":"3.8","services":{"alpine":{"image":"alpine:latest","command":"tail -f /dev/null"}}}
93+
94+
- name: "3: Test Compose"
95+
if: ${{ !cancelled() && !github.event.act }}
96+
uses: ./
97+
with:
98+
name: test_stack-deploy-compose
99+
file: docker-compose.yaml
100+
host: ${{ secrets.DOCKER_HOST }}
101+
port: ${{ secrets.DOCKER_PORT }}
102+
user: ${{ secrets.DOCKER_USER }}
103+
pass: ${{ secrets.DOCKER_PASS }}
104+
#ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
105+
mode: compose
106+
summary: false
107+
108+
- name: "4: Write YAML"
109+
if: ${{ !cancelled() }}
110+
uses: teunmooij/yaml@v1
111+
with:
112+
to-file: "docker-compose.yaml"
113+
data: |
114+
{"version":"3.8","services":{"alpine":{"image":"${{ env.PRIVATE_IMAGE }}","command":"tail -f /dev/null"}}}
115+
116+
- name: "4: Test Compose SSH and Auth"
117+
if: ${{ !cancelled() }}
118+
uses: ./
119+
with:
120+
name: test_stack-deploy-compose
121+
file: docker-compose.yaml
122+
host: ${{ secrets.DOCKER_HOST }}
123+
port: ${{ secrets.DOCKER_PORT }}
124+
user: ${{ secrets.DOCKER_USER }}
125+
#pass: ${{ secrets.DOCKER_PASS }}
126+
ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
127+
mode: compose
128+
registry_user: ${{ vars.DOCKER_HUB_USER }}
129+
registry_pass: ${{ secrets.DOCKER_HUB_PASS }}
130+
131+
- name: "Schedule Failure Notification"
132+
if: ${{ failure() && github.event_name == 'schedule' }}
133+
uses: sarisia/actions-status-discord@v1
134+
with:
135+
webhook: ${{ secrets.DISCORD_WEBHOOK }}

.github/workflows/test.yaml

Lines changed: 17 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -37,99 +37,37 @@ jobs:
3737
# run: |
3838
# cat "${GITHUB_EVENT_PATH}"
3939

40-
- name: "1: Write YAML"
40+
- name: "Write YAML"
4141
if: ${{ !cancelled() }}
4242
uses: teunmooij/yaml@v1
4343
with:
4444
to-file: "docker-compose.yaml"
4545
data: |
4646
{"version":"3.8","services":{"alpine":{"image":"alpine:latest","command":"tail -f /dev/null"}}}
4747
48-
- name: "1: Test Password"
48+
- name: "PRE Step"
49+
continue-on-error: true
50+
run: |
51+
docker context ls
52+
53+
- name: "Test Action"
4954
if: ${{ !cancelled() }}
5055
uses: ./
5156
with:
52-
name: test_stack-deploy
53-
file: docker-compose.yaml
57+
#name: test_stack-deploy
58+
#file: docker-compose.yaml
5459
host: ${{ secrets.DOCKER_HOST }}
5560
port: ${{ secrets.DOCKER_PORT }}
5661
user: ${{ secrets.DOCKER_USER }}
5762
pass: ${{ secrets.DOCKER_PASS }}
5863
#ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
59-
detach: false
60-
resolve_image: "changed"
61-
62-
- name: "2: Write YAML"
63-
if: ${{ !cancelled() && !github.event.act }}
64-
uses: teunmooij/yaml@v1
65-
with:
66-
to-file: "docker-compose.yaml"
67-
data: |
68-
{"version":"3.8","services":{"alpine":{"image":"${{ env.PRIVATE_IMAGE }}","command":"tail -f /dev/null"}}}
69-
70-
- name: "2: Test SSH and Auth"
71-
if: ${{ !cancelled() && !github.event.act }}
72-
uses: ./
73-
with:
74-
name: test_stack-deploy
75-
file: docker-compose.yaml
76-
host: ${{ secrets.DOCKER_HOST }}
77-
port: ${{ secrets.DOCKER_PORT }}
78-
user: ${{ secrets.DOCKER_USER }}
79-
#pass: ${{ secrets.DOCKER_PASS }}
80-
ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
64+
#detach: false
8165
prune: true
82-
registry_user: ${{ vars.DOCKER_HUB_USER }}
83-
registry_pass: ${{ secrets.DOCKER_HUB_PASS }}
84-
summary: false
85-
86-
- name: "3: Write YAML"
87-
if: ${{ !cancelled() && !github.event.act }}
88-
uses: teunmooij/yaml@v1
89-
with:
90-
to-file: "docker-compose.yaml"
91-
data: |
92-
{"version":"3.8","services":{"alpine":{"image":"alpine:latest","command":"tail -f /dev/null"}}}
93-
94-
- name: "3: Test Compose"
95-
if: ${{ !cancelled() && !github.event.act }}
96-
uses: ./
97-
with:
98-
name: test_stack-deploy-compose
99-
file: docker-compose.yaml
100-
host: ${{ secrets.DOCKER_HOST }}
101-
port: ${{ secrets.DOCKER_PORT }}
102-
user: ${{ secrets.DOCKER_USER }}
103-
pass: ${{ secrets.DOCKER_PASS }}
104-
#ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
105-
mode: compose
106-
summary: false
107-
108-
- name: "4: Write YAML"
109-
if: ${{ !cancelled() }}
110-
uses: teunmooij/yaml@v1
111-
with:
112-
to-file: "docker-compose.yaml"
113-
data: |
114-
{"version":"3.8","services":{"alpine":{"image":"${{ env.PRIVATE_IMAGE }}","command":"tail -f /dev/null"}}}
115-
116-
- name: "4: Test Compose SSH and Auth"
117-
if: ${{ !cancelled() }}
118-
uses: ./
119-
with:
120-
name: test_stack-deploy-compose
121-
file: docker-compose.yaml
122-
host: ${{ secrets.DOCKER_HOST }}
123-
port: ${{ secrets.DOCKER_PORT }}
124-
user: ${{ secrets.DOCKER_USER }}
125-
#pass: ${{ secrets.DOCKER_PASS }}
126-
ssh_key: ${{ secrets.DOCKER_SSH_KEY }}
127-
mode: compose
128-
registry_user: ${{ vars.DOCKER_HUB_USER }}
129-
registry_pass: ${{ secrets.DOCKER_HUB_PASS }}
66+
resolve_image: "changed"
67+
mode: context
68+
#args: --remove-orphans --force-recreate
13069

131-
- name: "Schedule Failure Notification"
132-
if: ${{ failure() && github.event_name == 'schedule' }}
133-
uses: sarisia/actions-status-discord@v1
134-
with:
135-
webhook: ${{ secrets.DISCORD_WEBHOOK }}
70+
- name: "POST Step"
71+
continue-on-error: true
72+
run: |
73+
docker context ls

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ __pycache__/
77
.env
88
.secrets
99
.vars
10+
.github/workflows/local.yaml

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ RUN apk add --update --no-cache bash sshpass
44

55
COPY src/ /src
66

7-
ENTRYPOINT ["bash", "/src/main.sh"]
7+
#ENTRYPOINT ["bash", "/src/main.sh"]

README.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Don't see your feature here? Please help by submitting a [Feature Request](https
7777
| :------------------- | :----------: | :---------------------------------- | :------------------------------------------------------------ |
7878
| `name` | **Yes** | - | Docker Stack/Project Name \* |
7979
| `file` | - | `docker-compose.yaml` | Docker Stack/Compose File(s) \* |
80-
| `mode`**¹** | - | `swarm` | Deploy Mode [`swarm`, `compose`] \* |
80+
| `mode`**¹** | - | `swarm` | Deploy Mode [`swarm`, `compose`, `context`] \* |
8181
| `args`**¹** | - | `--remove-orphans --force-recreate` | Additional **Compose** Arguments \* |
8282
| `host` | **Yes** | - | Remote Docker Hostname or IP \* |
8383
| `port` | - | `22` | Remote Docker Port |
@@ -122,7 +122,8 @@ Compose Note: `"${STACK_FILES[@]}"` is an array of `-f docker-compose.yaml` for
122122
**file:** Stack file or Compose file(s). Multiple files can be provided, space seperated, and a `-f` will be prepended to each.
123123
Example: `web.yaml db.yaml`.
124124

125-
**mode:** _Compose only._ Set this to `compose` to use `compose up` instead of `stack deploy` for non-swarm hosts.
125+
**mode:** _Compose only._ This can be `swarm`, `compose`, `context`.
126+
If using `context` you need to add your deployment commands in a subsequent step.
126127

127128
**args:** _Compose only._ Compose arguments to pass to the `compose up` command. Only used for `mode: compose` deployments.
128129
The `detach` flag defaults to false for compose. With no args the default is `--remove-orphans --force-recreate`.
@@ -551,48 +552,45 @@ Additionally, you can support other GitHub Actions I have published:
551552
- [VirusTotal Action](https://github.com/cssnr/virustotal-action?tab=readme-ov-file#readme)
552553
- [Mirror Repository Action](https://github.com/cssnr/mirror-repository-action?tab=readme-ov-file#readme)
553554
- [Update Version Tags Action](https://github.com/cssnr/update-version-tags-action?tab=readme-ov-file#readme)
555+
- [Docker Tags Action](https://github.com/cssnr/docker-tags-action?tab=readme-ov-file#readme)
554556
- [Update JSON Value Action](https://github.com/cssnr/update-json-value-action?tab=readme-ov-file#readme)
557+
- [JSON Key Value Check Action](https://github.com/cssnr/json-key-value-check-action?tab=readme-ov-file#readme)
555558
- [Parse Issue Form Action](https://github.com/cssnr/parse-issue-form-action?tab=readme-ov-file#readme)
556559
- [Cloudflare Purge Cache Action](https://github.com/cssnr/cloudflare-purge-cache-action?tab=readme-ov-file#readme)
557560
- [Mozilla Addon Update Action](https://github.com/cssnr/mozilla-addon-update-action?tab=readme-ov-file#readme)
558-
- [Docker Tags Action](https://github.com/cssnr/docker-tags-action?tab=readme-ov-file#readme)
559561
- [Package Changelog Action](https://github.com/cssnr/package-changelog-action?tab=readme-ov-file#readme)
560562
- [NPM Outdated Check Action](https://github.com/cssnr/npm-outdated-action?tab=readme-ov-file#readme)
561563
- [Label Creator Action](https://github.com/cssnr/label-creator-action?tab=readme-ov-file#readme)
562564
- [Algolia Crawler Action](https://github.com/cssnr/algolia-crawler-action?tab=readme-ov-file#readme)
563565
- [Upload Release Action](https://github.com/cssnr/upload-release-action?tab=readme-ov-file#readme)
564566
- [Check Build Action](https://github.com/cssnr/check-build-action?tab=readme-ov-file#readme)
565567
- [Web Request Action](https://github.com/cssnr/web-request-action?tab=readme-ov-file#readme)
568+
- [Get Commit Action](https://github.com/cssnr/get-commit-action?tab=readme-ov-file#readme)
566569

567-
<details><summary>Unpublished Actions ❔</summary>
568-
569-
These actions' are not published on the Marketplace, but may be useful.
570-
571-
Generic Actions:
572-
573-
- [cssnr/draft-release-action](https://github.com/cssnr/draft-release-action) - Keep a draft release ready to publish.
574-
- [cssnr/env-json-action](https://github.com/cssnr/env-json-action) - Convert env file to json or vice versa.
575-
- [cssnr/get-commit-action](https://github.com/cssnr/get-commit-action) - Get the current commit with full details.
570+
<details><summary>❔ Unpublished Actions</summary>
576571

577-
Specific Actions:
572+
These actions are not published on the Marketplace, but may be useful.
578573

579-
- [cssnr/push-artifacts-action](https://github.com/cssnr/push-artifacts-action) - Sync's artifacts to a remote host.
580-
- [smashedr/update-release-notes-action](https://github.com/smashedr/update-release-notes-action) - Update release notes.
574+
- [cssnr/draft-release-action](https://github.com/cssnr/draft-release-action?tab=readme-ov-file#readme) - Keep a draft release ready to publish.
575+
- [cssnr/env-json-action](https://github.com/cssnr/env-json-action?tab=readme-ov-file#readme) - Convert env file to json or vice versa.
576+
- [cssnr/push-artifacts-action](https://github.com/cssnr/push-artifacts-action?tab=readme-ov-file#readme) - Sync files to a remote host with rsync.
577+
- [smashedr/update-release-notes-action](https://github.com/smashedr/update-release-notes-action?tab=readme-ov-file#readme) - Update release notes.
578+
- [smashedr/combine-release-notes-action](https://github.com/smashedr/combine-release-notes-action?tab=readme-ov-file#readme) - Combine release notes.
581579

582580
---
583581

584582
</details>
585583

586-
<details><summary>Action Templates 📝</summary>
584+
<details><summary>📝 Template Actions</summary>
587585

588-
These are basic actions' templates that I use for creating new actions.
586+
These are basic action templates that I use for creating new actions.
589587

590588
- [js-test-action](https://github.com/smashedr/js-test-action?tab=readme-ov-file#readme) - JavaScript
591589
- [py-test-action](https://github.com/smashedr/py-test-action?tab=readme-ov-file#readme) - Python
592590
- [ts-test-action](https://github.com/smashedr/ts-test-action?tab=readme-ov-file#readme) - TypeScript
593591
- [docker-test-action](https://github.com/smashedr/docker-test-action?tab=readme-ov-file#readme) - Docker Image
594592

595-
Note: The `docker-action` template runs from, builds for, and pushes images to [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
593+
Note: The `docker-test-action` builds, runs and pushes images to [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
596594

597595
---
598596

action.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ branding:
88
inputs:
99
name:
1010
description: "Docker Stack Name"
11-
required: true
1211
file:
1312
description: "Docker Compose File"
14-
required: false
1513
default: "docker-compose.yaml"
1614
mode:
1715
description: "Deploy Mode"
18-
required: false
1916
default: "swarm"
2017
args:
2118
description: "Compose Arguments"
@@ -76,3 +73,5 @@ inputs:
7673
runs:
7774
using: "docker"
7875
image: "Dockerfile"
76+
entrypoint: "bash /src/main.sh"
77+
post-entrypoint: "bash /src/cleanup.sh"

src/cleanup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
# https://github.com/cssnr/stack-deploy-action
3+
4+
echo "STATE_CLEANUP: ${STATE_CLEANUP}"
5+
6+
if [[ -n "${STATE_CLEANUP}" ]];then
7+
echo "🧹 Cleaning Up authorized_keys"
8+
ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=30 -p "${INPUT_PORT}" "${INPUT_USER}@${INPUT_HOST}" \
9+
"sed -i '/docker-stack-deploy-action/d' ~/.ssh/authorized_keys"
10+
fi

0 commit comments

Comments
 (0)