Skip to content

Commit

Permalink
feat: add more params, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
astappiev committed Jan 29, 2023
1 parent 2d53511 commit 57f8037
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# Docker Compose Remote Action

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.
Logs into remote host via ssh. Unpacks the workspace there and runs `docker compose up -d` command.

## Inputs

### Required
* `ssh_user` - Remote user which should have access to docker.
* `ssh_host` - Remote host name.
* `ssh_port` - Remote port for SSH connection. Default is 22.
* `ssh_jump_host` - Jump host name.
* `ssh_private_key` - Private SSH key used for logging into remote system. Please, keep your key securely in GitHub secrets.
* `ssh_host_public_key` - Remote host SSH public key (The content of `~/.ssh/known_hosts` needs to be given here).

### Optional
* `ssh_port` - Remote port for SSH connection. Default is `22`.
* `ssh_jump_host` - Jump host name. If set, `ssh_jump_public_key` is required.
* `ssh_jump_public_key` - Jump host SSH public key (The content of `~/.ssh/known_hosts` needs to be given here).
* `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.
* `docker_use_stack` - Use docker stack instead of docker-compose.
* `docker_compose_prefix` - Project name passed to compose. Each docker container will have this prefix in name. Required if `docker_use_stack` is `true`.
* `docker_compose_filename` - Path to the docker-compose file in the repository. Default is `docker-compose.yml`.
* `docker_args` - Docker compose arguments. Default is `-d --remove-orphans --build`.
* `docker_use_stack` - Use docker stack instead of docker-compose. Default is `false`.
* `docker_env` - Docker Environment variables.
* `workspace` - A project directory to use.
* `workspace_keep` - Whether to keep the workspace directory after the action has finished.
* `workspace` - A project directory to use. Default is `~/workspace`.
* `workspace_keep` - Whether to keep the workspace directory after the action has finished. Default is `false`.
* `container_registry` - Container registry server to use.
* `container_registry_username` - Container registry username.
* `container_registry_password` - Container registry password.

# Usage example

Expand All @@ -37,15 +43,14 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: astappiev/docker-compose-remote-action@master
name: Docker-Compose Remote Deployment
with:
ssh_host: example.com
ssh_private_key: ${{ secrets.EXAMPLE_COM_SSH_PRIVATE_KEY }}
ssh_user: ${{ secrets.EXAMPLE_COM_SSH_USER }}
docker_compose_prefix: example_com
ssh_user: ${{ secrets.DEPLOY_USERNAME }}
ssh_private_key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
ssh_host_public_key: ${{ secrets.DEPLOY_PUBLIC_KEY }}
docker_compose_prefix: myapp
```
21 changes: 8 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ inputs:
ssh_port:
description: Remote SSH port.
default: '22'
required: true
ssh_user:
description: Remote user name.
required: true
Expand All @@ -24,40 +23,35 @@ inputs:
required: true
ssh_jump_public_key:
description: Jump host SSH public key (The content of `~/.ssh/known_hosts` needs to be given here).
required: true
docker_compose_prefix:
description: Prefix for docker compose containers.
required: true
docker_compose_filename:
description: Docker compose file to use.
default: docker-compose.yml
docker_compose_prefix:
description: Prefix for docker compose containers.
docker_args:
description: Docker compose command arguments.
default: '-d --remove-orphans --build'
docker_use_stack:
description: Use docker stack instead of docker compose ("true" or "false").
default: 'false'
docker_env:
description: Docker Environment variables.
required: false
workspace:
description: A project directory to use.
default: 'workspace'
required: false
workspace_keep:
description: Whether to keep the workspace directory after the action has finished.
default: 'false'
required: false
container_registry:
description: Container registry server to use.
required: false
container_registry_username:
description: Container registry username to use.
required: false
container_registry_password:
description: Container registry password to use.
required: false
runs:
using: docker
# image: Dockerfile
image: docker://astappev/docker-compose-remote-action:latest
image: Dockerfile
# image: docker://astappev/docker-compose-remote-action:latest
env:
SSH_USER: ${{ inputs.ssh_user }}
SSH_HOST: ${{ inputs.ssh_host }}
Expand All @@ -68,6 +62,7 @@ runs:
SSH_JUMP_PUBLIC_KEY: ${{ inputs.ssh_jump_public_key }}
DOCKER_COMPOSE_FILENAME: ${{ inputs.docker_compose_filename }}
DOCKER_COMPOSE_PREFIX: ${{ inputs.docker_compose_prefix }}
DOCKER_ARGS: ${{ inputs.docker_args }}
DOCKER_USE_STACK: ${{ inputs.docker_use_stack }}
DOCKER_ENV: ${{ inputs.docker_env }}
WORKSPACE: ${{ inputs.workspace }}
Expand Down
24 changes: 18 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ if [ -z "$DOCKER_COMPOSE_FILENAME" ]; then
DOCKER_COMPOSE_FILENAME=docker-compose.yml
fi

if [ -z "$DOCKER_COMPOSE_PREFIX" ]; then
echo "Input docker_compose_prefix is required!"
exit 1
if [ -z "$DOCKER_ARGS" ]; then
DOCKER_ARGS="-d --remove-orphans --build"
fi

if [ -z "$DOCKER_USE_STACK" ]; then
DOCKER_USE_STACK=false
else
if [ -z "$DOCKER_COMPOSE_PREFIX" ]; then
echo "Input docker_compose_prefix is required!"
exit 1
fi

if [ -z "$DOCKER_ARGS" ]; then
DOCKER_ARGS=""
fi
fi

if [ -z "$DOCKER_ENV" ]; then
Expand Down Expand Up @@ -92,10 +100,13 @@ fi
remote_path="\$HOME/$WORKSPACE"
remote_cleanup=""
remote_registry_login=""
remote_exec="docker compose -f \"$DOCKER_COMPOSE_FILENAME\" -p \"$DOCKER_COMPOSE_PREFIX\" up -d --remove-orphans --build"
remote_docker_exec="docker compose -f \"$DOCKER_COMPOSE_FILENAME\" up $DOCKER_ARGS"
if [ -n "$DOCKER_COMPOSE_PREFIX" ]; then
remote_docker_exec="$remote_docker_exec -p \"$DOCKER_COMPOSE_PREFIX\""
fi
if $DOCKER_USE_STACK ; then
remote_path="\$HOME/$WORKSPACE/$DOCKER_COMPOSE_PREFIX"
remote_exec="docker stack deploy -c \"$DOCKER_COMPOSE_FILENAME\" --prune \"$DOCKER_COMPOSE_PREFIX\""
remote_docker_exec="docker stack deploy -c \"$DOCKER_COMPOSE_FILENAME\" --prune \"$DOCKER_COMPOSE_PREFIX\" $DOCKER_ARGS"
fi
if ! $WORKSPACE_KEEP ; then
remote_cleanup="cleanup() { log 'Removing workspace'; rm -rf \"$remote_path\"; }; trap cleanup EXIT;"
Expand All @@ -118,8 +129,9 @@ $remote_cleanup
$remote_registry_login
log 'Launching docker compose...';
log 'Command \"$remote_docker_exec\"';
cd \"$remote_path\";
$DOCKER_ENV $remote_exec"
$DOCKER_ENV $remote_docker_exec"

ssh_jump=""
if [ -n "$SSH_JUMP_HOST" ]; then
Expand Down

0 comments on commit 57f8037

Please sign in to comment.