Skip to content

Commit

Permalink
Docker refactoring
Browse files Browse the repository at this point in the history
- update alpine to 3.19
- refactor DOCKER_PG_LLVM_DEPS parts, as upstream postgres fixed
- improve Dockerfile, and Dockerfile.ubuntu
- fix Dockerfile.ubuntu ( devel utf8 error and gosu )
- decrease ubuntu dockerfile sizes
- addapt Docker Official Postgres testing. ( ./test/* )
- improve ci/local_docker_matrix.sh with better logging and testing
  • Loading branch information
ImreSamu authored and akorotkov committed May 14, 2024
1 parent 5785499 commit 6544ef4
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 104 deletions.
39 changes: 35 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Exclude files and directories to minimize
# the Docker build context size.
# This practice limits the scope of COPY commands in the Dockerfile.
# When not using multi-layer builds, it can effectively reduce the final image size.

# The first part of this file is should be the same as the .gitignore file
# The second part is the extra not needed content for .dockerignore

########################################################
# first part: .gitignore contents
########################################################

# Global excludes across all subdirectories
**/*.o
**/*.obj
Expand Down Expand Up @@ -32,9 +44,6 @@
**/lib*dll.def
**/lib*.pc

# documnetation files
doc/

# Local excludes in root directory
t/__pycache__/
log/
Expand All @@ -46,4 +55,26 @@ output_iso/
include/utils/stopevents_defs.h
include/utils/stopevents_data.h
orioledb.typedefs
!**/ci/antithesis/libvoidstar.so
ci/antithesis



#######################################################
# second part: extra .dockerignore contents
#######################################################

# Exclude version control and continuous integration (CI) directories
.git
.github

# Exclude Dockerfiles
Dockerfile
Dockerfile.ubuntu

# Exclude OrioleDB Docker test definitions and code
# as they are not needed inside the Docker image.
test/
ci/local_docker_matrix.sh

# Documentation files, which are not needed inside the Docker image.
doc/
20 changes: 5 additions & 15 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
compiler: [clang]
distr: [alpine, ubuntu]
include:
- distr-version: 3.18
- distr-version: 3.19
distr: alpine
- distr-version: focal
distr: ubuntu
Expand All @@ -28,17 +28,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set DOCKER_PG_LLVM_DEPS
run: |
if [[ "${{ matrix.distr }}" == "alpine" ]] && ([[ "${{ matrix.distr-version }}" == "3.18" ]] || [[ "${{ matrix.distr-version }}" == "edge" ]]); \
then echo "DOCKER_PG_LLVM_DEPS=llvm15-dev clang15" >> $GITHUB_ENV; \
else echo "DOCKER_PG_LLVM_DEPS=llvm-dev clang" >> $GITHUB_ENV; \
fi
- name: Echo DOCKER_PG_LLVM_DEP
run: echo "DOCKER_PG_LLVM_DEP = ${{ env.DOCKER_PG_LLVM_DEPS }} "
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -54,7 +44,7 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
with:
images: orioledb/orioledb
tags: ${{ github.event.inputs.tags }}
Expand All @@ -64,7 +54,7 @@ jobs:
suffix=${{ contains(github.ref, 's3') && '-s3' || '' }}-pg${{ matrix.postgres }}${{ matrix.distr == 'ubuntu' && '-ubuntu' || '' }},onlatest=true
- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.distr == 'ubuntu' && 'Dockerfile.ubuntu' || 'Dockerfile' }}
Expand All @@ -77,4 +67,4 @@ jobs:
UBUNTU_VERSION=${{ matrix.distr == 'ubuntu' && matrix.distr-version || '' }}
PG_MAJOR=${{ matrix.postgres }}
BUILD_CC_COMPILER=${{ matrix.compiler }}
DOCKER_PG_LLVM_DEPS=${{ env.DOCKER_PG_LLVM_DEPS }}
DOCKER_PG_LLVM_DEPS=llvm-dev clang
17 changes: 4 additions & 13 deletions .github/workflows/dockertest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
compiler: [clang]
distr: [alpine, ubuntu]
include:
- distr-version: 3.18
- distr-version: 3.19
distr: alpine
- distr-version: focal
distr: ubuntu
Expand All @@ -27,21 +27,12 @@ jobs:
continue-on-error: ${{ matrix.alpine == 'edge' }}

