Skip to content

Commit

Permalink
generate python Dockerfiles for actual stable releases
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaszdunov committed Jun 2, 2024
1 parent 91206fb commit 4f18ed1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
34 changes: 34 additions & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM alpine as build

RUN mkdir /usr/bin/

# install dependencies and python
RUN apk add --no-cache \
build-base \
libffi-dev \
openssl-dev \
bzip2-dev \
zlib-dev \
xz-dev \
readline-dev \
sqlite-dev \
wget \
&& cd /usr/src \
&& wget {python_link} \
&& tar xzf Python-{python_version}.tgz \
&& cd Python-{python_version} \
&& ./configure --enable-optimizations \
&& make altinstall \
&& ln -s /usr/local/bin/python{python_short_version} /usr/bin/python3 \
&& ln -s /usr/local/bin/pip{python_short_version} /usr/bin/pip3 \
&& apk del build-base \
&& rm -rf /usr/src/Python-{python_version}.tgz /usr/src/Python-{python_version}


FROM scratch

COPY --from=build / /

WORKDIR /app

CMD ["python3"]
27 changes: 18 additions & 9 deletions src/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@
actual_versions_raw_list = page_data.find_all(
'span', attrs={'class': 'release-version'})

actual_releases_list = []
active_releases_list = []
for span in actual_versions_raw_list:
actual_releases_list.append(span.text)
active_releases_list.append(span.text)


# get all stable releases
response = requests.get(f'{URL}source/').text
page_data = bs(response, 'lxml')
stable_releases_raw_links = page_data.find_all('a')
releases_raw_download_links = page_data.find_all('a')

releases_links = []
for link in stable_releases_raw_links:
releases_links.append(link.get('href'))
releases_download_links = []
for link in releases_raw_download_links:
releases_download_links.append(link.get('href'))


actual_stable_releases_links = []

for actual_release in actual_releases_list:
for link in releases_links:
for actual_release in active_releases_list:
for link in releases_download_links:
check = re.fullmatch(r'.*Python-\d*.\d*.?\d*.tgz', link)
if check:
if actual_release in re.sub(r'.?\d*/Python*', '', link):
actual_stable_releases_links.append(link)
break
break

Dockerfile_temp = open('Dockerfile.template').read()
for link in actual_stable_releases_links:
py_version = re.search(r'\d+.\d+.?\d*', link)[0]
py_short_version = re.search(r'\d+.\d+', py_version)[0]
Dockerfile = Dockerfile_temp.format(python_link=link,
python_version=py_version,
python_short_version=py_short_version)
open(f'Dockerfile_{py_version}','w').write(Dockerfile)

0 comments on commit 4f18ed1

Please sign in to comment.