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

Auto add first 7 characters of the commit by default #117

Open
justin808 opened this issue Nov 24, 2023 · 1 comment
Open

Auto add first 7 characters of the commit by default #117

justin808 opened this issue Nov 24, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@justin808
Copy link
Member

justin808 commented Nov 24, 2023

should we change build-image without option --commit to default to call git to get the local commit sha?

module Command
  class BuildImage < Base
    NAME = "build-image"
    OPTIONS = [
      app_option(required: true),
      commit_option
    ].freeze
    DESCRIPTION = "Builds and pushes the image to Control Plane"
    LONG_DESCRIPTION = <<~DESC
      - Builds and pushes the image to Control Plane
      - Automatically assigns image numbers, e.g., `app:1`, `app:2`, etc.
      - Uses `.controlplane/Dockerfile` or a different Dockerfile specified through `dockerfile` in the `.controlplane/controlplane.yml` file
      - If a commit is provided through `--commit` or `-c`, it will be set as the runtime env var `GIT_COMMIT`
    DESC

https://github.com/shakacode/heroku-to-control-plane/blob/main/lib/command/build_image.rb

HiChee does:

            cpl build-image -a $APP_NAME_STAGING --commit ${CIRCLE_SHA1::7}

For Github action, that would be

 cpl build-image -a $APP_NAME_STAGING --commit ${GITHUB_SHA::7}

(https://chat.openai.com/share/7be4d077-9dab-4fab-b03d-b68ab057230b)

How about if we do this if the commit is not specified?

  # Assumes the git CLI is available. This is not the case in production on Heroku.
  def self.retrieve_sha_from_git
    `git rev-parse HEAD 2>/dev/null`.to_s.strip
  end

and get the commit and take the first 7 chars?

Maybe need to allow choosing the number of chars?
Maybe allow turning this off with --no-commit-in-name?

@ahangarha
Copy link
Contributor

I think we shouldn't make the default behavior dependent on git. cpl should work regardless of the used vcs in the project.

I think the better approach is to have the incremental image tag as the default, but also have ways to set the method of calculating the image tag in the configuration file.

Also, I think the current --commit option practically works as --tag CUSTOM_IMAGE_TAG. We may choose to use --commit as an alias to --tag COMMIT_SHA (only include first 7 char). But it adds some unnecessary complexity (for the case of passing both options).

In case it is important to know git commit hash in the deployed project in runtime, we may look for ways to pass custom args while building images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants