Skip to content

Commit

Permalink
update workflow and parser. Now Images with same minor tags "3.12" an…
Browse files Browse the repository at this point in the history
…d "3.12.3" can be download by pulling with tag "3" or "3.12"
  • Loading branch information
vlaszdunov committed Jun 3, 2024
1 parent 4f18ed1 commit 868a415
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 61 deletions.
75 changes: 60 additions & 15 deletions .github/workflows/Publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,86 @@ name: build and push
run-name: Build and push Python images to GHCR

on:
push:
schedule:
- cron: 0 0 * * *
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
MAIN_BRANCH: "main"

jobs:
build-and-publish:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: install dependencies
run: pip install -r requirements.txt

- name: Create Dockerfiles of Python Images
run: python ./src/parse.py

- uses: danyow/[email protected]
id: array
with:
cmd: ls Python_dockerfiles
separator: newline
- name: "Upload Artifact"
uses: actions/upload-artifact@v4
with:
name: Generated_Dockerfiles
path: Python_dockerfiles/
retention-days: 1
outputs:
param: ${{ steps.array.outputs.build }}

matrix_input:
permissions:
contents: read
packages: write
id-token: write

needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
param: ${{ fromJson(needs.setup.outputs.param) }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{env.REGISTRY}}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Python Images
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: Generated_Dockerfiles

- name: building images
run: |
docker build . --target III.X --tag ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:3.10
docker build . --target III.XI --tag ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:3.11
docker build . --target III.XII --tag ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:3.12
docker build . --target latest --tag ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
tags=$(cat ${{matrix.param}}/tags.txt)
IFS=$'\n'
for tag in $tags; do
docker build -q --file ${{matrix.param}}/Dockerfile --tag ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:$tag .
done
- name: Publish Python Images
- name: Publishing images
run: |
docker push ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:3.10
docker push ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:3.11
docker push ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:3.12
docker push ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
tags=$(cat ${{matrix.param}}/tags.txt)
IFS=$'\n'
for tag in $tags; do
docker push ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:$tag
done
- name: delete artifacts
uses: geekyeggo/delete-artifact@v1
with:
name: Generated_Dockerfiles
2 changes: 1 addition & 1 deletion Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine as build

RUN mkdir /usr/bin/
RUN mkdir /usr/src/

# install dependencies and python
RUN apk add --no-cache \
Expand Down
36 changes: 0 additions & 36 deletions src/create_dockerfile.py

This file was deleted.

40 changes: 31 additions & 9 deletions src/parse.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import requests
from bs4 import BeautifulSoup as bs
import re
import os

URL = 'https://www.python.org/downloads/'

request_headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"
}
# get list of active releases
response = requests.get(URL).text
response = requests.get(URL, request_headers).text

page_data = bs(response, 'lxml')
actual_versions_raw_list = page_data.find_all(
Expand All @@ -15,9 +19,10 @@
for span in actual_versions_raw_list:
active_releases_list.append(span.text)

active_releases_list = active_releases_list[2:]

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

Expand All @@ -27,20 +32,37 @@


actual_stable_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

print(active_releases_list)
Dockerfile_temp = open('Dockerfile.template').read()
if os.path.exists('Python_dockerfiles') == False:
os.mkdir('Python_dockerfiles')
for version in active_releases_list:
if re.fullmatch(r'\d.*', version):
os.mkdir(f'Python_dockerfiles/{version}')
open(f'Python_dockerfiles/{version}/tags.txt', 'w').write(version)

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]
py_version = re.search(r'\d+.\d+.?\d*', link)[0] # type:ignore
py_short_version = re.search(r'\d+.\d+', py_version)[0] # type:ignore
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)
python_version=py_version,
python_short_version=py_short_version)

open(
f'Python_dockerfiles/{py_short_version}/Dockerfile', 'w').write(Dockerfile)
open(f'Python_dockerfiles/{py_short_version}/tags.txt', 'a')\
.write(f'\n{py_version}')

if actual_stable_releases_links.index(link) == 0:
ver_short_version = re.sub(r'\.\d*', '', py_short_version)
open(f'Python_dockerfiles/{py_short_version}/tags.txt',
'a').write(f'\n{ver_short_version}')
open(f'Python_dockerfiles/{py_short_version}/tags.txt',
'a').write(f'\nlatest')

0 comments on commit 868a415

Please sign in to comment.