Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI deb release #79

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
9 changes: 6 additions & 3 deletions .github/workflows/publish-pg_tracing-pgxn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Bundle the Release
run: make dist

- id: dist
name: Bundle the Release
run: make dist >> "$GITHUB_OUTPUT"

- name: Release on PGXN
env:
PGXN_USERNAME: ${{ secrets.PGXN_USERNAME }}
PGXN_PASSWORD: ${{ secrets.PGXN_PASSWORD }}
run: pgxn-release
run: pgxn-release ${{ steps.dist.outputs.artifact }}
5 changes: 1 addition & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
with:
fetch-depth: 0

- name: Set environment variables
run: echo "PG_VERSION=${{ matrix.PG_VERSION }}" >> $GITHUB_ENV

- name: Add gcc problem matcher
run: echo "::add-matcher::matcher.json"

Expand Down Expand Up @@ -56,4 +53,4 @@ jobs:

- name: Run Test
timeout-minutes: 1
run: make run-test
run: PG_VERSION=${{ matrix.PG_VERSION }} make run-test
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ARG PG_VERSION=16

FROM ubuntu:jammy AS base

ARG PG_VERSION
Expand All @@ -10,6 +8,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
ca-certificates curl gnupg make sudo gcc \
&& rm -rf /var/lib/apt/lists/*

# Install PostgreSQL
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

RUN echo "deb http://apt.postgresql.org/pub/repos/apt jammy-pgdg main ${PG_VERSION}" > /etc/apt/sources.list.d/pgdg.list
Expand All @@ -36,28 +35,36 @@ RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
FROM base AS build

ARG PG_VERSION
ENV PG_CONFIG=/usr/lib/postgresql/${PG_VERSION}/bin/pg_config
USER postgres

WORKDIR /usr/src/pg_tracing

RUN mkdir src

# Copy sources and compile
COPY --chown=postgres common.mk ./
COPY --chown=postgres Makefile ./
COPY --chown=postgres typedefs.list ./
COPY --chown=postgres pg_tracing--0.1.0.sql pg_tracing.control ./
COPY --chown=postgres ./src/ ./src
COPY --chown=postgres *.sql ./
COPY --chown=postgres pg_tracing.control ./
COPY --chown=postgres ./src/*.c ./src
COPY --chown=postgres ./src/*.h ./src
COPY --chown=postgres pg_tracing.conf ./pg_tracing.conf

# Tests
# Copy test files
COPY --chown=postgres ./sql/ ./sql
COPY --chown=postgres ./t/ ./t
COPY --chown=postgres ./regress/ ./regress
COPY --chown=postgres ./expected/ ./expected

# Create empty results for mount bind
# Used to copy test results and update expected output
RUN mkdir results
RUN chown postgres:postgres results

RUN make -s clean
# Compile
RUN make -s
# And install
RUN sudo make -s install -j8

# Create test cluster
Expand Down
58 changes: 14 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
# Supported PostgreSQL versions:
PG_VERSIONS = 14 15 16 17 18

MODULE_big = pg_tracing
EXTENSION = pg_tracing
DATA = pg_tracing--0.1.0.sql
PGFILEDESC = "pg_tracing - Distributed Tracing for PostgreSQL"
PG_CONFIG = pg_config
SHLIB_LINK = -lcurl

PG_CONFIG_EXISTS := $(shell command -v $(PG_CONFIG) 2> /dev/null)
GIT_EXISTS := $(shell command -v git 2> /dev/null)
PG_CFLAGS = -Werror

# Prepare the package for PGXN submission
ifdef GIT_EXISTS
EXTVERSION = $(shell git describe --tags | sed 's/^v//')
else
EXTVERSION = "0.1"
endif

ifdef PG_CONFIG_EXISTS
# Default to pg_config's advertised version
PG_VERSION ?= $(shell $(PG_CONFIG) --version | cut -d' ' -f2 | cut -d'.' -f1 | tr -d 'devel')
else
# pg_config is not present, let's assume we are packaging and use the latest PG version
PG_VERSION ?= $(lastword $(PG_VERSIONS))
endif
include common.mk

OBJS = \
$(WIN32RES) \
Expand Down Expand Up @@ -53,8 +32,6 @@ PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
endif

EXTRA_CLEAN = META.json $(EXTENSION)-$(EXTVERSION).zip

REGRESSCHECKS = setup utility select parameters insert trigger cursor json transaction planstate_projectset

REGRESSCHECKS_OPTS = --no-locale --encoding=UTF8 --temp-config pg_tracing.conf
Expand Down Expand Up @@ -100,39 +77,33 @@ pgindent: typedefs.list
pgindent --typedefs=typedefs.list src/*.c src/*.h

# DOCKER BUILDS
TEST_CONTAINER_NAME = pg_tracing_test_$(PG_VERSION)
BUILD_TEST_TARGETS = $(patsubst %,build-test-pg%,$(PG_VERSIONS))
TEST_CONTAINER_NAME = pg_tracing_test_$(PG_VERSION)
BUILD_TEST_TARGETS = $(patsubst %,build-test-pg%,$(PG_VERSIONS))
DOCKER_RUN_OPTS = --name $(TEST_CONTAINER_NAME) $(TEST_CONTAINER_NAME):pg$(PG_VERSION)

.PHONY: build-test-image
build-test-image: build-test-pg$(PG_VERSION) ;

.PHONY: $(BUILD_TEST_TARGETS)
$(BUILD_TEST_TARGETS):
docker buildx build --load \
$(DOCKER_BUILD_OPTS) \
--build-arg PG_VERSION=$(PG_VERSION) \
-t $(TEST_CONTAINER_NAME):$(subst build-test-,,$@) .
--rm --build-arg PG_VERSION=$(PG_VERSION) \
-t $(TEST_CONTAINER_NAME):$(subst build-test-,,$@) .

.PHONY: run-test
run-test: build-test-pg$(PG_VERSION)
docker run \
--name $(TEST_CONTAINER_NAME) --rm \
$(TEST_CONTAINER_NAME):pg$(PG_VERSION) \
docker run $(DOCKER_RUN_OPTS) \
bash -c "make regresscheck_noinstall && make installcheck"

.PHONY: run-pgindent-diff
run-pgindent-diff: build-test-pg$(PG_VERSION)
docker run \
--name $(TEST_CONTAINER_NAME) --rm \
$(TEST_CONTAINER_NAME):pg$(PG_VERSION) \
docker run $(DOCKER_RUN_OPTS) \
bash -c "pgindent --diff --check --typedefs=typedefs.list src/*.c src/*.h"

.PHONY: update-regress-output
update-regress-output: build-test-pg$(PG_VERSION)
docker run \
--name $(TEST_CONTAINER_NAME) --rm \
docker run $(DOCKER_RUN_OPTS) \
-v./results:/usr/src/pg_tracing/results \
$(TEST_CONTAINER_NAME):pg$(PG_VERSION) \
bash -c "make regresscheck_noinstall || true"
@if [ $(PG_VERSION) = "15" ]; then \
cp results/*.out expected/; \
Expand All @@ -148,10 +119,9 @@ update-regress-output-local: regresscheck
cp results/*.out regress/$(PG_VERSION)/expected; \
fi

META.json: META.json.in
@sed "s/@PG_TRACING_VERSION@/$(EXTVERSION)/g" $< > $@

$(EXTENSION)-$(EXTVERSION).zip: META.json
git archive --format zip --prefix "$(EXTENSION)-$(EXTVERSION)/" --add-file $< -o "$(EXTENSION)-$(EXTVERSION).zip" HEAD
.PHONY: dist packages
dist:
@make -f Makefile.dist

dist: $(EXTENSION)-$(EXTVERSION).zip
packages:
@make -C packages
14 changes: 14 additions & 0 deletions Makefile.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include common.mk

default: dist

# pgxn packaging
$(TMP_DIR)/META.json: META.json.in
@mkdir -p $(TMP_DIR)
@sed "s/@PG_TRACING_VERSION@/$(EXT_VERSION)/g" $< > $@

$(TMP_DIR)/$(EXTENSION)-$(EXT_VERSION).zip: $(TMP_DIR)/META.json
@git archive --format zip --prefix "$(EXTENSION)-$(EXT_VERSION)/" --add-file $< -o "$(TMP_DIR)/$(EXTENSION)-$(EXT_VERSION).zip" HEAD
@echo "artifact=$(TMP_DIR)/$(EXTENSION)-$(EXT_VERSION).zip"

dist: $(TMP_DIR)/$(EXTENSION)-$(EXT_VERSION).zip
27 changes: 27 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Supported PostgreSQL versions:
PG_VERSIONS = 14 15 16 17 18

EXTENSION = pg_tracing
PG_CONFIG = pg_config

# Get postgres version
PG_CONFIG_EXISTS := $(shell command -v $(PG_CONFIG) 2> /dev/null)
ifdef PG_CONFIG_EXISTS
# Default to pg_config's advertised version
PG_VERSION ?= $(shell $(PG_CONFIG) --version | cut -d' ' -f2 | cut -d'.' -f1 | tr -d 'devel')
else
# pg_config is not present, let's assume we are packaging and use the latest PG version
PG_VERSION ?= $(lastword $(PG_VERSIONS))
endif

# Get extension version
GIT_EXISTS := $(shell command -v git 2> /dev/null)
ifdef GIT_EXISTS
EXT_VERSION = $(shell git describe --tags | sed 's/^v//')
else
EXT_VERSION = "0.1.0"
endif

TMP_DIR=tmp

EXTRA_CLEAN = META.json $(TMP_DIR)
26 changes: 26 additions & 0 deletions packages/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include ../common.mk

BUILD_CONTAINER_NAME = pg_tracing_build
DOCKER_BUILD_OPTS = --rm --build-arg PG_VERSION=$(PG_VERSION) --build-arg EXT_VERSION=$(EXT_VERSION)

DEB_PACKAGE_X86_64=$(EXTENSION)_$(PG_VERSION)_$(EXT_VERSION)_amd64.deb
DEB_PACKAGE_ARM64=$(EXTENSION)_$(PG_VERSION)_$(EXT_VERSION)_arm64.deb

IMAGE_NAME_AMD64 = $(BUILD_CONTAINER_NAME):pg_$(PG_VERSION)_amd64
IMAGE_NAME_ARM64 = $(BUILD_CONTAINER_NAME):pg_$(PG_VERSION)_arm64

.PHONY: all

all: $(TMP_DIR)/$(DEB_PACKAGE_X86_64) $(TMP_DIR)/$(DEB_PACKAGE_ARM64)

$(TMP_DIR)/$(DEB_PACKAGE_X86_64):
docker build -t $(IMAGE_NAME_AMD64) \
--platform linux/amd64 $(DOCKER_BUILD_OPTS) -f deb.Dockerfile ..
docker run $(IMAGE_NAME_AMD64) \
--platform linux/amd64 -v $(TMP_DIR):/out bash -c "cp /usr/src/pg_tracing/$(DEB_PACKAGE_X86_64) /out"

$(TMP_DIR)/$(DEB_PACKAGE_ARM64):
docker build -t $(IMAGE_NAME_AMD64) \
--platform linux/arm64 $(DOCKER_BUILD_OPTS) -f deb.Dockerfile ..
docker run $(IMAGE_NAME_ARM64) \
--platform linux/arm64 -v $(TMP_DIR):/out bash -c "cp /usr/src/pg_tracing/$(DEB_PACKAGE_ARM64) /out"
63 changes: 63 additions & 0 deletions packages/deb.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
FROM ubuntu:jammy AS base

ARG PG_VERSION
# Install packages
RUN apt update
RUN DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
ca-certificates curl gnupg make gcc ruby libcurl4-gnutls-dev \
&& rm -rf /var/lib/apt/lists/*

# Install PostgreSQL
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt jammy-pgdg main ${PG_VERSION}" > /etc/apt/sources.list.d/pgdg.list
RUN apt update \
&& DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
postgresql-server-dev-${PG_VERSION} && rm -rf /var/lib/apt/lists/*

# Install FPM
RUN gem install fpm

# Build pg_tracing for a given --build-arg PG_VERSION target version of
# PostgreSQL.
FROM base AS build

ARG PG_VERSION
ARG EXT_VERSION
ENV LIB_DIR usr/lib/postgresql/${PG_VERSION}/lib/
ENV SHARE_DIR usr/share/postgresql/${PG_VERSION}/extension
USER postgres

WORKDIR /usr/src/pg_tracing

RUN mkdir src

# Copy sources and compile
COPY --chown=postgres common.mk ./
COPY --chown=postgres Makefile ./
COPY --chown=postgres *.sql ./
COPY --chown=postgres pg_tracing.control ./
COPY --chown=postgres ./src/*.c ./src
COPY --chown=postgres ./src/*.h ./src
COPY --chown=postgres pg_tracing.conf ./pg_tracing.conf

# Compile
RUN make -s

# Prepare package directories
RUN mkdir -p ${LIB_DIR}
RUN mkdir -p ${SHARE_DIR}

# Copy package files
RUN cp pg_tracing.so ${LIB_DIR}
RUN cp *.sql ${SHARE_DIR}
RUN cp pg_tracing.control ${SHARE_DIR}

# Build package
RUN fpm \
-n pg_tracing -v ${EXT_VERSION} -t deb \
-m "<[email protected]>" --url "https://www.datadoghq.com/" \
--description "Distributed Tracing for PostgreSQL" \
--vendor "datadoghq" --license="MIT" \
-s dir usr

VOLUME ["/out"]
Loading