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

Fixes current branch check problem when tag is pushed to push docker tags #184

Merged
merged 13 commits into from
Sep 30, 2021

Conversation

gurkanindibay
Copy link
Contributor

@gurkanindibay gurkanindibay commented Sep 20, 2021

After building main docker images, we need to create tagged docker images such as 10.0-alpine by creating new tag on master branch
While tagging, Github Actions clones the code in detached state and when in this state we can not get current branch . Since we are using current branch to decide whether images weill published or not, and we can not use it in tag push case , we need to put tag existence case on master branch to be able to handle tag push case
Som improvements are suggested. These are in the issue below
#192

@@ -299,10 +300,29 @@ def prepend_line_in_file(file: str, match_regex: str, append_str: str) -> bool:

return has_match

def is_tag_on_branch(tag_name: str, branch_name: str):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new method to check whether branch contains tag

@@ -147,8 +147,9 @@ def publish_tagged_docker_images(docker_image_type, tag_name: str, current_branc
docker_client.images.build(dockerfile=docker_image_info_dict[docker_image_type]['file-name'],
tag=docker_image_name,
path=".")
if current_branch != DEFAULT_BRANCH_NAME:
print(f"Since current branch {current_branch} is not equal to {DEFAULT_BRANCH_NAME} tags will not be pushed.")
if is_tag_on_branch(tag_name=tag_name, branch_name=DEFAULT_BRANCH_NAME):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of tag push, tag contains check is used instead of branch name

@@ -216,23 +219,42 @@ def validate_and_extract_manual_exec_params(manual_trigger_type_param: str, tag_
return manual_trigger_type_param


def get_image_publish_status(github_ref: str, is_test: bool):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Centralized the image publish status to manage the publish status in one place

Copy link
Member

@hanefi hanefi left a comment

Choose a reason for hiding this comment

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

I do not really understand the purpose of the new publish parameter in many of your functions. Can you please choose a better name?

Comment on lines +32 to +33
with:
fetch-depth: 0
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? Do you really need all the git history?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/citusdata/tools/runs/3653741920?check_suite_focus=true
I can not test the is_tag_on_branch since devevlop is not fetched

@@ -11,7 +11,8 @@
import gnupg
import pathlib2
import requests
from git import Repo
from git import Repo, GitCommandError
import git
Copy link
Member

Choose a reason for hiding this comment

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

Please organize your imports.

Here is my suggestion:

import base64
import os
import re
import shlex
import subprocess
from datetime import datetime
from enum import Enum
from typing import Dict, List, Tuple

import git
import gnupg
import pathlib2
import requests
from git import GitCommandError, Repo
from github import Commit, Github, PullRequest, Repository
from jinja2 import Environment, FileSystemLoader
from parameters_validation import validate_parameters

from .common_validations import is_tag, is_version
from .dbconfig import RequestLog, RequestType

Imports should be divided according to what is being imported. There are generally three groups:

  1. standard library imports (Python’s built-in modules)
  2. related third party imports (modules that are installed and do not belong to the current application)
  3. local application imports (modules that belong to the current application)

Each group of imports should be separated by a blank space.

See https://realpython.com/absolute-vs-relative-python-imports/#styling-of-import-statements for more on this

Copy link
Member

Choose a reason for hiding this comment

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

Please consider updating your IDE to organize your imports on save, so it always keeps them in the correct format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Configured my IDE and fixed as you wish

@hanefi
Copy link
Member

hanefi commented Sep 28, 2021

@gurkanindibay I do not really get why we need to have a really convoluted solution to this problem.

I think we have 2 scenarios where we push images to DockerHub.

on:
  push:
    branches:
      - master
on:
  push:
    tags:
      - "**"

In either case, we should be able to get the ref properly by using ${GITHUB_REF#refs/*/} that will resolve to the branch name in case 1, and tag name in case 2.

Note that you may need separate workflow definitions to allow this.

Let's have a chat offline and create a better design for solving this problem.

@gurkanindibay gurkanindibay merged commit 75e574e into develop Sep 30, 2021
@hanefi hanefi deleted the docker_tag_fix branch September 30, 2021 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants