sharpetronics.com/.drone.yml

157 lines
5.7 KiB
YAML
Raw Normal View History

2022-11-26 22:23:28 -05:00
---
2022-11-26 22:14:34 -05:00
# This software configures the virtual machine environment with Gitea and Drone services, builds the Jekyll app, then, securely packages and transports that app to a designated service provider or VPS on the fly.
# Copyright (C) SharpeTronics, LLC, 2013-2023
# Author(s): Charles Sharpe(@odinzu_me) aka SharpeTronics, LLC,
# License: GPLv3
# Version: 1.6
# This is Free Software released under GPLv3. Any misuse of this software
# will be followed up with GPL enforcement via Software Freedom Law Center:
# https://www.softwarefreedom.org/
# If you incorporate or include any code from SharpeTronics, LLC,, your
# code must be licensed as GPLv3 (not GPLv2 or MIT)
# The GPLv3 software license applies to the code directly included in this source distribution.
# See the LICENSE & COPYING file for full information.
# Dependencies downloaded as part of the build process may be covered by other open-source licenses.
# We are open to granting a more permissive (such as MIT or Apache 2.0) license to SharpeTronics, LLC,
# software on a *case-by-case* basis, for an agreed upon price. Please email
# info@sharpetronics.com.
# If you would like to contribute to this code, please follow GPLv3 guidelines.
# as an example, after making changes to the software (Called a Fork) and credit the original copyright holder as the creator with your credit added to theirs.
2022-11-26 22:23:28 -05:00
2022-05-08 16:00:37 -04:00
kind: pipeline
type: docker
2022-05-08 19:21:48 -04:00
name: build
2022-05-08 16:00:37 -04:00
2022-05-08 16:26:06 -04:00
workspace:
path: /drone/src
platform:
2022-05-08 16:37:33 -04:00
os: linux
2022-05-08 16:26:06 -04:00
arch: amd64
2022-05-08 17:34:25 -04:00
trigger:
branch:
- master
2022-05-08 16:12:12 -04:00
steps:
2022-05-08 18:10:41 -04:00
- name: build-website
2022-05-09 19:45:25 -04:00
image: ruby:latest
environment:
2022-05-09 19:27:53 -04:00
GITEA_USER:
from_secret: gitea_user
2022-05-09 19:27:53 -04:00
GITEA_PASS:
from_secret: gitea_pass
2022-05-09 19:27:53 -04:00
SSH_USER:
from_secret: ssh_user
SSH_HOST:
from_secret: ssh_host
2022-05-10 19:15:40 -04:00
NO_HOSTKEY:
from_secret: no_hostkey
2022-05-10 00:13:15 -04:00
SERVER_PASS:
from_secret: server_pass
2022-07-26 22:18:46 -04:00
API_TOKEN:
from_secret: api_token
2022-05-08 18:38:31 -04:00
privileged: false
2022-05-08 16:26:06 -04:00
volumes:
- name: jekyll
path: /srv/jekyll
2022-05-08 18:10:41 -04:00
2022-05-08 16:12:12 -04:00
commands:
2022-05-09 19:27:53 -04:00
# general vm information for debugging
2022-05-08 18:43:35 -04:00
- whoami
- pwd
2022-05-14 20:22:47 -04:00
- gem environment
2022-05-10 19:26:43 -04:00
# add dependencies to tmp docker vm
- apt-get update && apt-get -y install rsync sshpass openssh-server openssh-client bc
- rsync --version
- bc --version
2022-05-09 19:27:53 -04:00
# write the ssh key to disk for rsync handshake to remote server
2022-05-10 18:24:59 -04:00
- 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)
2022-05-10 18:16:23 -04:00
- ssh-keygen -t ed25519 -f ~/.ssh/id_rsync_ed25519 -N ''
2022-05-10 18:27:53 -04:00
- chmod 600 ~/.ssh/id_rsync_ed25519
2022-05-10 18:39:28 -04:00
- eval `ssh-agent -s`
2022-05-10 19:33:41 -04:00
- service ssh start
2022-05-10 19:35:25 -04:00
- service ssh status
# load updated ssh_config from drone secret of repo: StrictHostKeyChecking no
2022-05-10 20:17:28 -04:00
- echo "$NO_HOSTKEY" > /etc/ssh/ssh_config
2022-05-10 19:54:34 -04:00
- cat /etc/ssh/ssh_config
# add private key to ssh-agent for ssh-copy-id
2022-05-10 20:32:08 -04:00
- ssh-add ~/.ssh/id_rsync_ed25519
2022-05-10 19:37:53 -04:00
- service ssh reload
2022-05-10 20:18:56 -04:00
- SSHPASS="$SERVER_PASS" sshpass -ev ssh-copy-id $SSH_USER@$SSH_HOST
2022-05-10 00:23:01 -04:00
2022-05-10 00:24:49 -04:00
# 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
2022-11-25 15:41:26 -05:00
- bundle update --bundler
- bundle exec jekyll build --verbose --trace
2022-05-10 00:24:49 -04:00
2022-05-14 19:05:52 -04:00
# prepare _site dir for www-data branch & compression
2022-05-10 00:27:05 -04:00
- ls -a _site/
- rm _site/docker-compose.yml
2022-05-10 00:23:01 -04:00
# update www-data branch with fresh drone ci Jekyll _site build
- git clone https://git.sharpetronics.com/sharpetronics/sharpetronics.com.git
- cd sharpetronics.com/
2022-11-29 15:50:52 -05:00
- git branch -b www-data
2022-05-10 00:23:01 -04:00
- git checkout www-data
2022-11-29 15:46:35 -05:00
- cp -R ../_site/* .
2022-05-10 00:23:01 -04:00
- git add *
2022-11-29 15:46:35 -05:00
- git commit -m "SharpeTronics bots bee ring bots! A drone CD www-data sync"
2022-11-29 15:00:56 -05:00
- git push https://$GITEA_USER:$GITEA_PASS@git.sharpetronics.com/sharpetronics/sharpetronics.com.git
2022-05-10 00:23:01 -04:00
2022-05-14 19:05:52 -04:00
# sync files to remote server [local _site ] to [remote www edge] while preserving permissions.
- chmod -R 775 ../_site
- groupadd rsync-users
- chown -R www-data:rsync-users ../_site
# a = archive v=verbose z=compress r=recursive -e=env
- rsync -aXvPzr --omit-dir-times --chown=www-data:rsync-users --chmod=775 -e ssh ../_site/* $SSH_USER@$SSH_HOST:/var/www/sharpetronics.com/html/
2022-05-09 19:27:53 -04:00
# 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
2022-11-29 15:46:35 -05:00
# 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*
2022-05-09 19:27:53 -04:00
# add download.tar.gz 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/
2022-05-14 19:07:44 -04:00
#______________________
#< Who you Gonna Call >
#----------------------
# \ __---__
# _- /--______
# __--( / \ )XXXXXXXXXXX\v.
# .-XXX( O O )XXXXXXXXXXXXXXX-
# /XXX( U ) XXXXXXX\
# /XXXXX( )--_ XXXXXXXXXXX\
# /XXXXX/ ( O ) XXXXXX \XXXXX\
# XXXXX/ / XXXXXX \__ \XXXXX
# XXXXXX__/ XXXXXX \__---->
# ---___ XXX__/ XXXXXX \__ /
# \- --__/ ___/\ XXXXXX / ___--/=
# \-\ ___/ XXXXXX '--- XXXXXX
# \-\/XXX\ XXXXXX /XXXXX
# \XXXXXXXXX \ /XXXXX/
# \XXXXXX > _/XXXXX/
# -XXXXXXXX--------------- XXXXXX-
#