Compare commits
17 Commits
fix
...
013c6a876d
| Author | SHA1 | Date | |
|---|---|---|---|
| 013c6a876d | |||
| 4489c33f6c | |||
| 5a84702512 | |||
| cbfb477c9a | |||
| bc2a6730e0 | |||
| 0d398b1de1 | |||
| 33237c1be7 | |||
| 356adf2c45 | |||
| d470e52020 | |||
| 20af335ef9 | |||
| bdca1670cb | |||
| 2b2f220c02 | |||
| b58bf80c7b | |||
| e3a0f5c937 | |||
| 0c81dda880 | |||
| 958d6d6863 | |||
| 90ddf7cf62 |
10
Dockerfile
10
Dockerfile
@@ -1,10 +1,8 @@
|
|||||||
FROM docker
|
FROM alpinelinux/docker-compose
|
||||||
COPY --from=docker/compose-bin:edge /docker-compose /usr/libexec/docker/cli-plugins/docker-compose
|
|
||||||
RUN docker compose version
|
|
||||||
|
|
||||||
LABEL 'name'='Docker Compose Remote Deployment Action'
|
LABEL 'name'='Docker Deployment Action'
|
||||||
LABEL 'com.github.actions.name'='Docker Compose Remote Deployment'
|
LABEL 'com.github.actions.name'='Docker Deployment'
|
||||||
LABEL 'com.github.actions.description'='supports docker-compose remotely through ssh.'
|
LABEL 'com.github.actions.description'='supports docker-compose and Docker Swarm deployments'
|
||||||
LABEL 'com.github.actions.icon'='send'
|
LABEL 'com.github.actions.icon'='send'
|
||||||
LABEL 'com.github.actions.color'='green'
|
LABEL 'com.github.actions.color'='green'
|
||||||
|
|
||||||
|
|||||||
20
README.md
20
README.md
@@ -25,23 +25,25 @@ Below is a brief example on how the action can be used:
|
|||||||
|
|
||||||
## Input Configurations
|
## Input Configurations
|
||||||
### `remote_docker_host`
|
### `remote_docker_host`
|
||||||
Remote Docker host.
|
Remote Docker host ie (user@host).
|
||||||
### `remote_docker_user`
|
|
||||||
Remote Docker user.
|
|
||||||
### `remote_docker_port`
|
### `remote_docker_port`
|
||||||
Remote Docker ssh port ie (22).
|
Remote Docker ssh port ie (22).
|
||||||
|
### `ssh_public_key`
|
||||||
|
Remote Docker SSH public key eg (~/.ssh/rsa_id.pub).
|
||||||
### `ssh_private_key`
|
### `ssh_private_key`
|
||||||
SSH private key used to connect to the docker host eg (~/.ssh/rsa_id).
|
SSH private key used to connect to the docker host eg (~/.ssh/rsa_id).
|
||||||
### `ssh_proxy_cmd`
|
|
||||||
SSH ProxyCommand used to connect to the docker host.
|
|
||||||
### `args`
|
### `args`
|
||||||
Deployment command args.
|
Deployment command args.
|
||||||
|
### `deployment_mode`
|
||||||
|
Deployment mode either docker-swarm or docker-compose. Default is docker-compose.
|
||||||
|
### `copy_stack_file`
|
||||||
|
Copy stack file to remote server and deploy from the server. Default is false.
|
||||||
### `deploy_path`
|
### `deploy_path`
|
||||||
The absolute path on remote docker host to deploy, default rely on repo working directory.
|
The path where the stack files will be copied to. Default ~/docker-deployment.
|
||||||
### `stack_file_name`
|
### `stack_file_name`
|
||||||
Compose configuration files.
|
Docker stack file used. Default is docker-compose.yml.
|
||||||
### `env_file_name`
|
### `keep_files`
|
||||||
Specify an alternate environment file.
|
Number of the files to be kept on the server. Default is 3.
|
||||||
### `docker_prune`
|
### `docker_prune`
|
||||||
A boolean input to trigger docker prune command. Default is false.
|
A boolean input to trigger docker prune command. Default is false.
|
||||||
### `pre_deployment_command_args`
|
### `pre_deployment_command_args`
|
||||||
|
|||||||
10
action.yml
10
action.yml
@@ -11,6 +11,9 @@ inputs:
|
|||||||
description: Remote Docker ssh port ie (22).
|
description: Remote Docker ssh port ie (22).
|
||||||
required: false
|
required: false
|
||||||
default: '22'
|
default: '22'
|
||||||
|
# ssh_public_key:
|
||||||
|
# description: Remote Docker SSH public key eg (~/.ssh/rsa_id.pub).
|
||||||
|
# required: true
|
||||||
ssh_private_key:
|
ssh_private_key:
|
||||||
description: SSH private key used to connect to the docker host eg (~/.ssh/rsa_id).
|
description: SSH private key used to connect to the docker host eg (~/.ssh/rsa_id).
|
||||||
required: true
|
required: true
|
||||||
@@ -21,7 +24,7 @@ inputs:
|
|||||||
description: Deployment command args.
|
description: Deployment command args.
|
||||||
required: true
|
required: true
|
||||||
deploy_path:
|
deploy_path:
|
||||||
description: The absolute path on remote docker host to deploy, default rely on repo working directory.
|
description: The absolute path on remote docker host to deploy, default rely on repo working directory .
|
||||||
required: false
|
required: false
|
||||||
stack_file_name:
|
stack_file_name:
|
||||||
description: Compose configuration files.
|
description: Compose configuration files.
|
||||||
@@ -29,14 +32,15 @@ inputs:
|
|||||||
env_file_name:
|
env_file_name:
|
||||||
description: Specify an alternate environment file.
|
description: Specify an alternate environment file.
|
||||||
required: false
|
required: false
|
||||||
|
keep_files:
|
||||||
|
description: Number of the files to be kept on the server. Default is 3.
|
||||||
|
required: false
|
||||||
docker_prune:
|
docker_prune:
|
||||||
description: A boolean input to trigger docker prune command. Default is false.
|
description: A boolean input to trigger docker prune command. Default is false.
|
||||||
required: false
|
required: false
|
||||||
pre_deployment_command_args:
|
pre_deployment_command_args:
|
||||||
description: The args for the pre deploument command.
|
description: The args for the pre deploument command.
|
||||||
required: false
|
required: false
|
||||||
pull_images_first:
|
|
||||||
description: Pull docker images before deploying. Default is false.
|
|
||||||
docker_registry_username:
|
docker_registry_username:
|
||||||
description: The docker registry username.
|
description: The docker registry username.
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@@ -1,40 +1,45 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
if [ -z "${INPUT_REMOTE_DOCKER_PORT+x}" ] || [ -z "$INPUT_REMOTE_DOCKER_PORT" ]; then
|
if [ -z "${INPUT_REMOTE_DOCKER_PORT+x}" ]; then
|
||||||
INPUT_REMOTE_DOCKER_PORT=22
|
INPUT_REMOTE_DOCKER_PORT=22
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${INPUT_REMOTE_DOCKER_HOST+x}" ] || [ -z "$INPUT_REMOTE_DOCKER_HOST" ]; then
|
if [ -z "${INPUT_REMOTE_DOCKER_HOST+x}" ]; then
|
||||||
echo "Input remote_docker_host is required!"
|
echo "Input remote_docker_host is required!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${INPUT_REMOTE_DOCKER_USER+x}" ] || [ -z "$INPUT_REMOTE_DOCKER_USER" ]; then
|
if [ -z "${INPUT_REMOTE_DOCKER_USER+x}" ]; then
|
||||||
echo "Input remote_docker_user is required!"
|
echo "Input remote_docker_user is required!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${INPUT_SSH_PRIVATE_KEY+x}" ] || [ -z "$INPUT_SSH_PRIVATE_KEY" ]; then
|
# if [ -z "${INPUT_SSH_PUBLIC_KEY+x}" ]; then
|
||||||
|
# echo "Input ssh_public_key is required!"
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
if [ -z "${INPUT_SSH_PRIVATE_KEY+x}" ]; then
|
||||||
echo "Input ssh_private_key is required!"
|
echo "Input ssh_private_key is required!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${INPUT_ARGS+x}" ] || [ -z "$INPUT_ARGS" ]; then
|
if [ -z "${INPUT_ARGS+x}" ]; then
|
||||||
echo "Input input_args is required!"
|
echo "Input input_args is required!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -z "${INPUT_DEPLOY_PATH+x}" ] && ! [ -z "$INPUT_DEPLOY_PATH" ]; then
|
if ! [ -z "${INPUT_DEPLOY_PATH+x}" ]; then
|
||||||
echo "Change working directory"
|
echo "Change working directory"
|
||||||
echo "Current: `pwd`"
|
echo "Current: `pwd`"
|
||||||
echo "Target: $INPUT_DEPLOY_PATH"
|
echo "Target: $INPUT_DEPLOY_PATH"
|
||||||
mkdir -p $INPUT_DEPLOY_PATH
|
mkdir -p $INPUT_DEPLOY_PATH
|
||||||
cp -rfp `pwd`/. $INPUT_DEPLOY_PATH
|
cp -rfp ./* $INPUT_DEPLOY_PATH/ || true
|
||||||
cd $INPUT_DEPLOY_PATH
|
cd $INPUT_DEPLOY_PATH
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${INPUT_DOCKER_REGISTRY_URI+x}" ] || [ -z "$INPUT_DOCKER_REGISTRY_URI" ]; then
|
if [ -z "${INPUT_DOCKER_REGISTRY_URI+x}" ]; then
|
||||||
INPUT_DOCKER_REGISTRY_URI=https://registry.hub.docker.com
|
INPUT_DOCKER_REGISTRY_URI=https://registry.hub.docker.com
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -45,9 +50,16 @@ mkdir -p ~/.ssh
|
|||||||
ls ~/.ssh
|
ls ~/.ssh
|
||||||
printf '%s\n' "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
printf '%s\n' "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
# printf '%s\n' "$INPUT_SSH_PUBLIC_KEY" > ~/.ssh/id_rsa.pub
|
||||||
|
# chmod 600 ~/.ssh/id_rsa.pub
|
||||||
|
#chmod 600 "~/.ssh"
|
||||||
eval $(ssh-agent)
|
eval $(ssh-agent)
|
||||||
ssh-add ~/.ssh/id_rsa
|
ssh-add ~/.ssh/id_rsa
|
||||||
|
|
||||||
|
# echo "Add known hosts"
|
||||||
|
# ssh-keyscan -p $INPUT_REMOTE_DOCKER_PORT "$INPUT_REMOTE_DOCKER_HOST" >> ~/.ssh/known_hosts
|
||||||
|
# ssh-keyscan -p $INPUT_REMOTE_DOCKER_PORT "$INPUT_REMOTE_DOCKER_HOST" >> /etc/ssh/ssh_known_hosts
|
||||||
|
|
||||||
echo "Add REMOTE_DOCKER_HOST alias to ~/.ssh/config"
|
echo "Add REMOTE_DOCKER_HOST alias to ~/.ssh/config"
|
||||||
touch ~/.ssh/config
|
touch ~/.ssh/config
|
||||||
echo >> ~/.ssh/config
|
echo >> ~/.ssh/config
|
||||||
@@ -58,50 +70,41 @@ echo " Port $INPUT_REMOTE_DOCKER_PORT" >> ~/.ssh/config
|
|||||||
echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
|
echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
|
||||||
echo " StrictHostKeyChecking no" >> ~/.ssh/config
|
echo " StrictHostKeyChecking no" >> ~/.ssh/config
|
||||||
echo " UserKnownHostsFile /dev/null" >> ~/.ssh/config
|
echo " UserKnownHostsFile /dev/null" >> ~/.ssh/config
|
||||||
echo " ConnectTimeout 300" >> ~/.ssh/config
|
if ! [ -z "${INPUT_SSH_PROXY_CMD+x}" ]; then
|
||||||
if ! [ -z "${INPUT_SSH_PROXY_CMD+x}" ] && ! [ -z "$INPUT_SSH_PROXY_CMD" ]; then
|
|
||||||
echo "Add ProxyCommand: $INPUT_SSH_PROXY_CMD"
|
echo "Add ProxyCommand: $INPUT_SSH_PROXY_CMD"
|
||||||
echo " ProxyCommand $INPUT_SSH_PROXY_CMD" >> ~/.ssh/config
|
echo " ProxyCommand $INPUT_SSH_PROXY_CMD" >> ~/.ssh/config
|
||||||
fi
|
fi
|
||||||
echo >> ~/.ssh/config
|
echo >> ~/.ssh/config
|
||||||
chmod 600 ~/.ssh/config
|
chmod 600 ~/.ssh/config
|
||||||
|
|
||||||
docker -v
|
# echo "docker -v"
|
||||||
docker compose version
|
# echo `docker -v`
|
||||||
|
# echo "docker-compose -v"
|
||||||
|
# echo `docker-compose -v`
|
||||||
|
|
||||||
set context
|
set context
|
||||||
echo "Create docker context"
|
echo "Create docker context"
|
||||||
docker context create remote --docker "host=ssh://REMOTE_DOCKER_HOST"
|
docker context create remote --docker "host=ssh://REMOTE_DOCKER_HOST"
|
||||||
docker context use remote
|
docker context use remote
|
||||||
|
sleep 1h
|
||||||
|
|
||||||
if ! [ -z "${INPUT_DOCKER_REGISTRY_USERNAME+x}" ] && ! [ -z "$INPUT_DOCKER_REGISTRY_USERNAME" ] &&
|
if ! [ -z "${INPUT_DOCKER_REGISTRY_USERNAME+x}" ] && ! [ -z "${INPUT_DOCKER_REGISTRY_PASSWORD+x}" ]; then
|
||||||
! [ -z "${INPUT_DOCKER_REGISTRY_PASSWORD+x}" ] && ! [ -z "$INPUT_DOCKER_REGISTRY_PASSWORD" ]; then
|
|
||||||
echo "Connecting to $INPUT_DOCKER_REGISTRY_URI... Command: docker login"
|
echo "Connecting to $INPUT_DOCKER_REGISTRY_URI... Command: docker login"
|
||||||
echo "$INPUT_DOCKER_REGISTRY_PASSWORD" | docker login -u "$INPUT_DOCKER_REGISTRY_USERNAME" --password-stdin "$INPUT_DOCKER_REGISTRY_URI"
|
echo "$INPUT_DOCKER_REGISTRY_PASSWORD" | docker login -u "$INPUT_DOCKER_REGISTRY_USERNAME" --password-stdin "$INPUT_DOCKER_REGISTRY_URI"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -z "${INPUT_DOCKER_PRUNE+x}" ] && [ $INPUT_DOCKER_PRUNE = 'true' ] ; then
|
if ! [ -z "${INPUT_DOCKER_PRUNE+x}" ] && [ $INPUT_DOCKER_PRUNE = 'true' ] ; then
|
||||||
yes | docker --log-level debug system prune -a 2>&1
|
yes | docker --log-level debug --host "ssh://$INPUT_REMOTE_DOCKER_HOST:$INPUT_REMOTE_DOCKER_PORT" system prune -a 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DEPLOYMENT_COMMAND="docker --log-level=debug compose"
|
DEPLOYMENT_COMMAND="docker --log-level=debug compose"
|
||||||
|
if ! [ -z "${INPUT_STACK_FILE_NAME+x}" ]; then
|
||||||
if ! [ -z "${INPUT_STACK_FILE_NAME+x}" ] && ! [ -z "$INPUT_STACK_FILE_NAME" ]; then
|
DEPLOYMENT_COMMAND="$DEPLOYMENT_COMMAND -f $INPUT_STACK_FILE_NAME"
|
||||||
DEPLOYMENT_COMMAND="$DEPLOYMENT_COMMAND -f ${INPUT_STACK_FILE_NAME//,/ -f }"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -z "${INPUT_ENV_FILE_NAME+x}" ] && ! [ -z "$INPUT_ENV_FILE_NAME" ]; then
|
if ! [ -z "${INPUT_ENV_FILE_NAME+x}" ]; then
|
||||||
DEPLOYMENT_COMMAND="$DEPLOYMENT_COMMAND --env-file ${INPUT_ENV_FILE_NAME//,/ --env-file }"
|
DEPLOYMENT_COMMAND="$DEPLOYMENT_COMMAND --env-file $INPUT_ENV_FILE_NAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Connecting to $INPUT_REMOTE_DOCKER_HOST... Command: ${DEPLOYMENT_COMMAND} config"
|
|
||||||
${DEPLOYMENT_COMMAND} "config"
|
|
||||||
|
|
||||||
if ! [ -z "${INPUT_PULL_IMAGES_FIRST+x}" ] && [ $INPUT_PULL_IMAGES_FIRST = 'true' ] ; then
|
|
||||||
echo "Connecting to $INPUT_REMOTE_DOCKER_HOST... Command: ${DEPLOYMENT_COMMAND} pull"
|
|
||||||
${DEPLOYMENT_COMMAND} "pull"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# DEPLOYMENT_COMMAND_OPTIONS=""
|
# DEPLOYMENT_COMMAND_OPTIONS=""
|
||||||
|
|
||||||
echo "Connecting to $INPUT_REMOTE_DOCKER_HOST... Command: ${DEPLOYMENT_COMMAND} ${INPUT_ARGS}"
|
echo "Connecting to $INPUT_REMOTE_DOCKER_HOST... Command: ${DEPLOYMENT_COMMAND} ${INPUT_ARGS}"
|
||||||
|
|||||||
Reference in New Issue
Block a user