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

Fix tag format of container when building tag #84

Merged
merged 1 commit into from
Apr 22, 2019

Conversation

jwliechty
Copy link
Contributor

@jwliechty jwliechty commented Apr 22, 2019

Another PR that addresses #63.

Doing a captain build when on a tagged commit currently causes a
erroneous tag name. For example, if on a tag v1.0 of a repository, when
the captain build occurs, this this the output:

[CAPTAIN] Skipping build of image my_organization/my_image_name:da5ewb3 - image is already built
[CAPTAIN] Tagging image my_organization/my_image_name:da5ewb3 as my_organization/my_image_name:latest
[CAPTAIN] Tagging image my_organization/my_image_name:da5ewb3 as my_organization/my_image_name:tags.v1.0^0
API error (500): {"message":"invalid tag format"}

Notice the tags.v1.0^0. That is wrong on two fronts. 1.) the tag should
be v1.0 and 2.) the carrot symbol ^ makes it an invalid format for a
docker tag.

The problem occurs when obtaining the branch names. The code uses the
command git name-rev --name-only HEAD to determine the branch name.
This used to work. However, git must have changed over the years because
if you are on a tag, this now returns tags.v1.0^0.

Fortunately, the same command has an --exclude parameter that will
allow us to indicate to filter out tags (which is what we wanted anyway
for that particular call). The tags are determined later via the git
command git tag --points-at HEAD. (all of these references occur in
git.go)

When running tests, as they currently are, they failed for this very
reason. After excluding tags with the --exclude parameter to the git
command, all the tests pass. (I am running git version 2.17.1 on Ubuntu
18.04)

Please accept this PR and create a new distributable so I and others do
not run into this again.

@CLAassistant
Copy link

CLAassistant commented Apr 22, 2019

CLA assistant check
All committers have signed the CLA.

Another PR that addresses harbur#63.

Doing a `captain build` when on a tagged commit currently causes a
erroneous tag name. For example, if on a tag v1.0 of a repository, when
the captain build occurs, this this the output:

```
[CAPTAIN] Skipping build of image my_organization/my_image_name:da5ewb3 - image is already built
[CAPTAIN] Tagging image my_organization/my_image_name:da5ewb3 as my_organization/my_image_name:latest
[CAPTAIN] Tagging image my_organization/my_image_name:da5ewb3 as my_organization/my_image_name:tags.v1.0^0
API error (500): {"message":"invalid tag format"}
```

Notice the `tags.v1.0^0`. That is wrong on two fronts. 1.) the tag should
be `v1.0` and 2.) the carrot symbol `^` makes it an invalid format for a
docker tag.

The problem occurs when obtaining the branch names. The code uses the
command `git name-rev --name-only HEAD` to determine the branch name.
This used to work. However, git must have changed over the years because
if you are on a tag, this now returns `tags.v1.0^0`.

Fortunately, the same command has an `--exclude` parameter that will
allow us to indicate to filter out tags (which is what we wanted anyway
for that particular call). The tags are determined later via the git
command `git tag --points-at HEAD`. (all of these references occur in
`git.go`)

When running tests, as they currently are, they failed for this very
reason. After excluding tags with the `--exclude` parameter to the git
command, all the tests pass. (I am running git version 2.17.1 on Ubuntu
18.04)

Please accept this PR and create a new distributable so I and others do
not run into this again.
@dkapanidis
Copy link
Member

Tested and it works properly.

Here is a quick way to test it locally (a variation of the test defined at #63)

git init

cat > Dockerfile << EOL
FROM scratch
EXPOSE 80
EOL

git add Dockerfile
git commit -am 'Testing'
git tag -a 1.0.0 -m 'test tag'
captain build

@dkapanidis dkapanidis merged commit 10c4ad3 into harbur:master Apr 22, 2019
@dkapanidis dkapanidis mentioned this pull request Apr 22, 2019
@jwliechty jwliechty deleted the b-fix_tag_format branch May 17, 2019 21:24
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.

3 participants