Compare commits

..

3 Commits

Author SHA1 Message Date
Christoph Schlosser
c7006319a6
Add ignore timezone and twice -R 2018-09-25 18:38:53 +02:00
Christoph Schlosser
e2827d98d7
Add -e option to only newer 2018-09-16 16:08:27 +02:00
Christoph Schlosser
0aee6b5f7a
Include option to upload only new files 2018-09-12 22:10:49 +02:00
5 changed files with 50 additions and 237 deletions

View File

@ -1,22 +0,0 @@
image: nemunaire/drone-ftps:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
- {{this}}
{{/each}}
{{/if}}
manifests:
- image: nemunaire/drone-ftps:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
- image: nemunaire/drone-ftps:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
variant: v8
- image: nemunaire/drone-ftps:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform:
architecture: arm
os: linux
variant: v7

View File

@ -1,92 +0,0 @@
---
kind: pipeline
type: docker
name: build-amd64
platform:
os: linux
arch: amd64
steps:
- name: publish on Docker Hub
image: plugins/docker
settings:
repo: nemunaire/drone-ftps
auto_tag: true
auto_tag_suffix: ${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
dockerfile: Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
---
kind: pipeline
type: docker
name: build-arm64
platform:
os: linux
arch: arm64
steps:
- name: publish on Docker Hub
image: plugins/docker
settings:
repo: nemunaire/drone-ftps
auto_tag: true
auto_tag_suffix: ${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
dockerfile: Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
---
kind: pipeline
type: docker
name: build-arm
platform:
os: linux
arch: arm
steps:
- name: publish on Docker Hub
image: plugins/docker:linux-arm
settings:
repo: nemunaire/drone-ftps
auto_tag: true
auto_tag_suffix: ${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
dockerfile: Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
---
kind: pipeline
name: docker-manifest
steps:
- name: publish on Docker Hub
image: plugins/manifest
settings:
auto_tag: true
ignore_missing: true
spec: .drone-manifest.yml
username:
from_secret: docker_username
password:
from_secret: docker_password
trigger:
event:
- cron
- push
- tag
depends_on:
- build-amd64
- build-arm64
- build-arm

View File

@ -1,12 +1,11 @@
FROM alpine:edge
RUN apk --no-cache add \
openssh \
libressl \
lftp \
bash
ADD upload.sh /bin/
RUN chmod +x /bin/upload.sh && mkdir ~/.ssh && chmod 700 ~/.ssh
RUN chmod +x /bin/upload.sh
ENTRYPOINT /bin/upload.sh

146
README.md
View File

@ -1,107 +1,61 @@
# Deploy to FTP(S) server from Drone CI
[![Docker Stars](https://badgen.net/docker/stars/cschlosser/drone-ftps)](https://hub.docker.com/r/cschlosser/drone-ftps/)
[![Docker Pulls](https://badgen.net/docker/pulls/cschlosser/drone-ftps)](https://hub.docker.com/r/cschlosser/drone-ftps/)
[![Docker Build](https://img.shields.io/docker/cloud/build/cschlosser/drone-ftps)](https://hub.docker.com/r/cschlosser/drone-ftps/)
[![Docker Size](https://badgen.net/docker/size/cschlosser/drone-ftps)](https://hub.docker.com/r/cschlosser/drone-ftps/)
[![Docker Stars](https://img.shields.io/docker/stars/cschlosser/drone-ftps.svg)](https://hub.docker.com/r/cschlosser/drone-ftps/)
[![Docker Pulls](https://img.shields.io/docker/pulls/cschlosser/drone-ftps.svg)](https://hub.docker.com/r/cschlosser/drone-ftps/)
[![Docker Build](https://img.shields.io/docker/build/cschlosser/drone-ftps.svg)](https://hub.docker.com/r/cschlosser/drone-ftps/)
[![Docker Layers](https://images.microbadger.com/badges/image/cschlosser/drone-ftps.svg)](https://hub.docker.com/r/cschlosser/drone-ftps/)
## Usage
You have to set the username and password for your FTP server in the `FTP_USERNAME` and `FTP_PASSWORD` secret.
## Required settings
### Basic
```yaml
environment:
FTP_USERNAME:
from_secret: username
FTP_PASSWORD:
from_secret: password
PLUGIN_HOSTNAME: example.com:21
```
## Optional settings
```yaml
environment:
PLUGIN_DEST_DIR: /path/to/dest (default /)
PLUGIN_SRC_DIR: /path/to/dest (default ./)
PLUGIN_SECURE: true | false (default true)
PLUGIN_VERIFY: false
PLUGIN_EXCLUDE: (egrep like pattern matching)
PLUGIN_INCLUDE: (egrep like pattern matching)
PLUGIN_CHMOD: true | false (default true)
PLUGIN_CLEAN_DIR: true | false (default false)
PLUGIN_ONLY_NEWER: true | false (default false)
PLUGIN_AUTO_CONFIRM: true | false (default false)
PLUGIN_SSH_ACCEPT_RSA: true | false (default false)
PLUGIN_PRE_ACTION: string (default empty)
PLUGIN_POST_ACTION: string (default empty)
PLUGIN_DEBUG: true | false (default false)
```
### Pre/Post Action
Pre/Post Action can be used to move files/folders out of the way or execute additional commands on the server before and after the deployment process.
The `PLUGIN_PRE_ACTION` is executed *before* the `PLUGIN_CLEAN_DIR` (if set).
The `PLUGIN_POST_ACTION` is executed *after* the ftp "mirror" operation.
Multiple Actions can be set, they need to be divided by a semicolon `;` .
#### Example:
There is another project's folder ("project2") in a subfolder in the destination directory. We need to move this folder to a temporary location and restore it after the upload completed.
```yaml
PLUGIN_CLEAN_DIR: true
PLUGIN_PRE_ACTION: mv /dest/project2 /temp/project2;
PLUGIN_POST_ACTION: mv /temp/project2 /dest/project2;
```
### Transfer only newer files
The setting `PLUGIN_ONLY_NEWER: true` (only transfer newer files) does not mix well with the `PLUGIN_CLEAN_DIR: true` (clean destination directory before transfer).
When setting `PLUGIN_ONLY_NEWER: true` parameter to true, make sure to _exclude_ any files/folders that are not present in the source directory, but should be kept on the server.
#### Example:
Source folder does not contain an `.env` file, it exists on the remote server and should be kept.
Also, we do not want to transfer the source's `.git` folder and `.gitignore` file:
Set `PLUGIN_ONLY_NEWER: true` and `PLUGIN_EXCLUDE: ^\.git/$,^\.gitignore$,^\.env$` environment variables.
## Full file example
```yaml
kind: pipeline
name: default
steps:
- name: master_build
pipeline:
deploy:
image: cschlosser/drone-ftps
environment:
FTP_USERNAME:
from_secret: username
FTP_PASSWORD:
from_secret: password
PLUGIN_HOSTNAME: example.com:21
PLUGIN_SECURE: false
PLUGIN_VERIFY: false
PLUGIN_EXCLUDE: ^\.git/$
when:
branch:
- master
event:
- push
- name: develop_build
image: cschlosser/drone-ftps
environment:
FTP_USERNAME:
from_secret: username
FTP_PASSWORD:
from_secret: password
PLUGIN_HOSTNAME: example.com:21
PLUGIN_DEST_DIR: /develop
PLUGIN_SECURE: false
PLUGIN_VERIFY: false
PLUGIN_EXCLUDE: ^\.git/$
when:
branch:
- develop
event:
- push
hostname: example.com:21
secrets: [ ftp_username, ftp_password ]
```
### Optional settings
```yaml
secure: true | false (default true)
dest_dir: /path/to/dest (default /)
src_dir: /path/to/src (default ./)
exclude: (egrep like pattern matching)
- ^\.git/$
- ^\.gitignore$
- ^\.drone.yml$
include: like exclude
```
Full file:
```yaml
pipeline:
deploy:
image: cschlosser/drone-ftps
hostname: example.com:21
secrets: [ ftp_username, ftp_password ]
secure: true (default) | false # true = use FTP(S), false = FTP without SSL
verify: true (default) | false # true = strong SSL verification, false = supress SSL verification error
chmod: true (default) | false # true = chmod after file transferred, false = no chmod after file transferred
clean_dir: true | false (default) # true = clean destination directory before transferring files, false = don't clean
dest_dir: /var/www/mysite
src_dir: /mysite/static
exclude:
- ^\.git/$
- ^\.gitignore$
- ^\.drone.yml$
include:
- ^*.css$
- ^*.js$
- ^*.html$
```

View File

@ -1,16 +1,10 @@
#!/bin/bash
if [[ -z "$FTP_USERNAME" && -z "$PLUGIN_FTP_USERNAME" ]]; then
if [ -z "$FTP_USERNAME" ]; then
echo "Need to set username"
exit 1
fi
FTP_USERNAME_STR=""
FTP_PASSWORD_STR=""
[ -n "$PLUGIN_FTP_USERNAME" ] && FTP_USERNAME_STR="$PLUGIN_FTP_USERNAME" || FTP_USERNAME_STR="$FTP_USERNAME"
[ -n "$PLUGIN_FTP_PASSWORD" ] && FTP_PASSWORD_STR="$PLUGIN_FTP_PASSWORD" || FTP_PASSWORD_STR="$FTP_PASSWORD"
if [ -z "$PLUGIN_HOSTNAME" ]; then
echo "Need to set hostname"
exit 1
@ -39,7 +33,7 @@ else
fi
if [ "$PLUGIN_ONLY_NEWER" = true ]; then
PLUGIN_ONLY_NEWER="-e -n --ignore-time"
PLUGIN_ONLY_NEWER="-Rne --ignore-time"
else
PLUGIN_ONLY_NEWER=""
fi
@ -50,44 +44,24 @@ else
PLUGIN_CLEAN_DIR=""
fi
if [ -z "$PLUGIN_DEBUG" ]; then
PLUGIN_DEBUG=""
else
PLUGIN_DEBUG="-d"
fi
if [ -n "$PLUGIN_AUTO_CONFIRM" ]; then
PLUGIN_AUTO_CONFIRM="true"
else
PLUGIN_AUTO_CONFIRM="false"
fi
if [ "$PLUGIN_SSH_ACCEPT_RSA" = true ]; then
echo "HostKeyAlgorithms ssh-rsa" > ~/.ssh/config && echo "PubkeyAcceptedKeyTypes ssh-rsa" >> ~/.ssh/config && chmod 600 ~/.ssh/config
fi;
PLUGIN_EXCLUDE_STR=""
PLUGIN_INCLUDE_STR=""
IFS=',' read -ra in_arr <<< "$PLUGIN_EXCLUDE"
for i in "${in_arr[@]}"; do
PLUGIN_EXCLUDE_STR="$PLUGIN_EXCLUDE_STR -x '$i'"
PLUGIN_EXCLUDE_STR="$PLUGIN_EXCLUDE_STR -x $i"
done
IFS=',' read -ra in_arr <<< "$PLUGIN_INCLUDE"
for i in "${in_arr[@]}"; do
PLUGIN_INCLUDE_STR="$PLUGIN_INCLUDE_STR -i '$i'"
PLUGIN_INCLUDE_STR="$PLUGIN_INCLUDE_STR -i $i"
done
lftp $PLUGIN_DEBUG -e "set xfer:log 1; \
lftp -e "set xfer:log 1; \
set ftp:ssl-allow $PLUGIN_SECURE; \
set ftp:ssl-force $PLUGIN_SECURE; \
set ftp:ssl-protect-data $PLUGIN_SECURE; \
set sftp:auto-confirm $PLUGIN_AUTO_CONFIRM; \
set ssl:verify-certificate $PLUGIN_VERIFY; \
set ssl:check-hostname $PLUGIN_VERIFY; \
set net:max-retries 3; \
$PLUGIN_PRE_ACTION; \
$PLUGIN_CLEAN_DIR; \
mirror --verbose $PLUGIN_CHMOD -R $PLUGIN_ONLY_NEWER $PLUGIN_MIRROR_OPTS $PLUGIN_INCLUDE_STR $PLUGIN_EXCLUDE_STR $(pwd)$PLUGIN_SRC_DIR $PLUGIN_DEST_DIR; \
$PLUGIN_POST_ACTION;" \
-u "$FTP_USERNAME_STR","$FTP_PASSWORD_STR" "$PLUGIN_HOSTNAME"
mirror --verbose $PLUGIN_CHMOD $PLUGIN_ONLY_NEWER -R $PLUGIN_INCLUDE_STR $PLUGIN_EXCLUDE_STR $(pwd)$PLUGIN_SRC_DIR $PLUGIN_DEST_DIR" \
-u $FTP_USERNAME,$FTP_PASSWORD $PLUGIN_HOSTNAME