100 lines
3.2 KiB
YAML
100 lines
3.2 KiB
YAML
---
|
||
# Woodpecker CI Pipeline for Trip Planner
|
||
# Builds and pushes production Docker image to Codeberg Container Registry
|
||
|
||
when:
|
||
- event: push
|
||
branch: main
|
||
|
||
variables:
|
||
- &image_repo 'codeberg.org/lvl0/trip-planner'
|
||
|
||
steps:
|
||
# Extract version from commit message if merging from release branch
|
||
- name: extract-version
|
||
image: alpine:latest
|
||
commands:
|
||
- |
|
||
# Install git and grep with PCRE support
|
||
apk add --no-cache git grep
|
||
|
||
# Get the commit message to check if it's a merge from release branch
|
||
COMMIT_MSG=$(git log -1 --pretty=%B)
|
||
|
||
# Try to extract version from merge commit message (e.g., "Merge branch 'release/v0.1.0'")
|
||
VERSION=$(echo "$COMMIT_MSG" | grep -oP "release/v?\K[0-9]+\.[0-9]+\.[0-9]+" || echo "")
|
||
|
||
if [ -z "$VERSION" ]; then
|
||
# No version found, use commit SHA as version
|
||
VERSION="dev-$(git rev-parse --short HEAD)"
|
||
echo "No release version detected, using: $VERSION"
|
||
echo "$VERSION" > /woodpecker/version.txt
|
||
else
|
||
echo "Detected release version: $VERSION"
|
||
echo "$VERSION" > /woodpecker/version.txt
|
||
# Export for use in build step
|
||
echo "export VERSION_TAG=$VERSION" >> /tmp/version_env.sh
|
||
fi
|
||
|
||
# Build and push with latest tag (always)
|
||
- name: build-and-push-latest
|
||
image: woodpeckerci/plugin-docker-buildx
|
||
settings:
|
||
repo: *image_repo
|
||
registry: codeberg.org
|
||
username:
|
||
from_secret: container_registry_username
|
||
password:
|
||
from_secret: container_registry_token
|
||
dockerfile: Dockerfile.prod
|
||
context: .
|
||
platforms: linux/amd64
|
||
build_args:
|
||
- BUILDKIT_INLINE_CACHE=1
|
||
auto_tag: false
|
||
tags:
|
||
- latest
|
||
depends_on:
|
||
- extract-version
|
||
|
||
# Check if this is a release build
|
||
- name: check-release
|
||
image: alpine:latest
|
||
commands:
|
||
- |
|
||
VERSION=$(cat /woodpecker/version.txt)
|
||
if echo "$VERSION" | grep -qv "^dev-"; then
|
||
echo "Release version detected: $VERSION"
|
||
echo "true" > /woodpecker/is_release.txt
|
||
else
|
||
echo "Development build ($VERSION), will skip version tag"
|
||
echo "false" > /woodpecker/is_release.txt
|
||
fi
|
||
depends_on:
|
||
- build-and-push-latest
|
||
|
||
# Notify build status
|
||
- name: notify-success
|
||
image: alpine:latest
|
||
commands:
|
||
- |
|
||
VERSION=$(cat /woodpecker/version.txt 2>/dev/null || echo "unknown")
|
||
IS_RELEASE=$(cat /woodpecker/is_release.txt 2>/dev/null || echo "false")
|
||
echo "✅ Successfully built and pushed trip-planner:latest"
|
||
echo "Version: $VERSION"
|
||
if [ "$IS_RELEASE" = "true" ]; then
|
||
echo "ℹ️ This is a release build. To tag with version $VERSION:"
|
||
echo " docker pull codeberg.org/lvl0/trip-planner:latest"
|
||
echo " docker tag codeberg.org/lvl0/trip-planner:latest codeberg.org/lvl0/trip-planner:$VERSION"
|
||
echo " docker push codeberg.org/lvl0/trip-planner:$VERSION"
|
||
fi
|
||
echo "Image: codeberg.org/lvl0/trip-planner:latest"
|
||
when:
|
||
status: success
|
||
|
||
- name: notify-failure
|
||
image: alpine:latest
|
||
commands:
|
||
- echo "❌ Build failed! Check the logs above for details."
|
||
when:
|
||
status: failure
|