Skip to content

Commit

Permalink
Added Docker files which set up the Action item for Github.
Browse files Browse the repository at this point in the history
Signed-off-by: Israel Roldan <[email protected]>
  • Loading branch information
airvzxf committed Sep 13, 2020
1 parent 7ae3456 commit b80affa
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .idea/runConfigurations/Dockerfile.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM debian:stable-slim

WORKDIR /app

RUN apt-get -y update && \
apt-get install -y \
lftp

COPY init.sh /app/init.sh
COPY LICENSE README.md /app/

ENTRYPOINT ["/app/init.sh"]
#RUN ["/bin/sh", "/app/init.sh"]
41 changes: 41 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'ftp-deployment-action'
author: 'Israel Roldan <[email protected]>'
description: >-
FTP Deployment:
This GitHub action copy the files via FTP from your Git project to your server in a specific path.
inputs:
server:
description: 'FTP Server'
required: true
user:
description: 'FTP User'
required: true
password:
description: 'FTP Password'
required: true
ssl_allow:
description: 'Allow SSL encryption'
required: false
default: 'false'
use_feat:
description: 'Use FEAT: Determining what extended features the FTP server supports'
required: false
default: 'false'
delete:
description: 'Delete all the files inside of the remote directory.'
required: false
default: 'false'
local_dir:
description: 'Local directory'
required: false
default: ''
remote_dir:
description: 'Remote directory'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
branding:
color: 'blue'
icon: 'upload-cloud'
53 changes: 53 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# TODO: Add list of excluded delete files in two formats, string separated by space and file.

INPUT_SERVER=rovisoft.net
[email protected]
INPUT_PASSWORD=OpYfgb5coLyd
INPUT_SSL_ALLOW=false
INPUT_USE_FEAT=false
INPUT_DELETE=true
#INPUT_LOCAL_DIR=""
INPUT_REMOTE_DIR=""

FTP_SETTINGS='set ftp:ssl-allow '${INPUT_SSL_ALLOW}'; set ftp:use-feat '${INPUT_USE_FEAT}';'
FILE_LIST=remote_ftp_list_$(date "+%s").tmp

if [ -z "${INPUT_REMOTE_DIR}" ]; then
INPUT_REMOTE_DIR="./"
else
INPUT_REMOTE_DIR="./${INPUT_REMOTE_DIR}/"
fi

if [ "${INPUT_DELETE}" = "true" ]; then
echo "Deleting from the Server the files and directories with 'lftp'."
echo -e " Path: ${INPUT_REMOTE_DIR}\n"

rm -f "${FILE_LIST}"

lftp \
-u ${INPUT_USER},${INPUT_PASSWORD} \
${INPUT_SERVER} \
-e "${FTP_SETTINGS} renlist > ${FILE_LIST}; quit;"

sed -i 's/^\.$/..\n/g' "${FILE_LIST}"
sed -i ':begin;N;$!b begin;s/\.\.\n//gm' "${FILE_LIST}"

DELETE_ITEMS=""
while read -r LINE; do
if [ -n "$LINE" ]; then
DELETE_ITEMS=${DELETE_ITEMS}"${INPUT_REMOTE_DIR}$LINE "
fi
done <"${FILE_LIST}"

rm -f "${FILE_LIST}"

lftp \
-u ${INPUT_USER},${INPUT_PASSWORD} \
${INPUT_SERVER} \
-e "${FTP_SETTINGS} glob rm -rf ${DELETE_ITEMS} 2>/dev/null; quit;"
fi

pwd
ls -lha .

0 comments on commit b80affa

Please sign in to comment.