diff --git a/Dockerfile.template b/Dockerfile.template new file mode 100644 index 0000000..b4f8247 --- /dev/null +++ b/Dockerfile.template @@ -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"] \ No newline at end of file diff --git a/src/parse.py b/src/parse.py index 672972f..d850232 100644 --- a/src/parse.py +++ b/src/parse.py @@ -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 \ No newline at end of file + 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)