Features: - Parse and compare semantic versions from Docker Hub - Check if current version is outdated on startup - Only pull updates when newer version is available - GitLab CI now tags images with Cargo.toml version - Created bump-version.sh script for easy version bumping How it works: 1. Cargo.toml contains source of truth version (0.1.0) 2. GitLab CI extracts version and tags Docker images with it 3. Agent queries Docker Hub for all semver tags 4. Compares current version against latest available 5. Only pulls and restarts if newer version exists Version bumping workflow: ./scripts/bump-version.sh patch # 0.1.0 -> 0.1.1 ./scripts/bump-version.sh minor # 0.1.0 -> 0.2.0 ./scripts/bump-version.sh major # 0.1.0 -> 1.0.0 This creates git commit and tag, ready to push.
122 lines
3.5 KiB
YAML
122 lines
3.5 KiB
YAML
# GitLab CI/CD Configuration for Towerops Agent
|
|
# Builds and publishes Docker image to Docker Hub
|
|
|
|
stages:
|
|
- test
|
|
- build
|
|
- release
|
|
|
|
variables:
|
|
# Docker Hub Registry
|
|
REGISTRY: docker.io
|
|
IMAGE_NAME: gmcintire/towerops-agent
|
|
# Docker BuildKit for better caching
|
|
DOCKER_BUILDKIT: 1
|
|
# Disable TLS for buildx compatibility
|
|
DOCKER_TLS_CERTDIR: ""
|
|
|
|
# Test stage - compile and check code
|
|
test:
|
|
stage: test
|
|
image: rust:1.83-alpine
|
|
before_script:
|
|
- apk add --no-cache musl-dev protobuf-dev
|
|
- rustup component add rustfmt clippy
|
|
script:
|
|
- cargo check --release
|
|
- cargo fmt -- --check
|
|
- cargo clippy -- -D warnings
|
|
only:
|
|
- branches
|
|
- merge_requests
|
|
cache:
|
|
key: ${CI_COMMIT_REF_SLUG}-cargo
|
|
paths:
|
|
- target/
|
|
|
|
# Build Docker image for branches (test build)
|
|
build:test:
|
|
stage: build
|
|
image: docker:24-dind
|
|
services:
|
|
- docker:24-dind
|
|
before_script:
|
|
- docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN
|
|
script:
|
|
- |
|
|
docker build \
|
|
--tag $REGISTRY/$IMAGE_NAME:$CI_COMMIT_REF_SLUG \
|
|
--tag $REGISTRY/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA \
|
|
.
|
|
- docker push $REGISTRY/$IMAGE_NAME:$CI_COMMIT_REF_SLUG
|
|
- docker push $REGISTRY/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA
|
|
only:
|
|
- branches
|
|
except:
|
|
- main
|
|
- tags
|
|
|
|
# Build and push for main branch (amd64 only for speed)
|
|
build:main:
|
|
stage: build
|
|
image: docker:24-dind
|
|
services:
|
|
- docker:24-dind
|
|
before_script:
|
|
- echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
|
|
- docker buildx create --driver docker-container --name builder --use || docker buildx use builder
|
|
- docker buildx inspect --bootstrap
|
|
# Extract version from Cargo.toml
|
|
- apk add --no-cache grep sed
|
|
- VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
|
|
- echo "Building version $VERSION"
|
|
script:
|
|
- |
|
|
docker buildx build \
|
|
--platform linux/amd64 \
|
|
--cache-from type=registry,ref=$REGISTRY/$IMAGE_NAME:buildcache \
|
|
--cache-to type=registry,ref=$REGISTRY/$IMAGE_NAME:buildcache,mode=max \
|
|
--tag $REGISTRY/$IMAGE_NAME:latest \
|
|
--tag $REGISTRY/$IMAGE_NAME:$VERSION \
|
|
--tag $REGISTRY/$IMAGE_NAME:main-$CI_COMMIT_SHORT_SHA \
|
|
--push \
|
|
.
|
|
- echo "IMAGE_TAG=$VERSION" >> build.env
|
|
artifacts:
|
|
reports:
|
|
dotenv: build.env
|
|
only:
|
|
- main
|
|
|
|
# Release build for tags (multi-architecture with caching)
|
|
# Note: Multi-arch builds are slow (~15-20 min) due to QEMU emulation for ARM64
|
|
release:multiarch:
|
|
stage: release
|
|
image: docker:24-dind
|
|
services:
|
|
- docker:24-dind
|
|
before_script:
|
|
- echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
|
|
- docker buildx create --driver docker-container --name multiarch-builder --use || docker buildx use multiarch-builder
|
|
- docker buildx inspect --bootstrap
|
|
script:
|
|
- |
|
|
VERSION=${CI_COMMIT_TAG#v}
|
|
|
|
docker buildx build \
|
|
--platform linux/amd64,linux/arm64 \
|
|
--cache-from type=registry,ref=$REGISTRY/$IMAGE_NAME:buildcache \
|
|
--cache-to type=registry,ref=$REGISTRY/$IMAGE_NAME:buildcache,mode=max \
|
|
--tag $REGISTRY/$IMAGE_NAME:$VERSION \
|
|
--tag $REGISTRY/$IMAGE_NAME:$CI_COMMIT_TAG \
|
|
--tag $REGISTRY/$IMAGE_NAME:latest \
|
|
--push \
|
|
.
|
|
|
|
echo "Released version: $VERSION"
|
|
echo "IMAGE_TAG=$VERSION" >> release.env
|
|
artifacts:
|
|
reports:
|
|
dotenv: release.env
|
|
only:
|
|
- tags
|