proces polegający na dodawaniu (integracji) zmian w kodzie do repozytorium oraz weryfikacji tych integracji
proces polegający na publikacji zmian
$ ssh-keygen -t ecdsa -b 521 -C "Gitlab CI"
* bez hasła (passphrase)
$ cat ~/.ssh/gitlab_ci_example.pub | pbcopy
GCI_HOST_PRODUCTION
- host / adres IP produkcji
GCI_HOST_PRODUCTION_PATH
- scieżka do katalogu na produkcji
GCI_HOST_STAGING
- host / adres IP stagingu
GCI_HOST_STAGING_PATH
- scieżka do katalogu na stagingu
GCI_SSH_KEY
- klucz prywatny (zakodowany w base64)
GCI_SSH_PORT
- port SSH
GCI_SSH_USER
- użytkownik SSH
GCI_THEME_NAME
- nazwa motywu
GCI_SSH_KEY
$ base64 -i /path/to/PRIVATE/key/file | pbcopy
stages:
- build
- deploy_staging
- deploy_production
.common:
image: php:7.4-alpine
artifacts:
paths:
- wp/wp-content/themes/$GCI_THEME_NAME
script:
- |
if [[ "$CI_COMMIT_REF_NAME" == "develop" ]]; then
export GCI_HOST="$GCI_HOST_STAGING"
export GCI_HOST_PATH="$GCI_HOST_STAGING_PATH"
elif [[ "$CI_COMMIT_REF_NAME" == "main" ]]; then
export GCI_HOST="$GCI_HOST_PRODUCTION"
export GCI_HOST_PATH="$GCI_HOST_PRODUCTION_PATH"
fi
- echo "Deploying to $GCI_HOST"
- apk add openssh rsync
- GCI_SSH_PATH="./.ssh"
- GCI_PRIVATE_KEY=$(echo "$GCI_SSH_KEY" | base64 -d)
- GCI_PRIVATE_KEY_PATH="$GCI_SSH_PATH/id_ecdsa"
- GCI_SRC_PATH="wp/"
- GCI_IGNORE_FILE=".ciignore"
- GCI_SSH_PARAMS="-v -p $GCI_SSH_PORT -o StrictHostKeyChecking=no -i $GCI_PRIVATE_KEY_PATH"
- mkdir "$GCI_SSH_PATH"
- echo "$GCI_PRIVATE_KEY" > "$GCI_PRIVATE_KEY_PATH"
- chmod 700 "$GCI_SSH_PATH"
- chmod 600 "$GCI_PRIVATE_KEY_PATH"
- echo -e "\e[0Ksection_start:`date +%s`:php_lint[collapsed=true]\r\e[0KLinting PHP files"
- |
for file in $(find $GCI_SRC_PATH -name "*.php"); do
php -l -f $file
STATUS=$?
if [[ $STATUS -ne 0 ]]; then
echo "FAILURE: Linting failed - $file :: $STATUS" && exit 1
fi
done
- echo -e "\e[0Ksection_end:`date +%s`:php_lint\r\e[0K"
- ssh $GCI_SSH_USER@$GCI_HOST $GCI_SSH_PARAMS -- "cd $GCI_HOST_PATH && sh bin/backup.sh"
- rsync --rsh="ssh $GCI_SSH_PARAMS" -azvr --exclude=".*" --exclude-from="./$GCI_IGNORE_FILE" $GCI_SRC_PATH $GCI_SSH_USER@$GCI_HOST:$GCI_HOST_PATH
- ssh $GCI_SSH_USER@$GCI_HOST $GCI_SSH_PARAMS -- "cd $GCI_HOST_PATH && sh bin/cc.sh"
- echo "SUCCESS! Site has been deployed to $GCI_HOST and cache has been flushed."
#!/bin/bash
BACKUP_DIR="$HOME/backups";
CURRDIR=$(pwd | xargs basename)
NOW=$(date +"%d-%m-%Y_%H:%M:%S")
FILENAME="backup-$CURRDIR-$NOW"
mkdir -p "$BACKUP_DIR"
echo "Rozpoczynam backup 🤞🚀"
printf "\n"
echo "➡️ Kopia bazy danych ..."
wp db export --add-drop-table "$FILENAME.sql"
printf "\n"
echo "➡️ Kopia plików ..."
zip -rq "$FILENAME.zip" * -x **/*.zip **/*.tar.gz wp-content/uploads/**\* wp-content/cache/**\* .git/**\*
echo "Plik został utworzony: $FILENAME.zip"
printf "\n"
echo "➡️ Przenoszę plik ($FILENAME)"
mv "$FILENAME.zip" "$BACKUP_DIR"/"$FILENAME.zip"
printf "\n"
echo "➡️ Usuwam zrzut bazy"
rm "$FILENAME.sql"
printf "\n"
echo "All steps done 💥💪"
#!/bin/bash
printf "\n"
echo "Rozpoczynam czyszczenie cache 🤞🚀"
printf "\n"
# LiteSpeed Cache plugin
# wp litespeed-purge all
# rm -rf wp-content/litespeed/*
# WordPress
wp cache flush
# Elementor plugin
# wp elementor flush_css
# WP Rocket plugin
# wp rocket clean --confirm