steps:
- name: Set DOCKER_PG_LLVM_DEPS
run: |
if [[ "${{ matrix.distr }}" == "alpine" ]] && ([[ "${{ matrix.distr-version }}" == "3.18" ]] || [[ "${{ matrix.distr-version }}" == "edge" ]]); \
then echo "DOCKER_PG_LLVM_DEPS=llvm15-dev clang15" >> $GITHUB_ENV; \
else echo "DOCKER_PG_LLVM_DEPS=llvm-dev clang" >> $GITHUB_ENV; \
fi
- name: Echo DOCKER_PG_LLVM_DEP
run: echo "DOCKER_PG_LLVM_DEP = ${{ env.DOCKER_PG_LLVM_DEPS }} "

- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: docker build orioletest:${{ matrix.postgres }}-${{ matrix.compiler }}-${{ matrix.distr }}-${{ matrix.distr-version }}
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.distr == 'ubuntu' && 'Dockerfile.ubuntu' || 'Dockerfile' }}
Expand All @@ -54,4 +45,4 @@ jobs:
UBUNTU_VERSION=${{ matrix.distr == 'ubuntu' && matrix.distr-version || '' }}
PG_MAJOR=${{ matrix.postgres }}
BUILD_CC_COMPILER=${{ matrix.compiler }}
DOCKER_PG_LLVM_DEPS=${{ env.DOCKER_PG_LLVM_DEPS }}
DOCKER_PG_LLVM_DEPS=llvm-dev clang
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# When adding new definitions here,
# please also include them in the first part of the .dockerignore file.

# Global excludes across all subdirectories
*.o
*.obj
Expand Down
24 changes: 4 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This is slightly adjusted Dockerfile from
# https://github.com/docker-library/postgres

# set ALPINE_VERSION= [ edge 3.18 3.17 3.16 3.15 3.14 3.13 ]
ARG ALPINE_VERSION=3.17
# set ALPINE_VERSION= [ edge 3.19 3.18 3.17 3.16 3.15 3.14 3.13 ]
ARG ALPINE_VERSION=3.19
FROM alpine:${ALPINE_VERSION}

ARG ALPINE_VERSION
# Set PG_MAJOR = [16 15]
ARG PG_MAJOR=15
ARG PG_MAJOR=16
ENV PG_MAJOR ${PG_MAJOR}

# set compiler: [ clang gcc ]
Expand Down Expand Up @@ -53,7 +53,7 @@ RUN set -eux; \
# https://wiki.alpinelinux.org/wiki/Release_Notes_for_Alpine_3.16.0#ICU_data_split
# https://github.com/docker-library/postgres/issues/327#issuecomment-1201582069
case "$ALPINE_VERSION" in 3.13 | 3.14 | 3.15 ) EXTRA_ICU_PACKAGES='' ;; \
3.16 | 3.17 | 3.18 | 3.19* ) EXTRA_ICU_PACKAGES=icu-data-full ;; \
3.16 | 3.17 | 3.18 | 3.19 | 3.20* ) EXTRA_ICU_PACKAGES=icu-data-full ;; \
*) : ;; \
esac ; \
\
Expand All @@ -78,22 +78,6 @@ RUN set -eux; \
fi ; \
fi ; \
\
# temporary not allowing LLVM 16 to be used
# reason: we can't overwrite and fix the DOCKER_PG_LLVM_DEPS
# and the future downstream extensions like PostGIS need a correct build information (DOCKER_PG_LLVM_DEPS)
if \
# if the custom llvm version is set ( via DOCKER_PG_LLVM_DEPS ), and it is 16, then halt operation
( [ ! -z "${CUSTOM_LLVM_VERSION}" ] && [ "$CUSTOM_LLVM_VERSION" == "16" ] ) \
# or - if the custom llvm version is not set, and the Alpine version is >=3.18, then halt operation
|| ( [ -z "${CUSTOM_LLVM_VERSION}" ] && ( [ "$ALPINE_VERSION" == "3.18" ] || [ "$ALPINE_VERSION" == "3.19" ]) ) \
; then \
set +x ; \
echo "------------------------------" ; \
echo "Error: The LLVM 16 is not compatible with the current PostgreSQL! Halting operation." ; \
echo "Suggested workarounds: use --build-arg DOCKER_PG_LLVM_DEPS='llvm15-dev clang15' " ; \
exit 1; \
fi ; \
\
apk add --no-cache --virtual .build-deps \
${DOCKER_PG_LLVM_DEPS} \
bison \
Expand Down
85 changes: 57 additions & 28 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# This is modified Dockerfile from 16/bookworm in
# https://github.com/docker-library/postgres

# Set UBUNTU_VERSION = [ devel 23.10 22.04 20.04 ]
# or [ devel mantic jammy focal ]
ARG UBUNTU_VERSION=focal
FROM ubuntu:${UBUNTU_VERSION}

# Set PG_MAJOR = [16 15 14 13 ]
ARG PG_MAJOR=14
ARG UBUNTU_VERSION

