Compare commits

...

29 Commits

Author SHA1 Message Date
797d0ef686 Migrate to drone build
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-29 17:15:05 +02:00
rubenelshof
db24bc0bdd Add PLUGIN_FTP_USERNAME & PLUGIN_FTP_PASSWORD 2024-04-29 15:22:33 +02:00
Christoph Schlosser
7f20f9eb2c
Merge pull request #31 from fuse314/only-newer-2
Only transfer newer files
2022-12-22 01:42:23 +01:00
Gottfried Mayer
ae476dce41
document PLUGIN_ONLY_NEWER parameter 2022-10-31 14:55:51 +01:00
Gottfried Mayer
42ec53a83b
new parameter PLUGIN_ONLY NEWER
- only uploads newer files (mirror parameter -n)
- ignores timestamp due to time differences between local and remote system (mirror parameter --ignore time)
- removes any files/folders from the server that are not present in the source directory (mirror parameter -e)
2022-10-31 14:39:38 +01:00
Christoph Schlosser
6b1af9d61e
Merge pull request #29 from fuse314/pre-post-actions
Pre/post actions
2022-08-20 16:44:04 +02:00
Gottfried Mayer
51da955bfc
describe pre/post actions with an example 2022-08-18 11:56:12 +02:00
Gottfried Mayer
2bbbdee1e1
Merge branch 'cschlosser:master' into pre-post-actions 2022-08-18 11:43:57 +02:00
Christoph Schlosser
cbf4cd4b5e
Merge pull request #28 from fuse314/ssh-rsa
New Parameter PLUGIN_SSH_ACCEPT_RSA
2022-08-16 21:11:26 +02:00
Christoph Schlosser
dfb6efbad3
Merge pull request #27 from Bouni/master
Update badges
2022-08-16 21:10:33 +02:00
Gottfried Mayer
431c98295b
document new parameters 2022-08-08 11:22:07 +02:00
Gottfried Mayer
481de753b1
new parameters PLUGIN_PRE/POST_ACTION 2022-08-08 11:20:08 +02:00
Gottfried Mayer
4f4063bf9e
document new parameter PLUGIN_SSH_ACCEPT_RSA 2022-08-05 21:25:13 +02:00
Gottfried Mayer
70452fab5c
new parameter PLUGIN_SSH_ACCEPT_RSA 2022-08-05 17:55:07 +02:00
Gottfried Mayer
3c4e54f0dd
create .ssh directory 2022-08-05 17:51:01 +02:00
bouni
ec9c488494
Update badges 2022-07-27 08:14:19 +02:00
Christoph Schlosser
9a67c805e1
Create docker.yml 2022-05-26 22:06:18 +02:00
Christoph Schlosser
89b3d3d4ed
Merge pull request #26 from Bouni/master
Add debug option, SSH auto confirm fingerprint
2022-05-26 21:58:21 +02:00
bouni
28fecde917 Extended README with missing and new options 2022-05-18 09:26:46 +00:00
bouni
6dd895b3a0 add PLUGIN_DEBUG and PLUGIN_AUTO_CONFIRM options 2022-05-18 09:22:49 +00:00
bouni
9a83d2192e Add openssh to Dockerfile 2022-05-18 09:22:09 +00:00
Christoph Schlosser
650ed37743
Merge pull request #20 from josevavia/custom-mirror-opts
Custom mirror opts
2020-10-25 14:46:13 +01:00
Christoph Schlosser
a938318be0
Merge pull request #19 from josevavia/fix-include-exclude
Fix PLUGIN_EXCLUDE and PLUGIN_INCLUDE
2020-10-25 14:45:41 +01:00
Jose Vázquez Viader
a625c2107f Added option to send custom options to mirror 2020-10-24 19:39:37 +02:00
Jose Vázquez Viader
785fccfb03 For use regexp in include/exclude, it is needed to surround expresion in single quotes 2020-10-24 19:05:03 +02:00
Christoph Schlosser
30922df403
Merge pull request #16 from nagos/master
FTP connection max retries
2020-03-30 21:40:43 +02:00
Vladimir Yakovlev
892aad0721 FTP connection max retries 2020-03-28 19:17:38 +03:00
Christoph Schlosser
022ff94a9c
Required vs optional 2019-05-17 20:17:33 +02:00
Christoph Schlosser
f99d405a71
Update README to drone 1.0.0 2019-05-17 20:15:51 +02:00
5 changed files with 242 additions and 49 deletions

22
.drone-manifest.yml Normal file
View File

@ -0,0 +1,22 @@
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

92
.drone.yml Normal file
View File

@ -0,0 +1,92 @@
---
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,11 +1,12 @@
FROM alpine:edge
RUN apk --no-cache add \
openssh \
libressl \
lftp \
bash
ADD upload.sh /bin/
RUN chmod +x /bin/upload.sh
RUN chmod +x /bin/upload.sh && mkdir ~/.ssh && chmod 700 ~/.ssh
ENTRYPOINT /bin/upload.sh

130
README.md
View File

@ -1,61 +1,107 @@
# Deploy to FTP(S) server from Drone CI
[![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/)
[![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/)
## Usage
You have to set the username and password for your FTP server in the `FTP_USERNAME` and `FTP_PASSWORD` secret.
### Basic
## Required settings
```yaml
pipeline:
deploy:
image: cschlosser/drone-ftps
hostname: example.com:21
secrets: [ ftp_username, ftp_password ]
environment:
FTP_USERNAME:
from_secret: username
FTP_PASSWORD:
from_secret: password
PLUGIN_HOSTNAME: example.com:21
```
### Optional settings
## Optional settings
```yaml
secure: true | false (default true)
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.
dest_dir: /path/to/dest (default /)
src_dir: /path/to/src (default ./)
exclude: (egrep like pattern matching)
- ^\.git/$
- ^\.gitignore$
- ^\.drone.yml$
include: like exclude
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;
```
Full file:
### 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
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$
kind: pipeline
name: default
steps:
- name: master_build
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
```

View File

@ -1,10 +1,16 @@
#!/bin/bash
if [ -z "$FTP_USERNAME" ]; then
if [[ -z "$FTP_USERNAME" && -z "$PLUGIN_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
@ -32,30 +38,56 @@ else
PLUGIN_CHMOD=""
fi
if [ "$PLUGIN_ONLY_NEWER" = true ]; then
PLUGIN_ONLY_NEWER="-e -n --ignore-time"
else
PLUGIN_ONLY_NEWER=""
fi
if [ "$PLUGIN_CLEAN_DIR" = true ]; then
PLUGIN_CLEAN_DIR="rm -r $PLUGIN_DEST_DIR"
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 -e "set xfer:log 1; \
lftp $PLUGIN_DEBUG -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_INCLUDE_STR $PLUGIN_EXCLUDE_STR $(pwd)$PLUGIN_SRC_DIR $PLUGIN_DEST_DIR" \
-u $FTP_USERNAME,$FTP_PASSWORD $PLUGIN_HOSTNAME
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"