feat(ci): add Docker image build and release workflow
Integration Tests / integration-test (push) Failing after 1m36s
Integration Tests / integration-test (push) Failing after 1m36s
* Implement GitHub Actions workflow for Docker image build and release * Validate release tags and manage Docker login credentials * Build and push Docker images with versioning and metadata * Add docker-build target to Makefile for local image building
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
name: Build & Release Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Existing tag to release (e.g. v0.1.0)'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
env:
|
||||
IMAGE: git.warky.dev/wdevs/pgsql-broker
|
||||
TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
|
||||
steps:
|
||||
- name: Validate release tag
|
||||
run: |
|
||||
case "$TAG" in
|
||||
v*) ;;
|
||||
*) echo "Release tags must start with v (received: $TAG)" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Verify package registry credentials
|
||||
env:
|
||||
PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
|
||||
PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
|
||||
run: |
|
||||
test -n "$PACKAGE_REGISTRY_USERNAME" || {
|
||||
echo 'PACKAGE_REGISTRY_USERNAME is required to publish the Docker image.' >&2
|
||||
exit 1
|
||||
}
|
||||
test -n "$PACKAGE_REGISTRY_TOKEN" || {
|
||||
echo 'PACKAGE_REGISTRY_TOKEN is required to publish the Docker image.' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Log in to the Warky container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.warky.dev
|
||||
username: ${{ secrets.PACKAGE_REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.PACKAGE_REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and push image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
push: true
|
||||
build-args: |
|
||||
VERSION=${{ env.TAG }}
|
||||
COMMIT=${{ github.sha }}
|
||||
BUILD_TIME=${{ github.event.head_commit.timestamp || github.event.repository.updated_at }}
|
||||
tags: |
|
||||
${{ env.IMAGE }}:${{ env.TAG }}
|
||||
${{ env.IMAGE }}:latest
|
||||
labels: |
|
||||
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
org.opencontainers.image.version=${{ env.TAG }}
|
||||
@@ -1,4 +1,4 @@
|
||||
.PHONY: all build clean test test-all test-integration-go test-unit-go test-connection schema-install broker-start broker-stop install deps docker-up docker-down help
|
||||
.PHONY: all build clean test test-all test-integration-go test-unit-go test-connection schema-install broker-start broker-stop install deps docker-up docker-down docker-build release help
|
||||
|
||||
# Build variables
|
||||
BINARY_NAME=pgsql-broker
|
||||
@@ -32,7 +32,7 @@ COMPOSE_CMD := $(shell \
|
||||
|
||||
# Version information
|
||||
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||
BUILD_TIME=$(shell date -u '+2026-01-02_19:58:30')
|
||||
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
||||
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
||||
|
||||
# Inject version info
|
||||
@@ -73,14 +73,22 @@ schema-install: build ## Install database schema using the broker CLI
|
||||
@echo "Installing database schema..."
|
||||
@$(BIN_DIR)/$(BINARY_NAME) install --config broker.test.yaml
|
||||
|
||||
test-setup: build ## Start test environment (docker-compose)
|
||||
@echo "Starting test environment..."
|
||||
@podman-compose -f tests/docker-compose.yml up -d
|
||||
test-setup: build ## Start test environment (docker-compose/podman-compose)
|
||||
@echo "Starting test environment (using $(COMPOSE_CMD))..."
|
||||
@if [ "$(CONTAINER_RUNTIME)" = "none" ]; then \
|
||||
echo "Error: Neither Docker nor Podman is installed"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@$(COMPOSE_CMD) -f tests/docker-compose.yml up -d
|
||||
|
||||
test-teardown: ## Stop test environment (docker-compose)
|
||||
@echo "Stopping test environment..."
|
||||
@podman-compose -f tests/docker-compose.yml down -v --rmi all
|
||||
@sleep 5 # Give Docker time to release resources
|
||||
test-teardown: ## Stop test environment (docker-compose/podman-compose)
|
||||
@echo "Stopping test environment (using $(COMPOSE_CMD))..."
|
||||
@if [ "$(CONTAINER_RUNTIME)" = "none" ]; then \
|
||||
echo "Neither Docker nor Podman is installed, skipping teardown"; \
|
||||
else \
|
||||
$(COMPOSE_CMD) -f tests/docker-compose.yml down -v --rmi all || true; \
|
||||
fi
|
||||
@sleep 5 # Give the container runtime time to release resources
|
||||
|
||||
broker-start: build ## Start the broker in the background
|
||||
@echo "Starting broker..."
|
||||
@@ -172,6 +180,15 @@ docker-down: ## Stop PostgreSQL test database
|
||||
fi
|
||||
@echo "PostgreSQL stopped"
|
||||
|
||||
docker-build: ## Build the pgsql-broker runtime image
|
||||
@if [ "$(CONTAINER_RUNTIME)" = "none" ]; then echo "Error: Neither Docker nor Podman is installed"; exit 1; fi
|
||||
@$(CONTAINER_RUNTIME) build \
|
||||
--build-arg VERSION=$(VERSION) \
|
||||
--build-arg COMMIT=$(COMMIT) \
|
||||
--build-arg BUILD_TIME=$(BUILD_TIME) \
|
||||
-t pgsql-broker:$(VERSION) -t pgsql-broker:latest \
|
||||
-f Dockerfile .
|
||||
|
||||
release: ## Create and push a new release tag (auto-increments patch version)
|
||||
@echo "Creating new release..."
|
||||
@latest_tag=$$(git describe --tags --abbrev=0 2>/dev/null || echo ""); \
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"git.warky.dev/wdevs/pgsql-broker/pkg/broker/adapter"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// Config holds all broker configuration
|
||||
|
||||
@@ -326,7 +326,7 @@ func execStatements(ctx context.Context, tx adapter.DBTransaction, sqlText strin
|
||||
// $$-quoted function bodies intact.
|
||||
// splitSQLStatements splits a SQL script into individual statements on
|
||||
// top-level semicolons, ignoring semicolons that appear inside single-quoted
|
||||
// strings ('...', with '' as an escaped quote), double-quoted identifiers,
|
||||
// strings ('...', with ” as an escaped quote), double-quoted identifiers,
|
||||
// line comments (--), and dollar-quoted bodies ($$...$$ or $tag$...$tag$).
|
||||
func splitSQLStatements(sqlText string) []string {
|
||||
var result []string
|
||||
|
||||
Reference in New Issue
Block a user