Skip to content

Commit d794fa5

Browse files
committed
Add docker-compose down execution
1 parent c857e98 commit d794fa5

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ unknown docker-images. It is entirely built from Dockerfile on top of
2020
container will have this prefix in name.
2121
* `docker_compose_filename` - Path to the docker-compose file in the repository.
2222
* `use_stack` - Use docker stack instead of docker-compose.
23+
* `docker_compose_down` - Execute docker-compose-down.
2324

2425
# Usage example
2526

@@ -124,3 +125,28 @@ jobs:
124125
use_stack: 'true'
125126
```
126127

128+
# Down deploy (Docker-compose down)
129+
If you need to run a docker-compose down to do a clean rollback. Only one down of the
130+
services will be executed To do that just set `docker_compose_down` input to `"true"`:
131+
```
132+
name: Deploy
133+
on:
134+
push:
135+
branches: [ master ]
136+
137+
jobs:
138+
deploy:
139+
runs-on: ubuntu-latest
140+
141+
steps:
142+
- actions/chockout@v2
143+
144+
- uses: alex-ac/github-action-ssh-docker-compose@master
145+
name: Docker-Stack Remote Deployment
146+
with:
147+
ssh_host: example.com
148+
ssh_private_key: ${{ secrets.EXAMPLE_COM_SSH_PRIVATE_KEY }}
149+
ssh_user: ${{ secrets.EXAMPLE_COM_SSH_USER }}
150+
docker_compose_prefix: example.com
151+
docker_compose_down: 'true'
152+
```

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ inputs:
2323
use_stack:
2424
description: Use docker stack instead of docker compose ("true" or "false").
2525
default: 'false'
26+
docker_compose_down:
27+
description: Execute docker-compose-down ("true" or "false").
28+
default: 'false'
2629
runs:
2730
using: docker
2831
image: Dockerfile
@@ -34,3 +37,4 @@ runs:
3437
DOCKER_COMPOSE_FILENAME: ${{ inputs.docker_compose_filename }}
3538
DOCKER_COMPOSE_PREFIX: ${{ inputs.docker_compose_prefix }}
3639
USE_DOCKER_STACK: ${{ inputs.use_stack }}
40+
DOCKER_COMPOSE_DOWN: ${{ inputs.docker_compose_down }}

entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ remote_command="set -e ; log() { echo '>> [remote]' \$@ ; } ; cleanup() { log 'R
2424
if $USE_DOCKER_STACK ; then
2525
remote_command="set -e ; log() { echo '>> [remote]' \$@ ; } ; cleanup() { log 'Removing workspace...'; rm -rf \"\$HOME/workspace\" ; } ; log 'Creating workspace directory...' ; mkdir -p \"\$HOME/workspace/$DOCKER_COMPOSE_PREFIX\" ; trap cleanup EXIT ; log 'Unpacking workspace...' ; tar -C \"\$HOME/workspace/$DOCKER_COMPOSE_PREFIX\" -xjv ; log 'Launching docker stack deploy...' ; cd \"\$HOME/workspace/$DOCKER_COMPOSE_PREFIX\" ; docker stack deploy -c \"$DOCKER_COMPOSE_FILENAME\" --prune \"$DOCKER_COMPOSE_PREFIX\""
2626
fi
27+
if $DOCKER_COMPOSE_DOWN ; then
28+
remote_command="set -e ; log() { echo '>> [remote]' \$@ ; } ; cleanup() { log 'Removing workspace...'; rm -rf \"\$HOME/workspace\" ; } ; log 'Creating workspace directory...' ; mkdir -p \"\$HOME/workspace\" ; trap cleanup EXIT ; log 'Unpacking workspace...' ; tar -C \"\$HOME/workspace\" -xjv ; log 'Launching docker-compose...' ; cd \"\$HOME/workspace\" ; docker-compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PREFIX\" down"
29+
fi
2730

2831
ssh-add <(echo "$SSH_PRIVATE_KEY")
2932

0 commit comments

Comments
 (0)