I'm using lftp to automated gitlab ci deployments. I run a script to deploy my code, except 'static' files that I need to upload to other server. Here a sample of my current code.
script:
- >
lftp
-e "mirror
--exclude ^\.git.*
--exclude-glob *.sql
--exclude-glob *.sqlite3
--exclude-glob *.txt
--exclude-glob *.csv
--exclude-glob *.pyc
--exclude settings.py
--exclude migracion/
--exclude static/
--exclude ^Resources/Private/
--exclude \.gitlab-ci.yaml
-eRv $CI_PROJECT_DIR /pro/ject/dirs; quit;"
sftp://$ACC
This works fine but after this, I have to upload by hand the static files to the static files server. Can you help me with a script that only fetch files in all static folders? Static folders can be in root and inside other folders. Many Thx.
You can use :
lftp -u username,passwd ftp.foobar.cmo \
-e "mirror -e -R -x .git -x static/ -p ./ dev-site ; quit"
Where, in mirror :
-e
: remove files that doesn't exist anymore
-R
: means you upload from local machine to ftp server
-x
: specify a directory to exlude. You can have more than one -x
-p
: parallelize
./
: local dir you want upload
dev-site
: remote dir where upload have to go. Take care about the remote dir parameter :
- if it end with a trail (
dev-site/
), your current dir will be uploaded INSIDE this dir on the ftp server
- if it doesn't end with a trail (
dev-site
), your current dir will be uploaded AS this dir on the ftp server
If yout to use this with GitLab CI to upload your static-generated documentation, here is an example .gitlab-ci.yml
with mkdocs
+ lftp
:
# Build static html site with mkdocs :
build:
stage: build
script:
- mkdocs build
# first upload, exclude static files:
- lftp -u ftp_username,$FTP_PASSWORD ftp.foobar.org -e "mirror -x static -R -p site dev ; quit"
# upload only static to other server:
- lftp -u ftp_username,$FTP_PASSWORD ftp.otherserv.org -e "mirror -R -p static/ remote/dir ; quit"