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

update-dockerfile-update-workflow #19147

Merged
merged 36 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
107ebaf
update-dockerfile-update-workflow
sapirshuker Aug 14, 2023
2f641c4
remove use with version
sapirshuker Aug 14, 2023
decdc95
add logs, change branch name,resolve githubaction trigger
sapirshuker Aug 14, 2023
50aa4c0
change branch name, added logs
sapirshuker Aug 14, 2023
d4f5ed3
fixes, add logs
sapirshuker Aug 14, 2023
38f0ae3
CR fixes, change branch name, fix workflow
sapirshuker Aug 14, 2023
13ecc49
CR fixes, change branch name, fix workflow
sapirshuker Aug 14, 2023
f3bee21
update regex, change branch name
sapirshuker Aug 14, 2023
631a308
update regex, change branch name
sapirshuker Aug 14, 2023
d0af773
fixes, change branch name
sapirshuker Aug 15, 2023
2373817
fixes, change branch name
sapirshuker Aug 15, 2023
9d0edd9
fixes, change branch name
sapirshuker Aug 15, 2023
ed20c37
for testing
sapirshuker Aug 15, 2023
28fc33a
fixes
sapirshuker Aug 15, 2023
447b4e7
fixes, change branch name
sapirshuker Aug 15, 2023
0efcff5
fixes, change branch name
sapirshuker Aug 15, 2023
8552908
change poetry install, change branch name, change log output
sapirshuker Aug 15, 2023
19edd58
fixes
sapirshuker Aug 15, 2023
bd677d0
change python version
sapirshuker Aug 15, 2023
a588294
change python version
sapirshuker Aug 15, 2023
5ccdca1
change python version
sapirshuker Aug 16, 2023
8b5a69a
update pipfile python version, change branch name
sapirshuker Aug 16, 2023
986cfaf
change python version, add logs,remove of for test
sapirshuker Aug 16, 2023
b3aa47e
Merge branch 'master' into update-dockerfile-update-workflow
sapirshuker Aug 16, 2023
9bc1f94
change branch name
sapirshuker Aug 16, 2023
7c9f464
change branch name, remove reverted content, CR fixes
sapirshuker Aug 16, 2023
b60ea75
check workflow
sapirshuker Aug 16, 2023
1caf49b
revert workflow changes
sapirshuker Aug 16, 2023
09fa8be
check workflow
sapirshuker Aug 16, 2023
000728c
revert workflow changes
sapirshuker Aug 16, 2023
e689514
revert all needed to be reverted
sapirshuker Aug 17, 2023
42c53f4
revert all needed to be reverted
sapirshuker Aug 17, 2023
24f065f
fixes CR review and last check
sapirshuker Aug 17, 2023
6cff664
fixes CR review and last check
sapirshuker Aug 17, 2023
fc3c780
revert changes fot tests
sapirshuker Aug 17, 2023
1959ccf
CR fixes
sapirshuker Aug 20, 2023
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
27 changes: 13 additions & 14 deletions .github/workflows/create-update-dockerfiles-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name: Create update dockerfiles PR

on:
workflow_run:
workflows: [Update external base images, Update internal base images]
sapirshuker marked this conversation as resolved.
Show resolved Hide resolved
types: completed
workflow_dispatch:

workflows: [Update external base images test, Update internal base images test]
types:
sapirshuker marked this conversation as resolved.
Show resolved Hide resolved
- completed
jobs:
# ------------------------
get_branches:
Expand All @@ -22,7 +21,7 @@ jobs:
GITHUB_TOKEN: ${{secrets.CONTENT_BOT_TOKEN}}
run: |
git fetch
branches=$(git branch -r | grep autoupdate/)
branches=$(git branch -r | grep TEST18auTESTtoTESTupdate/)
sapirshuker marked this conversation as resolved.
Show resolved Hide resolved
matrix="[ "
for branch in $(echo $branches); do
exists=`gh pr list --state open -H ${branch#origin/}`
Expand Down Expand Up @@ -55,13 +54,13 @@ jobs:
destination_branch: "" # If blank, default: master
pr_title: "build(dockerfiles) update Dockerfile - ${{ matrix.branches }}" # Title of pull request
pr_body: "This is automated PR to update dockerfiles base images\n${{ matrix.branches }}"
- name: approve and merge
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ steps.open-pr.outputs.pr_url }}
if: ${{ steps.open-pr.outputs.pr_url }}
run: |
echo "Approving and merging"
gh pr review --approve "$PR_URL"
gh pr merge --auto --squash "$PR_URL"
# - name: approve and merge
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder to revert

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# PR_URL: ${{ steps.open-pr.outputs.pr_url }}
# if: ${{ steps.open-pr.outputs.pr_url }}
# run: |
# echo "Approving and merging"
# gh pr review --approve "$PR_URL"
# gh pr merge --auto --squash "$PR_URL"

