added deploy process
This commit is contained in:
parent
22c976ff21
commit
3947b3e0c8
4
.vars
Normal file
4
.vars
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#/usr/bin/env bash
|
||||||
|
|
||||||
|
export DEPLOYMENT_HOST=docker.infra.bjphoster.cloud
|
||||||
|
export DEPLOYMENT_PATH=/opt/pedini.dev
|
42
deploy.sh
Executable file
42
deploy.sh
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
###
|
||||||
|
# FLOW
|
||||||
|
###
|
||||||
|
#
|
||||||
|
# if the private key variable is set, prepend "-i" to it
|
||||||
|
# if the username variable is set, append the at sign to it
|
||||||
|
# if either the deployment host or deployment path variables are not set, return an error
|
||||||
|
# tarball the built website and scp it to the deployment host
|
||||||
|
# ssh to the remote host, cd to the deployment path, and get the data path from .env file
|
||||||
|
# then remove everything in the data path, untar the tarball and reload the server
|
||||||
|
# finally remove the tarball, both from the remote host and locally (cleanup)
|
||||||
|
|
||||||
|
# Check if the private key variable is set
|
||||||
|
if [ ! -z "${SSH_PRIVATE_KEY}" ]; then
|
||||||
|
SSH_PRIVATE_KEY="-i ${SSH_PRIVATE_KEY}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the username variable is set
|
||||||
|
if [ ! -z "${SSH_USERNAME}" ]; then
|
||||||
|
SSH_USERNAME="${SSH_USERNAME}@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if either the deployment host or deployment path variables are not set
|
||||||
|
if [ -z "${DEPLOYMENT_HOST}" ] || [ -z "${DEPLOYMENT_PATH}" ]; then
|
||||||
|
echo "required variable DEPLOYMENT_HOST is not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar -czf httpdocs.tgz -C public .
|
||||||
|
scp -o StrictHostKeyChecking=no ${SSH_PRIVATE_KEY} httpdocs.tgz ${SSH_USERNAME}${DEPLOYMENT_HOST}:/tmp/httpdocs.tgz
|
||||||
|
ssh -o StrictHostKeyChecking=no ${SSH_PRIVATE_KEY} ${SSH_USERNAME}${DEPLOYMENT_HOST} "DEPLOYMENT_PATH=$DEPLOYMENT_PATH bash" << 'EOF'
|
||||||
|
cd ${DEPLOYMENT_PATH}
|
||||||
|
DATAPATH=$(cat .env | grep "NGINX_DATA" | sed "s/NGINX_DATA=//g")
|
||||||
|
rm -rf ${DATAPATH}/{*,.*}
|
||||||
|
tar xf /tmp/httpdocs.tgz -C ${DATAPATH}
|
||||||
|
docker compose restart
|
||||||
|
rm -f /tmp/httpdocs.tgz
|
||||||
|
EOF
|
||||||
|
rm -f httpdocs.tgz
|
4
makefile
4
makefile
@ -1,4 +1,5 @@
|
|||||||
#!make
|
#!make
|
||||||
|
include .vars
|
||||||
|
|
||||||
default: build
|
default: build
|
||||||
|
|
||||||
@ -8,5 +9,8 @@ prep:
|
|||||||
build: prep
|
build: prep
|
||||||
./version.sh
|
./version.sh
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
./deploy.sh
|
||||||
|
|
||||||
run: prep
|
run: prep
|
||||||
hugo server
|
hugo server
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Check if version is already provided
|
||||||
|
if [ -z "${APP_VERSION}"]; then
|
||||||
# Get version from user
|
# Get version from user
|
||||||
read -p "Version [latest]: " VERSIONINPUT
|
read -p "Version [latest]: " VERSIONINPUT
|
||||||
# If version was not provided, use the latest commit short hash as version
|
# If version was not provided, use the latest commit short hash as version
|
||||||
@ -9,6 +11,7 @@ if [ -z ${VERSIONINPUT} ]; then
|
|||||||
else
|
else
|
||||||
APP_VERSION=${VERSIONINPUT}
|
APP_VERSION=${VERSIONINPUT}
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Get project commit id and URL
|
# Get project commit id and URL
|
||||||
COMMIT_ID=$(git log HEAD --oneline | awk '{print $1}' | head -n1)
|
COMMIT_ID=$(git log HEAD --oneline | awk '{print $1}' | head -n1)
|
||||||
|
Loading…
Reference in New Issue
Block a user