Skip to content

Commit 656fdcb

Browse files
Add restart-only flag
1 parent 17f0dae commit 656fdcb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The following inputs can be used as `step.with` keys:
5555
| `docker-target-port` | String | `80` | Docker target port of container. |
5656
| `docker-opts` | String | | More docker options to create docker service. eg. `--log-driver=awslogs --log-opt awslogs-group=my-logs --log-opt awslogs-region=us-east-1`. |
5757
| `prune` | Boolean | `true` | On prune true, Will cleanup exitied containers and unused images. |
58+
| `restart-only` | Boolean | `false` | On restart-only true, Service will be force restarted with set replicas. |
5859

5960
## Contributing
6061

action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ inputs:
6363
description: "On prune true, Will cleanup exitied containers and unused images."
6464
default: true
6565
required: false
66+
restart-only:
67+
description: "On restart-only true, Service will be force restarted with set replicas."
68+
default: false
69+
required: false
6670

6771
runs:
6872
using: "composite"
@@ -95,6 +99,7 @@ runs:
9599
uses: aws-actions/amazon-ecr-login@v2
96100

97101
- name: EC2 Docker Service Deploy
102+
if: ${{ inputs.restart-only != 'true' }}
98103
uses: appleboy/ssh-action@master
99104
with:
100105
host: ${{ inputs.ssh-host }}
@@ -120,6 +125,21 @@ runs:
120125
${{ inputs.ecr-image-uri }}
121126
fi
122127
128+
- name: EC2 Docker Restart Service
129+
if: ${{ inputs.restart-only == 'true' }}
130+
uses: appleboy/ssh-action@master
131+
with:
132+
host: ${{ inputs.ssh-host }}
133+
username: ${{ inputs.ssh-username }}
134+
key: ${{ inputs.ssh-key }}
135+
script: |
136+
sudo docker login --username AWS -p $(aws ecr get-login-password --region ${{ inputs.aws-region }}) ${{ steps.login-ecr.outputs.registry }}
137+
sudo docker pull ${{ inputs.ecr-image-uri }}
138+
sudo -S docker service update \
139+
--force \
140+
--replicas ${{ inputs.replicas }} \
141+
${{ inputs.docker-service }}
142+
123143
- name: EC2 Prune conatiner and images
124144
if: ${{ inputs.prune == 'true' }}
125145
uses: appleboy/ssh-action@master

0 commit comments

Comments
 (0)