commit 11e0f786fe409ba855aa0867672f04b7b70d16d1 Author: Allan Eising Date: Tue Jul 2 13:09:46 2024 +0200 Initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7631691 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.20 + +RUN apk --update add openssh bash + +WORKDIR /gitea/workspace + +COPY entrypoint.sh . + +ENTRYPOINT ["/gitea/workspace/entrypoint.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9e0b0be --- /dev/null +++ b/LICENSE @@ -0,0 +1,33 @@ +BSD 4-Clause License + +Copyright (c) 2020, Aleksandr Derbenev +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. All advertising materials mentioning features or use of this software must + display the following acknowledgement: + This product includes software developed by Aleksandr Derbenev. + +4. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.org b/README.org new file mode 100644 index 0000000..25f1067 --- /dev/null +++ b/README.org @@ -0,0 +1 @@ +#+title: Action to login to a private registry on a remote host diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..0a3fc74 --- /dev/null +++ b/action.yml @@ -0,0 +1,40 @@ +name: Docker-Private-Registry-SSH-login +description: Action to log in to a private docker registry on a host reachable via SSH. +author: "Allan Eising" +branding: + icon: "unlock" + color: "yellow" + +inputs: + ssh_private_key: + description: "Private SSH key used for logging into remote system." + required: true + ssh_host: + description: Host to deploy to. + required: true + ssh_port: + description: SSH Port + default: 22 + required: true + ssh_user: + description: Remote user name. + required: true + registry: + description: Registry hostname + required: true + registry_username: + description: User to log in with on the registry. + registry_password: + description: Password or API token for the registry. + +runs: + using: docker + image: Dockerfile + env: + SSH_PRIVATE_KEY: ${{ inputs.ssh_private_key }} + SSH_HOST: ${{ inputs.ssh_host }} + SSH_PORT: ${{ inputs.ssh_port }} + SSH_USER: ${{ inputs.ssh_user }} + REGISTRY_HOST: ${{ inputs.registry }} + REGISTRY_USER: ${{ inputs.registry_username }} + REGISTRY_PASSWORD: ${{ inputs.registry_password }} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..0a56e53 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + + +set -eu + +echo "Launching SSH agent" +eval $(ssh-agent -s) +ssh-add <(echo "$SSH_PRIVATE_KEY") + +echo "Logging in on remote host..." + +ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ + "$SSH_USER@$SSH_HOST" -p "$SSH_PORT" \ + "docker login -u ${REGISTRY_USER} --password-stdin ${REGISTRY_HOST}" \ + <<< "$REGISTRY_PASSWORD" diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..e12a055 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,23 @@ +# Simple SSH server for testing + +FROM alpine:3.20 + + +RUN < /dev/null; then + echo -e "${GREEN}Test passed.${NC}" +else + echo -e "${RED}Test failed.${NC}" + echo -e "Output: \n" + echo "${output}" +fi + +echo -e "\n"