sharpetronics.com/.drone.yml
oDinZu 22fceaedee
All checks were successful
continuous-integration/drone/push Build is passing
add comment about variable
Signed-off-by: oDinZu <info@sharpetronics.com>
2022-05-14 17:44:42 -04:00

102 lines
3.2 KiB
YAML

---
kind: pipeline
type: docker
name: build
workspace:
path: /drone/src
platform:
os: linux
arch: amd64
trigger:
branch:
- master
steps:
- name: build-website
image: ruby:latest
environment:
GITEA_USER:
from_secret: gitea_user
GITEA_PASS:
from_secret: gitea_pass
SSH_USER:
from_secret: ssh_user
SSH_HOST:
from_secret: ssh_host
NO_HOSTKEY:
from_secret: no_hostkey
SERVER_PASS:
from_secret: server_pass
privileged: false
volumes:
- name: jekyll
path: /srv/jekyll
commands:
# general vm information for debugging
- whoami
- pwd
# add dependencies to tmp docker vm
- apt-get update && apt-get -y install rsync sshpass openssh-server openssh-client bc
- rsync --version
- bc --version
# write the ssh key to disk for rsync handshake to remote server
- mkdir -p ~/.ssh/
- chmod 700 ~/.ssh
## create key id_rsync_ed25519 & id_rsync_ed25519.pub (Only share *.pub with .ssh/authorized_keys on target server B)
- ssh-keygen -t ed25519 -f ~/.ssh/id_rsync_ed25519 -N ''
- chmod 600 ~/.ssh/id_rsync_ed25519
- eval `ssh-agent -s`
- service ssh start
- service ssh status
## load updated ssh_config from secret of repo: StrictHostKeyChecking no
- echo "$NO_HOSTKEY" > /etc/ssh/ssh_config
- cat /etc/ssh/ssh_config
## add private key to ssh-agent for ssh-copy-id
- ssh-add ~/.ssh/id_rsync_ed25519
- service ssh reload
- SSHPASS="$SERVER_PASS" sshpass -ev ssh-copy-id $SSH_USER@$SSH_HOST
# setup Jekyll permissions and build jekyll site
- adduser --no-create-home --disabled-password --gecos "" jekyll
- chown -R jekyll:jekyll /drone/src
- gem install bundler
- bundle install
- bundle exec jekyll build --trace
# prepare _site dir
- ls -a _site/
- rm _site/docker-compose.yml
# update www-data branch with fresh drone ci Jekyll _site build
- git clone https://git.sharpetronics.com/sharpetronics/sharpetronics.com.git
- cd sharpetronics.com/
- git checkout www-data
- cp -R ../_site/* .
- git add *
- git commit -m "bots beeing bots! A drone www-data push"
- git push https://$GITEA_USER:$GITEA_PASS@git.sharpetronics.com/sharpetronics/sharpetronics.com.git
# sync files to remote server [local _site ] to [remote _site www] while preserving permissions.
- chmod -R 775 ../_site
- groupadd rsync-users
- chown -R www-data:rsync-users ../_site
- rsync -aXvPzr --omit-dir-times --chown=www-data:rsync-users --chmod=775 -e ssh ../_site/* $SSH_USER@$SSH_HOST:/var/www/sharpetronics.com/html/
# create tar.gz of _site directory for download elsewhere
- tar -czf ../www-data_sharpetronics.tar.gz ../_site/*
- chmod 775 ../www-data_sharpetronics.tar.gz
- chown www-data:www-data ../www-data_sharpetronics.tar.gz
# size of the file in bytes
- tar -tzvf ../www-data_sharpetronics.tar.gz | sed 's/ \+/ /g' | cut -f3 -d' ' | sed '2,$s/^/+ /' | paste -sd' ' | bc
- ls ../ww*
# add download of files from download.sharpetronics.com
# a = archive v=verbose z=compress r=recursive -e=env
- rsync -avz --chmod=775 -e ssh ../www-data_sharpetronics.tar.gz $SSH_USER@$SSH_HOST:/var/www/downloads.sharpetronics.com/html/sharpetronics.com/