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

Python version bump #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM alpine:3.8
FROM alpine:3.16

ARG PYTHON_VERSION=3.8.5
ARG ASSET_VERSION=local_build
LABEL name="sensu/sensu-python-runtime-alpine"

RUN apk --no-cache add build-base gmp-dev zlib-dev bzip2-dev sqlite-dev gdbm-dev db-dev readline-dev libffi-dev coreutils yaml-dev linux-headers autoconf \
openssh-client openssl-dev libc6-compat \
wget git sudo bash bash-doc bash-completion
wget git sudo bash bash-doc bash-completion \
xz-dev

COPY scripts/pyenv-install pyenv-install
COPY scripts/binary_shim binary_shim
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.centos7
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG PYTHON_VERSION=3.8.5
ARG ASSET_VERSION=local_build
ARG GREP_EXCLUDE='(ld.so|ld-linux-x86-64.so|libBrokenLocale.so|libSegFault.so|libanl.so|libc.so|libdl.so|libm.so|libmvec.so|libnss_compat.so|libnss_dns.so|libnss_files.so|libpthread.so|libresolv.so|librt.so|libthread_db.so|libutil.so|vdso.so)'

RUN yum update -y && yum groupinstall -y "Development Tools" && yum install -y curl bzip2-devel zlib-devel sqlite-devel openssl-devel readline-devel
RUN yum update -y && yum groupinstall -y "Development Tools" && yum install -y curl bzip2-devel zlib-devel sqlite-devel openssl-devel readline-devel libffi-devel xz-devel

COPY scripts/pyenv-install pyenv-install
RUN ./pyenv-install
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile.debian8 → Dockerfile.debian10
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
FROM debian:8
FROM debian:10

LABEL name="sensu/sensu-python-runtime-debian8"
LABEL name="sensu/sensu-python-runtime-debian10"

ARG PYTHON_VERSION=3.8.5
ARG ASSET_VERSION=local_build
ARG GREP_EXCLUDE='(ld.so|ld-linux-x86-64.so|libBrokenLocale.so|libSegFault.so|libanl.so|libc.so|libdl.so|libm.so|libmvec.so|libnss_compat.so|libnss_dns.so|libnss_files.so|libpthread.so|libresolv.so|librt.so|libthread_db.so|libutil.so|vdso.so)'


RUN apt-get update && apt-get install -y build-essential zlib1g-dev libsqlite0-dev libbz2-dev libreadline-dev libssl-dev curl git
RUN apt-get update && apt-get install -y build-essential zlib1g-dev libsqlite0-dev libbz2-dev libreadline-dev libssl-dev curl git libsqlite3-dev liblzma-dev libffi-dev
COPY scripts/pyenv-install pyenv-install
RUN ./pyenv-install

RUN LIBS=$(find /build/pyenv -type f -executable -exec ldd {} 2>/dev/null \;| grep "=>" | egrep -v ${GREP_EXCLUDE} | awk '{print $3}'| sort -u ) && \
for f in $LIBS; do if [ -e $f ]; then echo "Copying Library: $f" && cp $f /build/lib/; fi; done

RUN mkdir /assets/ && \
export SENSU_ASSET="/assets/sensu-python-runtime_${ASSET_VERSION}_python-${PYTHON_VERSION}_debian8_$(uname -s | tr '[:upper:]' '[:lower:]')_amd64.tar.gz" && \
export SENSU_ASSET="/assets/sensu-python-runtime_${ASSET_VERSION}_python-${PYTHON_VERSION}_debian10_$(uname -s | tr '[:upper:]' '[:lower:]')_amd64.tar.gz" && \
tar -czf $SENSU_ASSET -C /build/ .

ENV PATH=$PATH:/build/bin
Expand Down
8 changes: 4 additions & 4 deletions build_and_test_platform.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

ignore_errors=0
python_version=3.6.11
python_version=3.9.16
asset_version=${TRAVIS_TAG:-local-build}
asset_filename=sensu-python-runtime_${asset_version}_python-${python_version}_${platform}_linux_amd64.tar.gz
asset_image=sensu-python-runtime-${python_version}-${platform}:${asset_version}
Expand All @@ -24,11 +24,12 @@ else
echo "Building Docker Image: sensu-python-runtime:${python_version}-${platform}"
docker build --build-arg "PYTHON_VERSION=$python_version" --build-arg "ASSET_VERSION=$asset_version" -t ${asset_image} -f Dockerfile.${platform} .
echo "Making Asset: /assets/sensu-python-runtime_${asset_version}_python-${python_version}_${platform}_linux_amd64.tar.gz"
docker run -v "$PWD/dist:/dist" ${asset_image} cp /assets/${asset_filename} /dist/
docker run --rm -v "$PWD/dist:/dist" ${asset_image} cp /assets/${asset_filename} /dist/
# #rm $PWD/test/*
# #cp $PWD/dist/${asset_filename} $PWD/dist/${asset_filename}
else
echo "Image already exists!!!"
docker run --rm -v "$PWD/dist:/dist" ${asset_image} cp /assets/${asset_filename} /dist/
[ $ignore_errors -eq 0 ] && exit 1
fi
fi
Expand All @@ -37,13 +38,12 @@ fi
test_arr=($test_platforms)
for test_platform in "${test_arr[@]}"; do
echo "Test: ${test_platform}"
docker run --name python_runtime_platform_test -e platform -e test_platform=${test_platform} -e asset_filename=${asset_filename} -v "$PWD/tests/:/tests" -v "$PWD/dist:/dist" ${test_platform} /tests/test.sh
docker run --rm --name python_runtime_platform_test -e "PYTHON_VERSION=$python_version" -e platform -e test_platform=${test_platform} -e asset_filename=${asset_filename} -v "$PWD/tests/:/tests" -v "$PWD/dist:/dist" ${test_platform} /tests/test.sh
retval=$?
if [ $retval -ne 0 ]; then
echo "!!! Error testing ${asset_filename} on ${test_platform}"
exit $retval
fi
docker rm python_runtime_platform_test
done

