Skip to content

Switch to a composite action #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

121 changes: 118 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -18,9 +18,11 @@ inputs:
compose_file_path:
description: path for Docker compose file used. Default is is repo root(docker-compose.yml)
required: false
default: "docker-compose.yml"
ssh_port:
description: The ssh port of the server. Default is 22
required: false
default: "22"
upload_directory:
description: when enabled, uploads entire docker directory, useful for configuration files needed along the container
required: false
@@ -44,11 +46,124 @@ inputs:
required: false

runs:
using: docker
image: 'Dockerfile'
using: "composite"
steps:
- name: Check remote docker host address
if: ${{ inputs.remote_docker_host == '' }}
shell: bash
run: |
echo "::error title=⛔ error hint::No docker host specified, we can't connect to the server without knowing the address!"
exit 1

- name: "Check SSH keys"
if: ${{ inputs.tailscale_ssh == '' }}
shell: bash
run: |
echo "Normal SSH mode, checking SSH keys"
if [ -z "$INPUT_SSH_PUBLIC_KEY" ]; then
echo echo "::error title=⛔ error hint::No public SSH key specified"
exit 1
fi

if [ -z "$INPUT_SSH_PRIVATE_KEY" ]; then
echo echo "::error title=⛔ error hint::No private SSH key specified"
exit 1
fi

- name: Check command arguments
if: ${{ inputs.args == '' }}
shell: bash
run: |
echo "::error title=⛔ error hint::No command arguments specified, these are required to execute the docker-compose / docker stack command!"
exit 1

- name: "Set DOCKER_HOST and SSH_HOST"
shell: bash
run: |
DOCKER_HOST=ssh://\${INPUT_REMOTE_DOCKER_HOST}:\${INPUT_SSH_PORT}
SSH_HOST=\${INPUT_REMOTE_DOCKER_HOST#*@}

- name: starting SSH agent
shell: bash
run: |
mkdir -p ~/.ssh
eval $(ssh-agent)

- name: "Register SSH keys"
if: ${{ inputs.tailscale_ssh == '' }}
shell: bash
run: |
echo "Registering SSH keys..."
ls ~/.ssh
printf '%s\n' "$INPUT_SSH_PRIVATE_KEY" > ~/.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)
ssh-add ~/.ssh/id_rsa

- name: Adding known host
shell: bash
run: |
ssh-keyscan -p $INPUT_SSH_PORT "$SSH_HOST" >> ~/.ssh/known_hosts
ssh-keyscan -p $INPUT_SSH_PORT "$SSH_HOST" >> /etc/ssh/ssh_known_hosts

- name: "Create docker context"
shell: bash
run: |
docker context create remote --docker "host=ssh://$INPUT_REMOTE_DOCKER_HOST:$INPUT_SSH_PORT"
docker context use remote

- name: "Check docker compose directory"
shell: bash
if: ${{ inputs.upload_directory }}
run: |
if [ -z "$INPUT_DOCKER_COMPOSE_DIRECTORY" ];
then
echo "::error title=⛔ error hint::No docker directory specified, this is required to know which diretory to upload"
exit 1
fi

- name: "Upload directory"
shell: bash
if: ${{ inputs.upload_directory }}
run: |
tar cjvf - -C "$GITHUB_WORKSPACE" "$INPUT_DOCKER_COMPOSE_DIRECTORY" | ssh -o StrictHostKeyChecking=no "$INPUT_REMOTE_DOCKER_HOST" -p "$INPUT_SSH_PORT" 'tar -xjvf -'
echo "Upload finished"

- name: "Run post upload command"
shell: bash
if: ${{ inputs.post_upload_command }}
run: |
then
echo "::notice Upload post command specified, running. $INPUT_POST_UPLOAD_COMMAND"
ssh -o StrictHostKeyChecking=no "$INPUT_REMOTE_DOCKER_HOST" -p "$INPUT_SSH_PORT" "eval $INPUT_POST_UPLOAD_COMMAND"

- name: "Connect to docker registry"
shell: bash
if: ${{ inputs.docker_login_user && inputs.docker_login_password &&inputs.docker_login_registry }}
run: |
echo "::notice Connecting to $INPUT_REMOTE_DOCKER_HOST... Command: docker login"
docker login -u "$INPUT_DOCKER_LOGIN_USER" -p "$INPUT_DOCKER_LOGIN_PASSWORD" "$INPUT_DOCKER_LOGIN_REGISTRY"

- name: "Deploy Stack file to swarm"
if: ${{ inputs.docker_swarm }}
shell: bash
run: |
echo "docker swarm mode enabled, using docker stack command"
echo "Command: docker ${INPUT_ARGS} stack deploy --compose-file ${INPUT_COMPOSE_FILE_PATH}"
docker ${INPUT_ARGS} stack deploy --compose-file ${INPUT_COMPOSE_FILE_PATH}

- name: "Deploy Compose file"
if: ${{ inputs.docker_swarm == '' }}
shell: bash
run: |
echo "::notice Command: docker compose -f ${INPUT_COMPOSE_FILE_PATH} pull"
docker compose -f ${INPUT_COMPOSE_FILE_PATH} pull
echo "::notice Command: docker compose -f ${INPUT_COMPOSE_FILE_PATH} ${INPUT_ARGS}"
docker compose -f ${INPUT_COMPOSE_FILE_PATH} ${INPUT_ARGS}

branding:
icon: upload-cloud
color: orange

104 changes: 0 additions & 104 deletions docker-entrypoint.sh

This file was deleted.