Skip to content

Commit

Permalink
fix image push logic (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
neel-astro committed Jul 6, 2022
1 parent 980c0d7 commit 2801ec3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
10 changes: 1 addition & 9 deletions airflow/podman_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,11 @@ func (p *PodmanImage) Push(cloudDomain, token, remoteImageTag string) error {
registry := "registry." + cloudDomain
remoteImage := fmt.Sprintf("%s/%s", registry, imageName(p.imageName, remoteImageTag))

err := p.podmanBind.Tag(p.conn, imageName(p.imageName, "latest"), remoteImageTag, fmt.Sprintf("%s/%s", registry, p.imageName), nil)
if err != nil {
return fmt.Errorf("command 'podman tag %s %s' failed: %w", p.imageName, remoteImage, err)
}
options := new(images.PushOptions)
if err := p.podmanBind.Push(p.conn, p.imageName, remoteImage, options); err != nil {
if err := p.podmanBind.Push(p.conn, imageName(p.imageName, "latest"), remoteImage, options); err != nil {
return fmt.Errorf("error pushing %s image to %s: %w", p.imageName, registry, err)
}

err = p.podmanBind.Untag(p.conn, imageName(p.imageName, "latest"), remoteImageTag, fmt.Sprintf("%s/%s", registry, p.imageName), nil)
if err != nil {
return fmt.Errorf("command 'podman untag %s' failed: %w", remoteImage, err)
}
return nil
}

Expand Down
15 changes: 1 addition & 14 deletions airflow/podman_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
func TestPodmanPushSuccess(t *testing.T) {
bindMock := new(mocks.PodmanBind)
podmanImageMock := &PodmanImage{imageName: "test", podmanBind: bindMock, conn: context.TODO()}
bindMock.On("Tag", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
bindMock.On("Push", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything).Return(nil)
bindMock.On("Untag", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)

err := podmanImageMock.Push("test.astro.io", "token", "2")
assert.NoError(t, err)
Expand All @@ -24,20 +22,9 @@ func TestPodmanPushSuccess(t *testing.T) {
func TestPodmanPushFailure(t *testing.T) {
bindMock := new(mocks.PodmanBind)
podmanImageMock := &PodmanImage{imageName: "test", podmanBind: bindMock, conn: context.TODO()}
bindMock.On("Tag", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(errPodman).Once()

err := podmanImageMock.Push("test.astro.io", "token", "2")
assert.Contains(t, err.Error(), "command 'podman tag test registry.test.astro.io/test/airflow:2' failed")

bindMock.On("Tag", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
bindMock.On("Push", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything).Return(errPodman).Once()

err = podmanImageMock.Push("test.astro.io", "token", "2")
err := podmanImageMock.Push("test.astro.io", "token", "2")
assert.Contains(t, err.Error(), "error pushing test image to registry.test.astro.io")

bindMock.On("Push", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything).Return(nil)
bindMock.On("Untag", podmanImageMock.conn, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(errPodman)

err = podmanImageMock.Push("test.astro.io", "token", "2")
assert.Contains(t, err.Error(), "command 'podman untag registry.test.astro.io/test/airflow:2' failed")
}

0 comments on commit 2801ec3

Please sign in to comment.