Compare commits
29 Commits
only-newer
...
master
Author | SHA1 | Date | |
---|---|---|---|
797d0ef686 | |||
|
db24bc0bdd | ||
|
7f20f9eb2c | ||
|
ae476dce41 | ||
|
42ec53a83b | ||
|
6b1af9d61e | ||
|
51da955bfc | ||
|
2bbbdee1e1 | ||
|
cbf4cd4b5e | ||
|
dfb6efbad3 | ||
|
431c98295b | ||
|
481de753b1 | ||
|
4f4063bf9e | ||
|
70452fab5c | ||
|
3c4e54f0dd | ||
|
ec9c488494 | ||
|
9a67c805e1 | ||
|
89b3d3d4ed | ||
|
28fecde917 | ||
|
6dd895b3a0 | ||
|
9a83d2192e | ||
|
650ed37743 | ||
|
a938318be0 | ||
|
a625c2107f | ||
|
785fccfb03 | ||
|
30922df403 | ||
|
892aad0721 | ||
|
022ff94a9c | ||
|
f99d405a71 |
22
.drone-manifest.yml
Normal file
22
.drone-manifest.yml
Normal 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
92
.drone.yml
Normal 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
|
@ -1,11 +1,12 @@
|
|||||||
FROM alpine:edge
|
FROM alpine:edge
|
||||||
|
|
||||||
RUN apk --no-cache add \
|
RUN apk --no-cache add \
|
||||||
|
openssh \
|
||||||
libressl \
|
libressl \
|
||||||
lftp \
|
lftp \
|
||||||
bash
|
bash
|
||||||
|
|
||||||
ADD upload.sh /bin/
|
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
|
ENTRYPOINT /bin/upload.sh
|
||||||
|
140
README.md
140
README.md
@ -1,61 +1,107 @@
|
|||||||
# Deploy to FTP(S) server from Drone CI
|
# 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 Stars](https://badgen.net/docker/stars/cschlosser/drone-ftps)](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 Pulls](https://badgen.net/docker/pulls/cschlosser/drone-ftps)](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 Build](https://img.shields.io/docker/cloud/build/cschlosser/drone-ftps)](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 Size](https://badgen.net/docker/size/cschlosser/drone-ftps)](https://hub.docker.com/r/cschlosser/drone-ftps/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
You have to set the username and password for your FTP server in the `FTP_USERNAME` and `FTP_PASSWORD` secret.
|
You have to set the username and password for your FTP server in the `FTP_USERNAME` and `FTP_PASSWORD` secret.
|
||||||
|
|
||||||
### Basic
|
## Required settings
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
pipeline:
|
environment:
|
||||||
deploy:
|
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
|
||||||
image: cschlosser/drone-ftps
|
image: cschlosser/drone-ftps
|
||||||
hostname: example.com:21
|
environment:
|
||||||
secrets: [ ftp_username, ftp_password ]
|
FTP_USERNAME:
|
||||||
```
|
from_secret: username
|
||||||
|
FTP_PASSWORD:
|
||||||
|
from_secret: password
|
||||||
|
PLUGIN_HOSTNAME: example.com:21
|
||||||
|
|
||||||
### Optional settings
|
PLUGIN_SECURE: false
|
||||||
|
PLUGIN_VERIFY: false
|
||||||
|
PLUGIN_EXCLUDE: ^\.git/$
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
- master
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
|
||||||
```yaml
|
- name: develop_build
|
||||||
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
|
image: cschlosser/drone-ftps
|
||||||
hostname: example.com:21
|
environment:
|
||||||
secrets: [ ftp_username, ftp_password ]
|
FTP_USERNAME:
|
||||||
secure: true (default) | false # true = use FTP(S), false = FTP without SSL
|
from_secret: username
|
||||||
verify: true (default) | false # true = strong SSL verification, false = supress SSL verification error
|
FTP_PASSWORD:
|
||||||
chmod: true (default) | false # true = chmod after file transferred, false = no chmod after file transferred
|
from_secret: password
|
||||||
clean_dir: true | false (default) # true = clean destination directory before transferring files, false = don't clean
|
PLUGIN_HOSTNAME: example.com:21
|
||||||
dest_dir: /var/www/mysite
|
PLUGIN_DEST_DIR: /develop
|
||||||
src_dir: /mysite/static
|
PLUGIN_SECURE: false
|
||||||
exclude:
|
PLUGIN_VERIFY: false
|
||||||
- ^\.git/$
|
PLUGIN_EXCLUDE: ^\.git/$
|
||||||
- ^\.gitignore$
|
when:
|
||||||
- ^\.drone.yml$
|
branch:
|
||||||
include:
|
- develop
|
||||||
- ^*.css$
|
event:
|
||||||
- ^*.js$
|
- push
|
||||||
- ^*.html$
|
|
||||||
```
|
```
|
||||||
|
40
upload.sh
40
upload.sh
@ -1,10 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [ -z "$FTP_USERNAME" ]; then
|
if [[ -z "$FTP_USERNAME" && -z "$PLUGIN_FTP_USERNAME" ]]; then
|
||||||
echo "Need to set username"
|
echo "Need to set username"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
if [ -z "$PLUGIN_HOSTNAME" ]; then
|
||||||
echo "Need to set hostname"
|
echo "Need to set hostname"
|
||||||
exit 1
|
exit 1
|
||||||
@ -33,7 +39,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$PLUGIN_ONLY_NEWER" = true ]; then
|
if [ "$PLUGIN_ONLY_NEWER" = true ]; then
|
||||||
PLUGIN_ONLY_NEWER="-Rne --ignore-time"
|
PLUGIN_ONLY_NEWER="-e -n --ignore-time"
|
||||||
else
|
else
|
||||||
PLUGIN_ONLY_NEWER=""
|
PLUGIN_ONLY_NEWER=""
|
||||||
fi
|
fi
|
||||||
@ -44,24 +50,44 @@ else
|
|||||||
PLUGIN_CLEAN_DIR=""
|
PLUGIN_CLEAN_DIR=""
|
||||||
fi
|
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_EXCLUDE_STR=""
|
||||||
PLUGIN_INCLUDE_STR=""
|
PLUGIN_INCLUDE_STR=""
|
||||||
|
|
||||||
IFS=',' read -ra in_arr <<< "$PLUGIN_EXCLUDE"
|
IFS=',' read -ra in_arr <<< "$PLUGIN_EXCLUDE"
|
||||||
for i in "${in_arr[@]}"; do
|
for i in "${in_arr[@]}"; do
|
||||||
PLUGIN_EXCLUDE_STR="$PLUGIN_EXCLUDE_STR -x $i"
|
PLUGIN_EXCLUDE_STR="$PLUGIN_EXCLUDE_STR -x '$i'"
|
||||||
done
|
done
|
||||||
IFS=',' read -ra in_arr <<< "$PLUGIN_INCLUDE"
|
IFS=',' read -ra in_arr <<< "$PLUGIN_INCLUDE"
|
||||||
for i in "${in_arr[@]}"; do
|
for i in "${in_arr[@]}"; do
|
||||||
PLUGIN_INCLUDE_STR="$PLUGIN_INCLUDE_STR -i $i"
|
PLUGIN_INCLUDE_STR="$PLUGIN_INCLUDE_STR -i '$i'"
|
||||||
done
|
done
|
||||||
|
|
||||||
lftp -e "set xfer:log 1; \
|
lftp $PLUGIN_DEBUG -e "set xfer:log 1; \
|
||||||
set ftp:ssl-allow $PLUGIN_SECURE; \
|
set ftp:ssl-allow $PLUGIN_SECURE; \
|
||||||
set ftp:ssl-force $PLUGIN_SECURE; \
|
set ftp:ssl-force $PLUGIN_SECURE; \
|
||||||
set ftp:ssl-protect-data $PLUGIN_SECURE; \
|
set ftp:ssl-protect-data $PLUGIN_SECURE; \
|
||||||
|
set sftp:auto-confirm $PLUGIN_AUTO_CONFIRM; \
|
||||||
set ssl:verify-certificate $PLUGIN_VERIFY; \
|
set ssl:verify-certificate $PLUGIN_VERIFY; \
|
||||||
set ssl:check-hostname $PLUGIN_VERIFY; \
|
set ssl:check-hostname $PLUGIN_VERIFY; \
|
||||||
|
set net:max-retries 3; \
|
||||||
|
$PLUGIN_PRE_ACTION; \
|
||||||
$PLUGIN_CLEAN_DIR; \
|
$PLUGIN_CLEAN_DIR; \
|
||||||
mirror --verbose $PLUGIN_CHMOD $PLUGIN_ONLY_NEWER -R $PLUGIN_INCLUDE_STR $PLUGIN_EXCLUDE_STR $(pwd)$PLUGIN_SRC_DIR $PLUGIN_DEST_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; \
|
||||||
-u $FTP_USERNAME,$FTP_PASSWORD $PLUGIN_HOSTNAME
|
$PLUGIN_POST_ACTION;" \
|
||||||
|
-u "$FTP_USERNAME_STR","$FTP_PASSWORD_STR" "$PLUGIN_HOSTNAME"
|
||||||
|
Loading…
Reference in New Issue
Block a user