You've already forked pedini.dev
Compare commits
5 Commits
126bd66ddb
...
9463c44034
| Author | SHA1 | Date | |
|---|---|---|---|
| 9463c44034 | |||
| b7286eeeb6 | |||
| 9a4bdf15a3 | |||
| fafafb0d37 | |||
| d0189c57a5 |
@@ -1,11 +1,13 @@
|
|||||||
---
|
---
|
||||||
name: Deploy website on production server when committing on main
|
name: Deploy website on production server when committing on main
|
||||||
concurrency: 1
|
concurrency:
|
||||||
|
group: deploy-website
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
tags:
|
||||||
- main
|
- '*'
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
@@ -15,8 +17,6 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: echo "${{ secrets.SSH_PRIVATE_KEY }}" > /private.key
|
|
||||||
- run: chmod 600 /private.key
|
|
||||||
- run: |
|
- run: |
|
||||||
export HUGO_VERSION=$(curl --silent -I https://github.com/gohugoio/hugo/releases/latest | grep location | sed 's|.*tag/||' | tr -d '\r')
|
export HUGO_VERSION=$(curl --silent -I https://github.com/gohugoio/hugo/releases/latest | grep location | sed 's|.*tag/||' | tr -d '\r')
|
||||||
export HUGO_VERSION_SHORT=$(echo ${HUGO_VERSION} | sed 's/v//')
|
export HUGO_VERSION_SHORT=$(echo ${HUGO_VERSION} | sed 's/v//')
|
||||||
@@ -25,10 +25,17 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- run: APP_VERSION=latest make
|
|
||||||
- run: |
|
- run: |
|
||||||
export SSH_PRIVATE_KEY=/private.key
|
mkdir -p ~/.ssh/
|
||||||
export SSH_USERNAME=${{ secrets.SSH_USERNAME }}
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||||
export DEPLOYMENT_HOST=${{ secrets.DEPLOYMENT_HOST }}
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
export DEPLOYMENT_PATH=${{ secrets.DEPLOYMENT_PATH }}
|
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
||||||
|
make
|
||||||
make deploy
|
make deploy
|
||||||
|
env:
|
||||||
|
SSH_USERNAME: ${{ vars.SSH_USERNAME }}
|
||||||
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
SSH_KNOWN_HOSTS: ${{ vars.SSH_KNOWN_HOSTS }}
|
||||||
|
DEPLOYMENT_HOST: ${{ vars.DEPLOYMENT_HOST }}
|
||||||
|
DEPLOYMENT_PATH: ${{ vars.DEPLOYMENT_PATH }}
|
||||||
|
APP_VERSION: ${{ vars.GITHUB_REF_NAME }}
|
||||||
|
|||||||
14
deploy.sh
14
deploy.sh
@@ -5,7 +5,6 @@ set -e
|
|||||||
# FLOW
|
# 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 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
|
# 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
|
# tarball the built website and scp it to the deployment host
|
||||||
@@ -13,11 +12,6 @@ set -e
|
|||||||
# then remove everything in the data path, untar the tarball and reload the server
|
# 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)
|
# 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
|
# Check if the username variable is set
|
||||||
if [ ! -z "${SSH_USERNAME}" ]; then
|
if [ ! -z "${SSH_USERNAME}" ]; then
|
||||||
SSH_USERNAME="${SSH_USERNAME}@"
|
SSH_USERNAME="${SSH_USERNAME}@"
|
||||||
@@ -29,14 +23,16 @@ if [ -z "${DEPLOYMENT_HOST}" ] || [ -z "${DEPLOYMENT_PATH}" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Compress the built website and scp it to the remote host
|
||||||
tar -czf httpdocs.tgz -C public .
|
tar -czf httpdocs.tgz -C public .
|
||||||
scp -o StrictHostKeyChecking=no ${SSH_PRIVATE_KEY} httpdocs.tgz ${SSH_USERNAME}${DEPLOYMENT_HOST}:/tmp/httpdocs.tgz
|
scp ${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'
|
|
||||||
|
# SSH to the remote host, cd to the deployment path, and deploy the website (delete and overwrite everything)
|
||||||
|
ssh ${SSH_PRIVATE_KEY} ${SSH_USERNAME}${DEPLOYMENT_HOST} "DEPLOYMENT_PATH=$DEPLOYMENT_PATH bash" << 'EOF'
|
||||||
cd ${DEPLOYMENT_PATH}
|
cd ${DEPLOYMENT_PATH}
|
||||||
DATAPATH=$(cat .env | grep "NGINX_DATA" | sed "s/NGINX_DATA=//g")
|
DATAPATH=$(cat .env | grep "NGINX_DATA" | sed "s/NGINX_DATA=//g")
|
||||||
rm -rf ${DATAPATH}/{*,.*}
|
rm -rf ${DATAPATH}/{*,.*}
|
||||||
tar xf /tmp/httpdocs.tgz -C ${DATAPATH}
|
tar xf /tmp/httpdocs.tgz -C ${DATAPATH}
|
||||||
docker compose restart
|
|
||||||
rm -f /tmp/httpdocs.tgz
|
rm -f /tmp/httpdocs.tgz
|
||||||
EOF
|
EOF
|
||||||
rm -f httpdocs.tgz
|
rm -f httpdocs.tgz
|
||||||
|
|||||||
4
makefile
4
makefile
@@ -7,10 +7,10 @@ prep:
|
|||||||
git submodule foreach --recursive bash -c "git checkout \$$(git remote show origin | grep HEAD | sed 's/.*\: //'); git pull"
|
git submodule foreach --recursive bash -c "git checkout \$$(git remote show origin | grep HEAD | sed 's/.*\: //'); git pull"
|
||||||
|
|
||||||
build: prep
|
build: prep
|
||||||
./version.sh
|
/usr/bin/env bash version.sh
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
./deploy.sh
|
/usr/bin/env bash deploy.sh
|
||||||
|
|
||||||
run: prep
|
run: prep
|
||||||
hugo server
|
hugo server
|
||||||
|
|||||||
Reference in New Issue
Block a user