Skip to content
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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## github-action-ssh-docker-compose
Simple github action to run docker-compose on remote host.
Simple github action to run docker compose on remote host.

This action packs contents of the action workspace into archive.
Logs into remote host via ssh. Unpacks the workspace there and runs
`docker-compose up -d` command.
`docker compose up -d` command.

Comparing to other actions with similar behavior this one does not use any
unknown docker-images. It is entirely built from Dockerfile on top of
Expand All @@ -18,14 +18,14 @@ unknown docker-images. It is entirely built from Dockerfile on top of
* `ssh_user` - Remote user which should have access to docker.
* `docker_compose_prefix` - Project name passed to compose. Each docker
container will have this prefix in name.
* `docker_compose_filename` - Path to the docker-compose file in the repository.
* `use_stack` - Use docker stack instead of docker-compose.
* `docker_compose_down` - Execute docker-compose-down.
* `docker_compose_filename` - Path to the docker compose file in the repository.
* `use_stack` - Use docker stack instead of docker compose.
* `docker_compose_down` - Execute docker compose-down.

# Usage example

Let's say we have a repo with single docker-compose file in it and remote
ubuntu based server with docker and docker-compose installed.
Let's say we have a repo with single docker compose file in it and remote
ubuntu based server with docker and docker compose installed.

1. Generate key pair, do not use a password here.

Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:

In case you want to use some advanced features like secrets. You'll need to
setup a docker swarm cluster and use docker stack command instead of the plain
docker-compose. To do that just set `use_stack` input to `"true"`:
docker compose. To do that just set `use_stack` input to `"true"`:

```
name: Deploy
Expand All @@ -125,8 +125,8 @@ jobs:
use_stack: 'true'
```

# Down deploy (Docker-compose down)
If you need to run a docker-compose down to do a clean rollback. Only one down of the
# Down deploy (Docker Compose down)
If you need to run a docker compose down to do a clean rollback. Only one down of the
services will be executed To do that just set `docker_compose_down` input to `"true"`:
```
name: Deploy
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: SSH-Compose
description: SSH into host and deploy repository with Docker-Compose
description: SSH into host and deploy repository with Docker Compose
branding:
icon: server
color: purple
Expand All @@ -18,7 +18,7 @@ inputs:
description: Remote user name.
required: true
docker_compose_prefix:
description: Prefix for docker-compose containers.
description: Prefix for docker compose containers.
required: true
docker_compose_filename:
description: Docker compose file to use
Expand All @@ -27,7 +27,7 @@ inputs:
description: Use docker stack instead of docker compose ("true" or "false").
default: 'false'
docker_compose_down:
description: Execute docker-compose-down ("true" or "false").
description: Execute docker compose-down ("true" or "false").
default: 'false'
runs:
using: docker
Expand Down
4 changes: 2 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ tar cjvf /tmp/workspace.tar.bz2 --exclude .git --exclude vendor .
log "Launching ssh agent."
eval `ssh-agent -s`

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\" pull ; docker-compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PREFIX\" up -d --remove-orphans --build"
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\" pull ; docker compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PREFIX\" up -d --remove-orphans --build"
if $USE_DOCKER_STACK ; then
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\""
fi
if $DOCKER_COMPOSE_DOWN ; then
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"
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"
fi

ssh-add <(echo "$SSH_PRIVATE_KEY")
Expand Down