Skip to content

Commit 63393a9

Browse files
[CI] Dockerfiles are updated (PYTHON_BINARY) (postgrespro#328)
Main: - run_tests.sh requires and uses ${PYTHON_BINARY}, not python${PYTHON_VERSION} - run_tests2.sh setups python version and runs run_tests.sh Also: - "ADD --chown=xxx:xxx . /pg/testgres" is used - Dockerfile--std2-all.tmpl is optimized for docker cache
1 parent 8bccdf4 commit 63393a9

8 files changed

+16
-87
lines changed

Dockerfile--altlinux_10.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ ARG PYTHON_VERSION
33

44
# --------------------------------------------- base1
55
FROM alt:p10 as base1
6-
ARG PG_VERSION
76

87
RUN apt-get update
98
RUN apt-get install -y sudo curl ca-certificates
@@ -66,7 +65,7 @@ RUN apt-get install -y python3
6665
RUN apt-get install -y python3-dev
6766
RUN apt-get install -y python3-modules-sqlite3
6867

69-
ENV PYTHON_VERSION=3
68+
ENV PYTHON_BINARY=python3
7069

7170
# --------------------------------------------- final
7271
FROM base2_with_python-${PYTHON_VERSION} as final
@@ -76,9 +75,8 @@ RUN adduser test -G wheel
7675
# It enables execution of "sudo service ssh start" without password
7776
RUN sh -c "echo \"WHEEL_USERS ALL=(ALL:ALL) NOPASSWD: ALL\"" >> /etc/sudoers
7877

79-
ADD . /pg/testgres
78+
ADD --chown=test:test . /pg/testgres
8079
WORKDIR /pg/testgres
81-
RUN chown -R test /pg/testgres
8280

8381
ENV LANG=C.UTF-8
8482

Dockerfile--altlinux_11.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ ARG PYTHON_VERSION
33

44
# --------------------------------------------- base1
55
FROM alt:p11 as base1
6-
ARG PG_VERSION
76

87
RUN apt-get update
98
RUN apt-get install -y sudo curl ca-certificates
@@ -69,7 +68,7 @@ RUN apt-get install -y python3
6968
RUN apt-get install -y python3-dev
7069
RUN apt-get install -y python3-modules-sqlite3
7170

72-
ENV PYTHON_VERSION=3
71+
ENV PYTHON_BINARY=python3
7372

7473
# --------------------------------------------- final
7574
FROM base2_with_python-${PYTHON_VERSION} as final
@@ -79,9 +78,8 @@ RUN adduser test -G wheel
7978
# It enables execution of "sudo service ssh start" without password
8079
RUN sh -c "echo \"WHEEL_USERS ALL=(ALL:ALL) NOPASSWD: ALL\"" >> /etc/sudoers
8180

82-
ADD . /pg/testgres
81+
ADD --chown=test:test . /pg/testgres
8382
WORKDIR /pg/testgres
84-
RUN chown -R test /pg/testgres
8583

8684
ENV LANG=C.UTF-8
8785

Dockerfile--std-all.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ FROM postgres:${PG_VERSION}-alpine as base1
77
# --------------------------------------------- base2_with_python-3
88
FROM base1 as base2_with_python-3
99
RUN apk add --no-cache curl python3 python3-dev build-base musl-dev linux-headers
10-
ENV PYTHON_VERSION=3
10+
ENV PYTHON_BINARY=python3
1111

1212
# --------------------------------------------- final
1313
FROM base2_with_python-${PYTHON_VERSION} as final
@@ -29,9 +29,8 @@ RUN adduser postgres sudo
2929
EXPOSE 22
3030
RUN ssh-keygen -A
3131

32-
ADD . /pg/testgres
32+
ADD --chown=postgres:postgres . /pg/testgres
3333
WORKDIR /pg/testgres
34-
RUN chown -R postgres:postgres /pg
3534

3635
# It allows to use sudo without password
3736
RUN sh -c "echo \"postgres ALL=(ALL:ALL) NOPASSWD:ALL\"">>/etc/sudoers

Dockerfile--std.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ FROM postgres:${PG_VERSION}-alpine as base1
77
# --------------------------------------------- base2_with_python-3
88
FROM base1 as base2_with_python-3
99
RUN apk add --no-cache curl python3 python3-dev build-base musl-dev linux-headers
10-
ENV PYTHON_VERSION=3
10+
ENV PYTHON_BINARY=python3
1111

1212
# --------------------------------------------- final
1313
FROM base2_with_python-${PYTHON_VERSION} as final
@@ -16,9 +16,8 @@ RUN apk add --no-cache git
1616

1717
ENV LANG=C.UTF-8
1818

19-
ADD . /pg/testgres
19+
ADD --chown=postgres:postgres . /pg/testgres
2020
WORKDIR /pg/testgres
21-
RUN chown -R postgres:postgres /pg
2221

2322
USER postgres
2423
ENTRYPOINT bash run_tests.sh

Dockerfile--std2-all.tmpl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FROM postgres:${PG_VERSION}-alpine as base1
66

77
# --------------------------------------------- base2_with_python-3
88
FROM base1 as base2_with_python-3
9+
ENV PYTHON_BINARY=python3
910
RUN apk add --no-cache curl python3 python3-dev build-base musl-dev linux-headers
1011

1112
# For pyenv
@@ -75,10 +76,6 @@ RUN adduser postgres sudo
7576
EXPOSE 22
7677
RUN ssh-keygen -A
7778

78-
ADD . /pg/testgres
79-
WORKDIR /pg/testgres
80-
RUN chown -R postgres:postgres /pg
81-
8279
# It allows to use sudo without password
8380
RUN sh -c "echo \"postgres ALL=(ALL:ALL) NOPASSWD:ALL\"">>/etc/sudoers
8481

@@ -88,14 +85,15 @@ RUN sh -c "echo "postgres:*" | chpasswd -e"
8885
USER postgres
8986

9087
RUN curl https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
91-
9288
RUN ~/.pyenv/bin/pyenv install ${PYTHON_VERSION}
9389

90+
ADD --chown=postgres:postgres . /pg/testgres
91+
WORKDIR /pg/testgres
92+
9493
# THIS CMD IS NEEDED TO CONNECT THROUGH SSH WITHOUT PASSWORD
9594
RUN chmod 700 ~/
9695

9796
RUN mkdir -p ~/.ssh
98-
#RUN chmod 700 ~/.ssh
9997

10098
ENTRYPOINT sh -c " \
10199
set -eux; \

Dockerfile--ubuntu_24_04.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ RUN sh -c "echo postgres ALL=NOPASSWD:/usr/sbin/service ssh start" >> /etc/sudoe
4242
# --------------------------------------------- base2_with_python-3
4343
FROM base1 as base2_with_python-3
4444
RUN apt install -y python3 python3-dev python3-venv libpq-dev build-essential
45-
ENV PYTHON_VERSION=3
45+
ENV PYTHON_BINARY=python3
4646

4747
# --------------------------------------------- final
4848
FROM base2_with_python-${PYTHON_VERSION} as final
4949

5050
RUN apt install -y git
5151

52-
ADD . /pg/testgres
52+
ADD --chown=postgres:postgres . /pg/testgres
5353
WORKDIR /pg/testgres
54-
RUN chown -R postgres /pg
5554

5655
ENV LANG=C.UTF-8
5756

run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ command -v pg_config
1313
# prepare python environment
1414
VENV_PATH="/tmp/testgres_venv"
1515
rm -rf $VENV_PATH
16-
python${PYTHON_VERSION} -m venv "${VENV_PATH}"
16+
${PYTHON_BINARY} -m venv "${VENV_PATH}"
1717
export VIRTUAL_ENV_DISABLE_PROMPT=1
1818
source "${VENV_PATH}/bin/activate"
1919
pip install -r tests/requirements.txt

run_tests2.sh

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,4 @@ eval "$(pyenv virtualenv-init -)"
88
pyenv virtualenv --force ${PYTHON_VERSION} cur
99
pyenv activate cur
1010

11-
if [ -z ${TEST_FILTER+x} ]; \
12-
then export TEST_FILTER="TestTestgresLocal or (TestTestgresCommon and (not remote))"; \
13-
fi
14-
15-
# fail early
16-
echo check that pg_config is in PATH
17-
command -v pg_config
18-
19-
# prepare python environment
20-
VENV_PATH="/tmp/testgres_venv"
21-
rm -rf $VENV_PATH
22-
python -m venv "${VENV_PATH}"
23-
export VIRTUAL_ENV_DISABLE_PROMPT=1
24-
source "${VENV_PATH}/bin/activate"
25-
pip install -r tests/requirements.txt
26-
27-
# test code quality
28-
pip install flake8 flake8-pyproject
29-
flake8 .
30-
pip uninstall -y flake8 flake8-pyproject
31-
32-
# remove existing coverage file
33-
export COVERAGE_FILE=.coverage
34-
rm -f $COVERAGE_FILE
35-
36-
pip install coverage
37-
38-
# run tests (PATH)
39-
time coverage run -a -m pytest -l -v -n 4 -k "${TEST_FILTER}"
40-
41-
# run tests (PG_BIN)
42-
PG_BIN=$(pg_config --bindir) \
43-
time coverage run -a -m pytest -l -v -n 4 -k "${TEST_FILTER}"
44-
45-
# run tests (PG_CONFIG)
46-
PG_CONFIG=$(pg_config --bindir)/pg_config \
47-
time coverage run -a -m pytest -l -v -n 4 -k "${TEST_FILTER}"
48-
49-
# test pg8000
50-
pip uninstall -y psycopg2
51-
pip install pg8000
52-
PG_CONFIG=$(pg_config --bindir)/pg_config \
53-
time coverage run -a -m pytest -l -v -n 4 -k "${TEST_FILTER}"
54-
55-
# show coverage
56-
coverage report
57-
58-
pip uninstall -y coverage
59-
60-
# build documentation
61-
pip install Sphinx
62-
63-
cd docs
64-
make html
65-
cd ..
66-
67-
pip uninstall -y Sphinx
68-
69-
# attempt to fix codecov
70-
set +eux
71-
72-
# send coverage stats to Codecov
73-
bash <(curl -s https://codecov.io/bash)
11+
./run_tests.sh

0 commit comments

Comments
 (0)