13 Commits

Author SHA1 Message Date
smf
7ab8b2997c 修改cp方式 2024-09-19 14:08:44 +08:00
smf
59b017690d Merge pull request 'add compose config info' (#7) from config into local
Reviewed-on: #7
2024-03-25 21:50:43 +08:00
smf
5338247b08 add compose config info 2024-03-25 21:49:41 +08:00
smf
b8bb637fb2 Merge pull request 'add pull param' (#6) from pull into local
Reviewed-on: #6
2024-03-11 14:08:36 +08:00
smf
5b1e185867 add pull param 2024-03-11 14:08:05 +08:00
smf
e6a76a28ca Merge pull request 'add ssh option' (#5) from ssh_para into local
Reviewed-on: #5
2024-03-11 10:15:12 +08:00
smf
87349b1fc8 add ssh option 2024-03-11 10:14:41 +08:00
smf
e8b7bda08f Merge pull request 'base_image' (#4) from base_image into local
Reviewed-on: #4
2024-03-08 21:47:22 +08:00
smf
5e5c5eeda2 info 2024-03-08 21:46:42 +08:00
smf
45da665ce0 change base image 2024-03-08 21:26:54 +08:00
smf
1ec01bdf99 Merge pull request 'update readme' (#3) from readme into local
Reviewed-on: #3
2024-03-08 18:46:40 +08:00
smf
83c611bb20 update readme 2024-03-08 18:46:09 +08:00
smf
3ec54a128a m5x2 (#2)
Reviewed-on: #2
2024-03-08 18:15:54 +08:00
4 changed files with 44 additions and 55 deletions

View File

@@ -1,8 +1,10 @@
FROM alpinelinux/docker-compose
FROM docker
COPY --from=docker/compose-bin:edge /docker-compose /usr/libexec/docker/cli-plugins/docker-compose
RUN docker compose version
LABEL 'name'='Docker Deployment Action'
LABEL 'com.github.actions.name'='Docker Deployment'
LABEL 'com.github.actions.description'='supports docker-compose and Docker Swarm deployments'
LABEL 'name'='Docker Compose Remote Deployment Action'
LABEL 'com.github.actions.name'='Docker Compose Remote Deployment'
LABEL 'com.github.actions.description'='supports docker-compose remotely through ssh.'
LABEL 'com.github.actions.icon'='send'
LABEL 'com.github.actions.color'='green'

View File

@@ -25,25 +25,23 @@ Below is a brief example on how the action can be used:
## Input Configurations
### `remote_docker_host`
Remote Docker host ie (user@host).
Remote Docker host.
### `remote_docker_user`
Remote Docker user.
### `remote_docker_port`
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 used to connect to the docker host eg (~/.ssh/rsa_id).
### `ssh_proxy_cmd`
SSH ProxyCommand used to connect to the docker host.
### `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`
The path where the stack files will be copied to. Default ~/docker-deployment.
The absolute path on remote docker host to deploy, default rely on repo working directory.
### `stack_file_name`
Docker stack file used. Default is docker-compose.yml.
### `keep_files`
Number of the files to be kept on the server. Default is 3.
Compose configuration files.
### `env_file_name`
Specify an alternate environment file.
### `docker_prune`
A boolean input to trigger docker prune command. Default is false.
### `pre_deployment_command_args`

View File

@@ -11,9 +11,6 @@ inputs:
description: Remote Docker ssh port ie (22).
required: false
default: '22'
# ssh_public_key:
# description: Remote Docker SSH public key eg (~/.ssh/rsa_id.pub).
# required: true
ssh_private_key:
description: SSH private key used to connect to the docker host eg (~/.ssh/rsa_id).
required: true
@@ -32,15 +29,14 @@ inputs:
env_file_name:
description: Specify an alternate environment file.
required: false
keep_files:
description: Number of the files to be kept on the server. Default is 3.
required: false
docker_prune:
description: A boolean input to trigger docker prune command. Default is false.
required: false
pre_deployment_command_args:
description: The args for the pre deploument command.
required: false
pull_images_first:
description: Pull docker images before deploying. Default is false.
docker_registry_username:
description: The docker registry username.
required: false

View File

@@ -1,44 +1,40 @@
#!/bin/sh
set -eu
if [ -z "${INPUT_REMOTE_DOCKER_PORT+x}" ]; then
if [ -z "${INPUT_REMOTE_DOCKER_PORT+x}" ] || [ -z "$INPUT_REMOTE_DOCKER_PORT" ]; then
INPUT_REMOTE_DOCKER_PORT=22
fi
if [ -z "${INPUT_REMOTE_DOCKER_HOST+x}" ]; then
if [ -z "${INPUT_REMOTE_DOCKER_HOST+x}" ] || [ -z "$INPUT_REMOTE_DOCKER_HOST" ]; then
echo "Input remote_docker_host is required!"
exit 1
fi
if [ -z "${INPUT_REMOTE_DOCKER_USER+x}" ]; then
if [ -z "${INPUT_REMOTE_DOCKER_USER+x}" ] || [ -z "$INPUT_REMOTE_DOCKER_USER" ]; then
echo "Input remote_docker_user is required!"
exit 1
fi
if [ -z "${INPUT_SSH_PRIVATE_KEY+x}" ]; then
if [ -z "${INPUT_SSH_PRIVATE_KEY+x}" ] || [ -z "$INPUT_SSH_PRIVATE_KEY" ]; then
echo "Input ssh_private_key is required!"
exit 1
fi
if [ -z "${INPUT_ARGS+x}" ]; then
if [ -z "${INPUT_ARGS+x}" ] || [ -z "$INPUT_ARGS" ]; then
echo "Input input_args is required!"
exit 1
fi
CHANGE_DIR=true
if [ -z "${INPUT_DEPLOY_PATH+x}" ]; then
CHANGE_DIR=false
fi
if $CHANGE_DIR ; then
if ! [ -z "${INPUT_DEPLOY_PATH+x}" ] && ! [ -z "$INPUT_DEPLOY_PATH" ]; then
echo "Change working directory"
echo "Current: `pwd`"
echo "Target: $INPUT_DEPLOY_PATH"
mkdir -p $INPUT_DEPLOY_PATH
cp -rfp ./. $INPUT_DEPLOY_PATH
cp -rfp `pwd`/. $INPUT_DEPLOY_PATH
cd $INPUT_DEPLOY_PATH
fi
if [ -z "${INPUT_DOCKER_REGISTRY_URI+x}" ]; then
if [ -z "${INPUT_DOCKER_REGISTRY_URI+x}" ] || [ -z "$INPUT_DOCKER_REGISTRY_URI" ]; then
INPUT_DOCKER_REGISTRY_URI=https://registry.hub.docker.com
fi
@@ -52,10 +48,6 @@ chmod 600 ~/.ssh/id_rsa
eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa
SSH_PROXY=true
if [ -z "${INPUT_SSH_PROXY_CMD+x}" ]; then
SSH_PROXY=false
fi
echo "Add REMOTE_DOCKER_HOST alias to ~/.ssh/config"
touch ~/.ssh/config
echo >> ~/.ssh/config
@@ -66,49 +58,50 @@ echo " Port $INPUT_REMOTE_DOCKER_PORT" >> ~/.ssh/config
echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
echo " StrictHostKeyChecking no" >> ~/.ssh/config
echo " UserKnownHostsFile /dev/null" >> ~/.ssh/config
if $SSH_PROXY ; then
echo " ConnectTimeout 300" >> ~/.ssh/config
if ! [ -z "${INPUT_SSH_PROXY_CMD+x}" ] && ! [ -z "$INPUT_SSH_PROXY_CMD" ]; then
echo "Add ProxyCommand: $INPUT_SSH_PROXY_CMD"
echo " ProxyCommand $INPUT_SSH_PROXY_CMD" >> ~/.ssh/config
fi
echo >> ~/.ssh/config
chmod 600 ~/.ssh/config
docker -v
docker compose version
set context
echo "Create docker context"
docker context create remote --docker "host=ssh://REMOTE_DOCKER_HOST"
docker context use remote
DOCKER_REGISTRY_LOGIN=true
if [ -z "${INPUT_DOCKER_REGISTRY_USERNAME+x}" ] || [ -z "${INPUT_DOCKER_REGISTRY_PASSWORD+x}" ]; then
DOCKER_REGISTRY_LOGIN=false
fi
if $DOCKER_REGISTRY_LOGIN ; then
if ! [ -z "${INPUT_DOCKER_REGISTRY_USERNAME+x}" ] && ! [ -z "$INPUT_DOCKER_REGISTRY_USERNAME" ] &&
! [ -z "${INPUT_DOCKER_REGISTRY_PASSWORD+x}" ] && ! [ -z "$INPUT_DOCKER_REGISTRY_PASSWORD" ]; then
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"
fi
if ! [ -z "${INPUT_DOCKER_PRUNE+x}" ] && [ $INPUT_DOCKER_PRUNE = 'true' ] ; then
yes | docker --log-level debug --host "ssh://$INPUT_REMOTE_DOCKER_HOST:$INPUT_REMOTE_DOCKER_PORT" system prune -a 2>&1
yes | docker --log-level debug system prune -a 2>&1
fi
DEPLOYMENT_COMMAND="docker --log-level=debug compose"
STACK_FILE=true
if [ -z "${INPUT_STACK_FILE_NAME+x}" ]; then
STACK_FILE=false
fi
if $STACK_FILE ; then
if ! [ -z "${INPUT_STACK_FILE_NAME+x}" ] && ! [ -z "$INPUT_STACK_FILE_NAME" ]; then
DEPLOYMENT_COMMAND="$DEPLOYMENT_COMMAND -f ${INPUT_STACK_FILE_NAME//,/ -f }"
fi
ENV_FILE=true
if [ -z "${INPUT_ENV_FILE_NAME+x}" ]; then
ENV_FILE=false
fi
if $ENV_FILE ; then
if ! [ -z "${INPUT_ENV_FILE_NAME+x}" ] && ! [ -z "$INPUT_ENV_FILE_NAME" ]; then
DEPLOYMENT_COMMAND="$DEPLOYMENT_COMMAND --env-file ${INPUT_ENV_FILE_NAME//,/ --env-file }"
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=""
echo "Connecting to $INPUT_REMOTE_DOCKER_HOST... Command: ${DEPLOYMENT_COMMAND} ${INPUT_ARGS}"