# Set PG_MAJOR = [16 15]
ARG PG_MAJOR=16
ENV PG_MAJOR ${PG_MAJOR}

# set compiler: [ clang gcc ]
Expand All @@ -28,16 +32,33 @@ RUN set -eux; \
mkdir -p /var/lib/postgresql; \
chown -R postgres:postgres /var/lib/postgresql

RUN set -ex; \
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
DEBIAN_FRONTEND=noninteractive apt-get full-upgrade -y; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
gnupg \
; \
rm -rf /var/lib/apt/lists/*
locales \
tzdata \
\
# Ensures compatibility with the official PostgreSQL Docker image
libnss-wrapper \
xz-utils \
zstd \
; \
echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen; \
locale-gen; \
locale -a | grep 'en_US.utf8' ; \
\
rm -rf /var/lib/apt/lists/* ; \
apt-get clean

# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
ENV LANG en_US.utf8

# grab gosu for easy step-down from root
# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.16
ENV GOSU_VERSION 1.17
RUN set -eux; \
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
Expand All @@ -58,20 +79,6 @@ RUN set -eux; \
gosu --version; \
gosu nobody true

RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get full-upgrade -y; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
locales \
tzdata \
curl \
ca-certificates \
; \
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8;

# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
ENV LANG en_US.utf8

RUN mkdir -p /usr/src/postgresql/contrib/orioledb

COPY . /usr/src/postgresql/contrib/orioledb
Expand All @@ -92,11 +99,16 @@ RUN set -eux; \
echo "ORIOLEDB_BUILDTIME=$ORIOLEDB_BUILDTIME" ; \
echo "DOCKER_PG_LLVM_DEPS=$DOCKER_PG_LLVM_DEPS" ; \
\
LLVM_RUNTIME_DEPS=$(echo "$DOCKER_PG_LLVM_DEPS" | grep -o 'llvm[0-9]*') ; \
echo "LLVM_RUNTIME_DEPS=$LLVM_RUNTIME_DEPS" ; \
\
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
build-essential \
${LLVM_RUNTIME_DEPS} \
${DOCKER_PG_LLVM_DEPS} \
bison \
curl \
flex \
gdb \
git \
Expand All @@ -113,7 +125,8 @@ RUN set -eux; \
libuuid1 \
libxml2 \
libxml2-dev \
libxslt-dev \
libxslt1.1 \
libxslt1-dev \
libzstd1 \
libzstd-dev \
make \
Expand Down Expand Up @@ -179,7 +192,7 @@ RUN set -eux; \
--with-llvm \
--with-lz4 \
--with-zstd \
--with-extra-version=" ${ORIOLEDB_VERSION} PGTAG=${PGTAG} ubuntu:focal+${BUILD_CC_COMPILER} build:${ORIOLEDB_BUILDTIME}" \
--with-extra-version=" ${ORIOLEDB_VERSION} PGTAG=${PGTAG} ubuntu:${UBUNTU_VERSION}+${BUILD_CC_COMPILER} build:${ORIOLEDB_BUILDTIME}" \
|| cat config.log ); \
echo "ORIOLEDB_PATCHSET_VERSION = `echo $PGTAG | cut -d'_' -f2`" >> src/Makefile.global; \
make -j "$(nproc)"; \
Expand All @@ -190,11 +203,26 @@ RUN set -eux; \
make -C contrib/orioledb install; \
\
apt-get -y remove \
build-essential flex bison pkg-config \
libreadline-dev libipc-run-perl \
libicu-dev python3-dev python3-pip \
libzstd-dev \
curl wget liblz4-dev uuid-dev \
${DOCKER_PG_LLVM_DEPS} \
bison \
build-essential \
curl \
flex \
gdb \
git \
libicu-dev \
libipc-run-perl \
liblz4-dev \
libreadline-dev \
libxml2-dev \
libxslt1-dev \
libzstd-dev \
make \
pkg-config \
python3-dev \
python3-pip \
uuid-dev \
wget \
; \
apt-get -y autoremove; \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/*; \
Expand All @@ -220,6 +248,7 @@ COPY --chown=postgres:postgres postgresql.docker.conf /etc/postgresql/postgresql
ENV PG_CONF=/etc/postgresql/postgresql.conf

COPY docker-entrypoint.sh /usr/local/bin/
RUN sed -i -e 's/su-exec/gosu/g' "/usr/local/bin/docker-entrypoint.sh"
ENTRYPOINT ["docker-entrypoint.sh"]

# We set the default STOPSIGNAL to SIGINT, which corresponds to what PostgreSQL
Expand Down
Loading

0 comments on commit 6544ef4

Please sign in to comment.