Skip to content

Commit

Permalink
Changed the Docker container from Debian to Alpine.
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 5d314db commit 3f62b86
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 46 deletions.
12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
FROM debian:stable-slim
FROM alpine:latest

WORKDIR /app
RUN apk add --no-cache lftp

RUN apt-get -y update && \
apt-get install -y \
lftp
WORKDIR /app
WORKDIR /public_html

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

RUN ["/bin/chmod", "+x", "/app/init.sh"]

ENTRYPOINT ["/app/init.sh"]
#RUN ["/bin/sh", "/app/init.sh"]
72 changes: 34 additions & 38 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
#!/bin/bash

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

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

echo "=== Environment variables ==="
echo "INPUT_SERVER: ${INPUT_SERVER}"
echo "INPUT_USER: ${INPUT_USER}"
echo "INPUT_PASSWORD: ${INPUT_PASSWORD}"
echo "INPUT_SSL_ALLOW: ${INPUT_SSL_ALLOW}"
echo "INPUT_USE_FEAT: ${INPUT_USE_FEAT}"
echo "INPUT_DELETE: ${INPUT_DELETE}"
echo "INPUT_LOCAL_DIR: ${INPUT_LOCAL_DIR}"
echo "INPUT_REMOTE_DIR: ${INPUT_REMOTE_DIR}"
echo ""
echo "=== Current location==="
pwd
echo ""
echo "=== List this directory ==="
ls -lha
echo ""

if [ -z "${INPUT_LOCAL_DIR}" ]; then
INPUT_LOCAL_DIR="/public_html/"
else
INPUT_LOCAL_DIR="/public_html/${INPUT_LOCAL_DIR}/"
fi

if [ -z "${INPUT_REMOTE_DIR}" ]; then
INPUT_REMOTE_DIR="./"
Expand All @@ -12,39 +34,13 @@ else
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;"
MIRROR_COMMAND="${MIRROR_COMMAND} --delete"
fi

echo "INPUT_SERVER: ${INPUT_SERVER}"
echo "INPUT_USER: ${INPUT_USER}"
echo "INPUT_PASSWORD: ${INPUT_PASSWORD}"
echo "INPUT_SSL_ALLOW: ${INPUT_SSL_ALLOW}"
echo "INPUT_USE_FEAT: ${INPUT_USE_FEAT}"
echo "INPUT_DELETE: ${INPUT_DELETE}"
echo "INPUT_LOCAL_DIR: ${INPUT_LOCAL_DIR}"
echo "INPUT_REMOTE_DIR: ${INPUT_REMOTE_DIR}"
lftp \
-u "${INPUT_USER}","${INPUT_PASSWORD}" \
"${INPUT_SERVER}" \
-e "${FTP_SETTINGS} ${MIRROR_COMMAND} ${INPUT_LOCAL_DIR} ${INPUT_REMOTE_DIR}; quit;"

echo ""
echo "FTP UPLOADED FINISHED!"

0 comments on commit 3f62b86

Please sign in to comment.