19 changes: 12 additions & 7 deletions .github/workflows/update-external-base-images.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Update external base images
name: Update external base images test

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

push:
branches:
- update-dockerfile-update-workflow
# schedule:
# - cron: '0 0 * * *'
# workflow_dispatch:


jobs:
update-docker-files:
Expand All @@ -17,14 +20,16 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'
- name: Setup Poetry
uses: Gr1N/setup-poetry@v8
- name: run
run: |
git config --global user.email ""
git config --global user.name "auto dockerfiles update"
echo "==== $(date): Starting pipenv setup... ===="
python -m pip install --upgrade pip
pip install pipenv
pip install pipenv==2023.3.18
pipenv install
echo "==== Finished ===="
[[ ${{ vars.DISABLE_TIMESTAMP_AUTOUPDATES }} = 'true' ]] && tu_flag="--no-timestamp-updates"
Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/update-internal-base-images.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
name: Update internal base images
name: Update internal base images test

# on:
# schedule:
# - cron: '30 0,4,8,12,16,20 * * *'
on:
schedule:
- cron: '30 0,4,8,12,16,20 * * *'
workflow_dispatch:
push:
branches:
- update-dockerfile-update-workflow
# workflow_dispatch:

jobs:
update-docker-files:
Expand All @@ -15,14 +19,16 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: '3.10'
- name: Setup Poetry
uses: Gr1N/setup-poetry@v8
- name: run
run: |
git config --global user.email ""
git config --global user.name "auto dockerfiles update"
echo "==== $(date): Starting pipenv setup... ===="
python -m pip install --upgrade pip
pip install pipenv
pip install pipenv==2023.3.18
pipenv install
echo "==== Finished ===="
pipenv run python ./utils/auto_dockerfile_update/update_dockerfiles.py -t internal
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ gitpython = "*"
pytest = "*"

[requires]
python_version = "3.9"
python_version = "3.10"
4 changes: 2 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions utils/auto_dockerfile_update/get_dockerfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
import re
from datetime import datetime
from pathlib import Path
from typing import List, Dict
from typing import List, Dict, Tuple, Optional
from configparser import ConfigParser, MissingSectionHeaderError
from dateutil.parser import parse


EXTRACT_PYTHON_VERSION_REGEX = re.compile(r"3.\d{1,3}.\d{1,3}")
BASE_IMAGE_REGEX = re.compile(r"(?:FROM [\S]+)")
INTERNAL_BASE_IMAGES = re.compile(r"(demisto\/|devdemisto\/)")
LAST_MODIFIED_REGEX = re.compile(r"# Last modified: [^\n]*")



def get_last_modified(docker_file_content: str) -> str:
"""
Get the last modified section in dockerfile, if not exists return 1.1.2000 12:00:00 +00:00
Expand Down Expand Up @@ -90,7 +91,31 @@ def filter_ignored_files(files_list):
print(f'could not read ignored config {str(e)}')
return files_list


def get_file_path_and_docker_version_if_exist(dockerfile: dict, docker_latest_tag:str)-> Optional[Tuple]:
"""Gets the Pipfile or the pyproject.toml file path
and the docker version from the Dockerfile.
Args:
dockerfile (str): A dict that represents the docker file.
docker_latest_tag (str): latest tag string.
Returns:
Tuple[str,str]: The file path, The docker file tag.
"""
base_path = dockerfile["path"]
base_path=base_path.replace("/Dockerfile", "")
pipfile_path = glob(f"{base_path}/Pipfile", recursive=True)
pyproject_path = glob(f"{base_path}/pyproject.toml", recursive=True)
extracted_python_version = re.search(EXTRACT_PYTHON_VERSION_REGEX, docker_latest_tag)
if extracted_python_version:
extracted_version = extracted_python_version.group(0)
if path := (pipfile_path or pyproject_path):
print(f"[INFO] Got path for: {path[0]}")
return path[0],extracted_version
else:
print(f"[INFO] Can't find Pipfile/pyproject file for {dockerfile['name']}.")
else:
print(f"[ERROR] Can't find docker tag for {dockerfile['name']}.")
return None

def get_docker_files(base_path="docker/", devonly=False, external=False, internal=False) -> List[Dict]:
"""
Get all the relevant dockerfiles from the repository.
Expand Down
Loading
Loading