rework: deployment workflow
All checks were successful
Staging Blog Deployment / check-hugo-version (push) Successful in 3s
Staging Blog Deployment / build (push) Has been skipped
Staging Blog Deployment / deploy (push) Successful in 9s
Staging Blog Deployment / test (push) Successful in 3s
Staging Blog Deployment / merge (push) Successful in 5s
Staging Blog Deployment / clean (push) Has been skipped

This commit is contained in:
Vezpi 2025-06-04 19:40:36 +00:00
parent e835486965
commit 041ed1fe42
3 changed files with 176 additions and 45 deletions

View File

@ -1,45 +0,0 @@
name: Deploy
on: [push]
jobs:
Deploy:
runs-on: ubuntu
env:
BLOG_FOLDER: /blog
container:
volumes:
- /appli/data/blog:/blog
steps:
- name: Check out repository
run: |
cd ${BLOG_FOLDER}
git config --global user.name "Gitea Actions"
git config --global user.email "actions@local"
git config --global --add safe.directory ${BLOG_FOLDER}
git submodule update --init --recursive
git fetch origin
git reset --hard origin/main
- name: Get current Hugo version
run: |
current_version=$(${BLOG_FOLDER}/hugo version | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+')
echo "current_version=$current_version" | tee -a $GITEA_ENV
- name: Verify latest Hugo version
run: |
latest_version=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep -oP '"tag_name": "\K[^"]+')
echo "latest_version=$latest_version" | tee -a $GITEA_ENV
- name: Download latest Hugo version
if: env.current_version != env.latest_version
run: |
rm -f ${BLOG_FOLDER}/{LICENSE,README.md,hugo}
curl -L https://github.com/gohugoio/hugo/releases/download/$latest_version/hugo_extended_${latest_version#v}_Linux-64bit.tar.gz -o hugo.tar.gz
tar -xzvf hugo.tar.gz -C ${BLOG_FOLDER}/
- name: Generate the static files with Hugo
run: |
rm -f ${BLOG_FOLDER}/content/posts/template.md
rm -rf ${BLOG_FOLDER}/private/* ${BLOG_FOLDER}/public/*
${BLOG_FOLDER}/hugo -D -b https://blog-dev.vezpi.com -s ${BLOG_FOLDER} -d ${BLOG_FOLDER}/private
${BLOG_FOLDER}/hugo -s ${BLOG_FOLDER} -d ${BLOG_FOLDER}/public
chown 1000:1000 -R ${BLOG_FOLDER}

View File

@ -0,0 +1,45 @@
name: Production Blog Deployment
on:
push:
branches:
- main
env:
CONTAINER_NAME: blog_production
URL: "https://blog.vezpi.com/en/"
jobs:
deploy:
runs-on: docker
container:
volumes:
- /appli/docker/blog:/blog
defaults:
run:
shell: sh
steps:
- name: Restart ${CONTAINER_NAME} container
run: |
cd /blog
docker compose down ${CONTAINER_NAME}
docker compose up -d ${CONTAINER_NAME}
sleep 5
echo "- Displaying container logs"
docker compose logs ${CONTAINER_NAME}
test:
needs: deploy
runs-on: ubuntu
steps:
- name: Check HTTP response
run: |
code=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
echo "HTTP response code: $code"
if [ "$code" -ne 200 ]; then
echo "❌ Service is not healthy (HTTP $code)"
exit 1
else
echo "✅ Service is healthy"
fi

View File

@ -0,0 +1,131 @@
name: Staging Blog Deployment
on:
push:
branches:
- preview
env:
DOCKER_IMAGE: vezpi-blog
CONTAINER_NAME: blog_staging
URL: "https://blog-dev.vezpi.com/en/"
jobs:
check-hugo-version:
runs-on: docker
defaults:
run:
shell: sh
outputs:
latest_hugo_version: ${{ steps.get_latest.outputs.version }}
current_hugo_version: ${{ steps.get_current.outputs.version }}
newer_version_available: ${{ steps.compare.outputs.version }}
steps:
- name: Check latest Hugo version
id: get_latest
run: |
apk add curl
latest_version=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep tag_name | sed -E 's/.*"v([^"]+)".*/\1/')
echo "version=$latest_version" | tee -a $GITEA_OUTPUT
- name: Check current Hugo version
id: get_current
run: |
current_version=$(docker image ls ${DOCKER_IMAGE} --format '{{.Tag}}' | head -n1)
echo "version=$current_version" | tee -a $GITEA_OUTPUT
- name: Compare current and latest Hugo versions
id: compare
run: |
if [ "${{ steps.get_latest.outputs.version }}" != "${{ steps.get_current.outputs.version }}" ]; then
new_version_available=true
echo "New version available: ${{ steps.get_latest.outputs.version }}"
else
new_version_available=false
echo "Current version is the latest: ${{ steps.get_latest.outputs.version }}"
fi
echo "version=$new_version_available" | tee -a $GITEA_OUTPUT
build:
needs: check-hugo-version
if: needs.check-hugo-version.outputs.newer_version_available == 'true'
runs-on: docker
defaults:
run:
shell: sh
steps:
- name: Checkout repository
run: git clone --branch preview https://${{ secrets.REPO_TOKEN }}@git.vezpi.me/Vezpi/blog.git .
- name: Build Docker Image
run: |
cd docker
docker build \
--build-arg HUGO_VERSION=${{ needs.check-hugo-version.outputs.latest_hugo_version }} \
--tag ${DOCKER_IMAGE}:${{ needs.check-hugo-version.outputs.latest_hugo_version }} \
.
docker tag ${DOCKER_IMAGE}:${{ needs.check-hugo-version.outputs.latest_hugo_version }} ${DOCKER_IMAGE}:latest
deploy:
needs:
- check-hugo-version
- build
if: always() && needs.check-hugo-version.result == 'success' && (needs.build.result == 'skipped' || needs.build.result == 'success')
runs-on: docker
container:
volumes:
- /appli/docker/blog:/blog
defaults:
run:
shell: sh
steps:
- name: Restart ${CONTAINER_NAME} container
run: |
cd /blog
docker compose down ${CONTAINER_NAME}
docker compose up -d ${CONTAINER_NAME}
sleep 5
echo "- Displaying container logs"
docker compose logs ${CONTAINER_NAME}
test:
needs: deploy
runs-on: ubuntu
steps:
- name: Check HTTP response
run: |
code=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
echo "HTTP response code: $code"
if [ "$code" -ne 200 ]; then
echo "❌ Service is not healthy (HTTP $code)"
exit 1
else
echo "✅ Service is healthy"
fi
merge:
needs: test
runs-on: ubuntu
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Merge preview branch on main
run: |
git merge --ff-only origin/preview
git push origin main
clean:
needs:
- check-hugo-version
- build
- merge
runs-on: docker
defaults:
run:
shell: sh
steps:
- name: Checkout repository
run: docker image rm vezpi-blog:${{ needs.check-hugo-version.outputs.current_hugo_version }} --force