if [ -z "$TRAVIS_TAG" ]; then exit 0; fi
Expand Down
13 changes: 3 additions & 10 deletions build_platforms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,21 @@ mkdir -p assets
mkdir -p scripts

# Alpine platform
platform="alpine" test_platforms="alpine:latest alpine:3 alpine:3.8" ./build_and_test_platform.sh
platform="alpine" test_platforms="alpine:latest alpine:3 alpine:3.16" ./build_and_test_platform.sh
retval=$?
if [[ retval -ne 0 ]]; then
exit $retval
fi

# Debian8 platform
platform="debian8" test_platforms="debian:8 debian:9 debian:10 ubuntu:20.04 ubuntu:16.04 ubuntu:18.04 centos:7 centos:8" ./build_and_test_platform.sh
platform="debian10" test_platforms="debian:10 debian:11 ubuntu:20.04" ./build_and_test_platform.sh
retval=$?
if [[ retval -ne 0 ]]; then
exit $retval
fi

# CentOS7 platform
platform="centos7" test_platforms="centos:8 centos:7 debian:8 debian:9 debian:10 ubuntu:16.04 ubuntu:18.04" ./build_and_test_platform.sh
retval=$?
if [[ retval -ne 0 ]]; then
exit $retval
fi

# CentOS6 platform
platform="centos6" test_platforms="centos:6 centos:8 centos:7 debian:8 debian:9 debian:10 ubuntu:16.04 ubuntu:18.04" ./build_and_test_platform.sh
platform="centos7" test_platforms="centos:7 almalinux:8 almalinux:9" ./build_and_test_platform.sh
retval=$?
if [[ retval -ne 0 ]]; then
exit $retval
Expand Down
9 changes: 4 additions & 5 deletions scripts/pyenv-install
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/bin/sh
git clone https://github.com/pyenv/pyenv.git ~/.pyenv && \
export PYENV_ROOT="$HOME/.pyenv" && \
set -e
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
pyenv install ${PYTHON_VERSION}
~/.pyenv/bin/pyenv install ${PYTHON_VERSION}
mkdir -p build/bin
mkdir -p build/lib
cp -r $PYENV_ROOT build/pyenv
cd build/bin
ln -s ../pyenv/versions/${PYTHON_VERSION}/bin/python python
ln -s ../pyenv/versions/${PYTHON_VERSION}/bin/pip pip

2 changes: 2 additions & 0 deletions tests/lzma_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import lzma
print(lzma.compress(b"Hello World"))
4 changes: 4 additions & 0 deletions tests/sqlite_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("CREATE TABLE movie(title, year, score)")
14 changes: 14 additions & 0 deletions tests/ssl_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import socket
import ssl

context = ssl.create_default_context()
context.check_hostname = False # Debian and Ubuntu containers ship with no certs
context.verify_mode = ssl.CERT_NONE

hostname = 'www.google.com'

print(ssl.get_default_verify_paths())

with socket.create_connection((hostname, 443)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
print(ssock.version())
7 changes: 5 additions & 2 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
set -e
echo "Test Script:"
echo " Asset Platform: ${platform}"
echo " Target Platform: ${test_platform}"
Expand All @@ -10,7 +11,9 @@ fi
mkdir -p /build
cd /build
tar xzf /dist/$asset_filename
#LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" /build/bin/python /tests/test_ssl_url.py
LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" [ "$(/build/bin/python --version)" = "Python 3.6.11" ]
[ "$(LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" /build/bin/python --version)" = "Python ${PYTHON_VERSION}" ]
LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" /build/bin/python /tests/uuid_test.py
LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" /build/bin/python /tests/ssl_test.py
LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" /build/bin/python /tests/lzma_test.py
LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" /build/bin/python /tests/sqlite_test.py
LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" /build/bin/python /tests/module_search_path.py