Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Rebase Dockerfiles according to release schedule
Browse files Browse the repository at this point in the history
# Conflicts:
#	doozerlib/distgit.py
  • Loading branch information
locriandev committed Oct 6, 2022
1 parent 43c2a0c commit 7b25335
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
17 changes: 13 additions & 4 deletions doozerlib/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import re
import shutil
import sys
import threading
import time
import traceback
from datetime import date
from datetime import date, datetime
from multiprocessing import Event, Lock
from typing import Dict, List, Optional, Tuple, Union

Expand All @@ -35,6 +34,7 @@
from doozerlib.model import ListModel, Missing, Model
from doozerlib.osbs2_builder import OSBS2Builder
from doozerlib.pushd import Dir
from doozerlib.release_schedule import ReleaseSchedule
from doozerlib.rpm_utils import parse_nvr
from doozerlib.source_modifications import SourceModifierFactory
from doozerlib.util import convert_remote_git_to_https, yellow_print
Expand Down Expand Up @@ -430,6 +430,15 @@ def __init__(self, metadata, autoclone=True,
self.logger: logging.Logger = metadata.logger
self.source_modifier_factory = source_modifier_factory

# Check if we should try to match upstream
if self.runtime.group_config.canonical_builders_from_upstream == 'auto':
# canonical_builders_from_upstream set to 'auto': rebase according to release schedule
feature_freeze_date = ReleaseSchedule(self.runtime).get_ff_date()
self.should_match_upstream = datetime.now() < feature_freeze_date
else:
# canonical_builders_from_upstream set to either 'false' or 'true'
self.should_match_upstream = self.runtime.group_config.canonical_builders_from_upstream

def clone(self, distgits_root_dir, distgit_branch):
super(ImageDistGitRepo, self).clone(distgits_root_dir, distgit_branch)
self._read_master_data()
Expand Down Expand Up @@ -1633,11 +1642,11 @@ def _mapped_image_for_assembly_build(self, parent_images, i):
def _mapped_image_from_stream(self, image, original_parent, dfp):
stream = self.runtime.resolve_stream(image.stream)

if not self.runtime.group_config.canonical_builders_from_upstream:
if not self.should_match_upstream:
# Do typical stream resolution.
return stream.image

# When canonical_builders_from_upstream flag is set, try to match upstream FROM
# canonical_builders_from_upstream flag is either True, or 'auto' and we are before feature freeze
try:
self.logger.debug('Retrieving image info for image %s', original_parent)
cmd = f'oc image info {original_parent} -o json'
Expand Down
43 changes: 43 additions & 0 deletions doozerlib/release_schedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from datetime import datetime
import os

import yaml

from doozerlib import gitdata


class ReleaseSchedule:
"""
This class is a Singleton. Only at first object construction, it will clone ocp-release-schedule repo inside Doozer
working directory, parse and store yaml data related to the current OCP version
"""

_instance = None

def __new__(cls, runtime):
if cls._instance is None:
cls._instance = super(ReleaseSchedule, cls).__new__(cls)
cls.initialize(runtime)
return cls._instance

@classmethod
def initialize(cls, runtime):
if 'GITLAB_TOKEN' not in os.environ:
raise RuntimeError('A GITLAB_TOKEN env var must be defined')

# Clone ocp-release-schedule in doozer working dir
git_data = gitdata.GitData(
data_path=f'https://oauth2:{os.environ["GITLAB_TOKEN"]}@gitlab.cee.redhat.com/ocp-release-schedule/schedule.git',
clone_dir=runtime.working_dir
)

# Parse and store relevant yaml
major = runtime.group_config.vars['MAJOR']
minor = runtime.group_config.vars['MINOR']
config_file = f'{git_data.data_dir}/schedules/{major}.{minor}.yaml'
with open(config_file) as f:
cls._instance.schedule_data = yaml.safe_load(f.read())

def get_ff_date(self) -> datetime:
event = next(item for item in self.schedule_data['events'] if item["name"] == "feature-freeze")
return datetime.strptime(event['date'], '%Y-%m-%dT%H:00:00-00:00')

0 comments on commit 7b25335

Please sign in to comment.