sharpetronics.com/.drone.yml

162 lines
5.9 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.
2022-12-13 21:02:01 -05:00
# Copyright (C) SharpeTronics LLC, 2013-PRESENT
2022-11-26 22:14:34 -05:00
2022-12-13 21:02:01 -05:00
# Author(s): SharpeTronics LLC
2022-11-26 22:14:34 -05:00
# 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/
2022-12-13 21:02:01 -05:00
# If you incorporate or include any code from SharpeTronics LLC, your
2022-11-26 22:14:34 -05:00
# 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.
2022-12-13 21:02:01 -05:00
# We are open to granting a more permissive (such as MIT or Apache 2.0) license to SharpeTronics LLC,
2022-11-26 22:14:34 -05:00
# 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-12-10 17:20:15 -05:00
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-12-01 21:10:26 -05:00
STRAPI_BOT_USER_EMAIL:
from_secret: strapi_bot_user_email
2022-12-01 21:11:20 -05:00
STRAPI_BOT_USER_PASS:
2022-12-01 21:10:26 -05:00
from_secret: strapi_bot_user_pass
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/
- git checkout www-data
2022-11-29 16:58:34 -05:00
# remove all build files and keep only _site directory
2022-11-29 17:08:29 -05:00
- ls -a
- rm -rfv *
2022-11-29 16:58:34 -05:00
# copy all the files from the finished previous build ../site
2022-11-29 15:46:35 -05:00
- cp -R ../_site/* .
2022-11-29 16:58:34 -05:00
# display files being pushed to www-data
2022-11-29 17:14:18 -05:00
- ls -a
2022-11-29 16:58:34 -05:00
# add changes from all tracked and untracked files
- git add -A
- git commit -m "SharpeTronics bots bee-ring bots!"
# push fresh _site only www-data to remote git.sharpetronics.com
2022-11-29 17:14:18 -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
2022-12-13 21:02:01 -05:00
#- 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
2022-12-13 21:02:01 -05:00
#- 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
2022-12-13 21:02:01 -05:00
#- rsync -avz --chmod=775 -e ssh ../www-data_sharpetronics.tar.gz $SSH_USER@$SSH_HOST:/var/www/downloads.sharpetronics.com/html/sharpetronics.com/
# _ _ _
# ___| |_ __ _ _ __ | |_ _ __ ___| | __
# / __| __/ _` | '__| | __| '__/ _ \ |/ /
# \__ \ || (_| | | | |_| | | __/ <
# |___/\__\__,_|_| \__|_| \___|_|\_\
# _______----_______
# ___---~~~~~.. ... .... ... ..~~~~~---___
# _ ==============================================
# __________________________ - .. .. _--~~~~~-------____-------~~~~~
#(______________________][__)____ -
# / /______---~~~.. .. ..~~-_~
# <_______________________________-
# ~~~~~~~-----__ __-
# ~~~~~~~~~~~
# U S S E N T E R P R I S E N C C - 1 7 0 1 - D