| 
									
										
										
										
											2017-03-07 07:11:40 +08:00
										 |  |  | #!/usr/bin/env bats | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | load helpers | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @test "from" { | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json alpine | 
					
						
							|  |  |  |   cid=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm $cid | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch | 
					
						
							|  |  |  |   cid=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm $cid | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --pull=false --signature-policy ${TESTSDIR}/policy.json --name i-love-naming-things alpine | 
					
						
							|  |  |  |   cid=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm i-love-naming-things | 
					
						
							| 
									
										
										
										
											2017-03-18 05:46:21 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @test "from-defaultpull" { | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json alpine | 
					
						
							|  |  |  |   cid=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm $cid | 
					
						
							| 
									
										
										
										
											2017-03-18 05:46:21 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 05:38:15 +08:00
										 |  |  | @test "from-scratch" { | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --pull=false --signature-policy ${TESTSDIR}/policy.json scratch | 
					
						
							|  |  |  |   cid=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm $cid | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --pull=true  --signature-policy ${TESTSDIR}/policy.json scratch | 
					
						
							|  |  |  |   cid=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm $cid | 
					
						
							| 
									
										
										
										
											2017-03-29 05:38:15 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 05:46:21 +08:00
										 |  |  | @test "from-nopull" { | 
					
						
							| 
									
										
											  
											
												Fix --pull=true||false and add --pull-never to bud and from (retry)
(Replaces #1873 as it had lint issues that were timing out tests that I couldn't
track down easily)
Prior to this fix, if someone did `buildah bud --pull=false .` and the image in
the Containerfile's FROM statement was not local, the build would fail. The same
build on Docker will succeed. In Docker, when `--pull` is set to false, it only
pulls the image from the registry if there was not one locally. Buildah would never
pull the image and if the image was not locally available, it would throw an error.
In certain Kubernetes environments, this was especially troublesome.
To retain the old `--pull=false` functionality, I've created a new `--pull-never`
option that fails if an image is not locally available just like the old
`--pull=false` option used to do.
In addition, if there was a newer version of the image on the repository than
the one locally, the `--pull=true` option would not pull the image as it should
have, this corrects that.
Changes both the from and bud commands.
Addresses: #1675
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Closes: #1959
Approved by: rhatdan
											
										 
											2019-10-31 22:15:56 +08:00
										 |  |  |   run_buildah 1 from --pull-never --signature-policy ${TESTSDIR}/policy.json alpine | 
					
						
							| 
									
										
										
										
											2017-03-07 07:11:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @test "mount" { | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch | 
					
						
							|  |  |  |   cid=$output | 
					
						
							|  |  |  |   run_buildah mount $cid | 
					
						
							|  |  |  |   root=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah unmount $cid | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah mount $cid | 
					
						
							|  |  |  |   root=$output | 
					
						
							| 
									
										
										
										
											2017-03-28 02:46:35 +08:00
										 |  |  |   touch $root/foobar | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah unmount $cid | 
					
						
							|  |  |  |   run_buildah rm $cid | 
					
						
							| 
									
										
										
										
											2017-03-07 07:11:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-16 05:25:05 +08:00
										 |  |  | @test "by-name" { | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --signature-policy ${TESTSDIR}/policy.json --name scratch-working-image-for-test scratch | 
					
						
							|  |  |  |   cid=$output | 
					
						
							|  |  |  |   run_buildah mount scratch-working-image-for-test | 
					
						
							|  |  |  |   root=$output | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah unmount scratch-working-image-for-test | 
					
						
							|  |  |  |   run_buildah rm scratch-working-image-for-test | 
					
						
							| 
									
										
										
										
											2017-03-16 05:25:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-07 07:11:40 +08:00
										 |  |  | @test "commit" { | 
					
						
							| 
									
										
										
										
											2017-03-25 00:49:22 +08:00
										 |  |  |   createrandom ${TESTDIR}/randomfile | 
					
						
							|  |  |  |   createrandom ${TESTDIR}/other-randomfile | 
					
						
							| 
									
										
										
										
											2017-03-07 07:11:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --signature-policy ${TESTSDIR}/policy.json scratch | 
					
						
							|  |  |  |   cid=$output | 
					
						
							|  |  |  |   run_buildah mount $cid | 
					
						
							|  |  |  |   root=$output | 
					
						
							| 
									
										
										
										
											2017-03-25 00:49:22 +08:00
										 |  |  |   cp ${TESTDIR}/randomfile $root/randomfile | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah unmount $cid | 
					
						
							|  |  |  |   run_buildah commit --iidfile output.iid --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image | 
					
						
							| 
									
										
										
										
											2018-04-25 22:00:46 +08:00
										 |  |  |   iid=$(cat output.iid) | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rmi $iid | 
					
						
							|  |  |  |   run_buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image | 
					
						
							|  |  |  |   run_buildah rm $cid | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json new-image | 
					
						
							|  |  |  |   newcid=$output | 
					
						
							|  |  |  |   run_buildah mount $newcid | 
					
						
							|  |  |  |   newroot=$output | 
					
						
							| 
									
										
										
										
											2017-03-25 00:49:22 +08:00
										 |  |  |   test -s $newroot/randomfile | 
					
						
							|  |  |  |   cmp ${TESTDIR}/randomfile $newroot/randomfile | 
					
						
							|  |  |  |   cp ${TESTDIR}/other-randomfile $newroot/other-randomfile | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah commit --signature-policy ${TESTSDIR}/policy.json $newcid containers-storage:other-new-image | 
					
						
							| 
									
										
										
										
											2017-03-25 00:49:22 +08:00
										 |  |  |   # Not an allowed ordering of arguments and flags.  Check that it's rejected. | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah 1 commit $newcid --signature-policy ${TESTSDIR}/policy.json containers-storage:rejected-new-image | 
					
						
							|  |  |  |   run_buildah commit --signature-policy ${TESTSDIR}/policy.json $newcid containers-storage:another-new-image | 
					
						
							|  |  |  |   run_buildah commit --signature-policy ${TESTSDIR}/policy.json $newcid yet-another-new-image | 
					
						
							|  |  |  |   run_buildah commit --signature-policy ${TESTSDIR}/policy.json $newcid containers-storage:gratuitous-new-image | 
					
						
							|  |  |  |   run_buildah unmount $newcid | 
					
						
							|  |  |  |   run_buildah rm $newcid | 
					
						
							| 
									
										
										
										
											2017-03-07 07:11:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json other-new-image | 
					
						
							|  |  |  |   othernewcid=$output | 
					
						
							|  |  |  |   run_buildah mount $othernewcid | 
					
						
							|  |  |  |   othernewroot=$output | 
					
						
							| 
									
										
										
										
											2017-03-25 00:49:22 +08:00
										 |  |  |   test -s $othernewroot/randomfile | 
					
						
							|  |  |  |   cmp ${TESTDIR}/randomfile $othernewroot/randomfile | 
					
						
							|  |  |  |   test -s $othernewroot/other-randomfile | 
					
						
							|  |  |  |   cmp ${TESTDIR}/other-randomfile $othernewroot/other-randomfile | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm $othernewcid | 
					
						
							| 
									
										
										
										
											2017-03-18 05:46:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json another-new-image | 
					
						
							|  |  |  |   anothernewcid=$output | 
					
						
							|  |  |  |   run_buildah mount $anothernewcid | 
					
						
							|  |  |  |   anothernewroot=$output | 
					
						
							| 
									
										
										
										
											2017-03-25 00:49:22 +08:00
										 |  |  |   test -s $anothernewroot/randomfile | 
					
						
							|  |  |  |   cmp ${TESTDIR}/randomfile $anothernewroot/randomfile | 
					
						
							|  |  |  |   test -s $anothernewroot/other-randomfile | 
					
						
							|  |  |  |   cmp ${TESTDIR}/other-randomfile $anothernewroot/other-randomfile | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rm $anothernewcid | 
					
						
							| 
									
										
										
										
											2017-03-18 05:46:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json yet-another-new-image | 
					
						
							|  |  |  |   yetanothernewcid=$output | 
					
						
							|  |  |  |   run_buildah mount $yetanothernewcid | 
					
						
							|  |  |  |   yetanothernewroot=$output | 
					
						
							| 
									
										
										
										
											2017-03-25 00:49:22 +08:00
										 |  |  |   test -s $yetanothernewroot/randomfile | 
					
						
							|  |  |  |   cmp ${TESTDIR}/randomfile $yetanothernewroot/randomfile | 
					
						
							|  |  |  |   test -s $yetanothernewroot/other-randomfile | 
					
						
							|  |  |  |   cmp ${TESTDIR}/other-randomfile $yetanothernewroot/other-randomfile | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah delete $yetanothernewcid | 
					
						
							| 
									
										
										
										
											2017-03-29 05:08:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 03:11:08 +08:00
										 |  |  |   run_buildah from --quiet --signature-policy ${TESTSDIR}/policy.json new-image | 
					
						
							|  |  |  |   newcid=$output | 
					
						
							| 
									
										
										
										
											2017-07-14 20:57:26 +08:00
										 |  |  |   buildah commit --rm --signature-policy ${TESTSDIR}/policy.json $newcid containers-storage:remove-container-image | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah 1 mount $newcid | 
					
						
							| 
									
										
										
										
											2017-07-14 20:57:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rmi remove-container-image | 
					
						
							|  |  |  |   run_buildah rmi containers-storage:other-new-image | 
					
						
							|  |  |  |   run_buildah rmi another-new-image | 
					
						
							| 
									
										
										
										
											2019-12-12 02:28:27 +08:00
										 |  |  |   run_buildah images -q | 
					
						
							| 
									
										
										
										
											2017-03-29 05:08:37 +08:00
										 |  |  |   [ "$output" != "" ] | 
					
						
							| 
									
										
										
										
											2019-04-02 05:56:29 +08:00
										 |  |  |   run_buildah rmi -a | 
					
						
							| 
									
										
										
										
											2019-12-12 02:28:27 +08:00
										 |  |  |   run_buildah images -q | 
					
						
							| 
									
										
										
										
											2019-04-05 23:59:54 +08:00
										 |  |  |   expect_output "" | 
					
						
							| 
									
										
										
										
											2017-03-07 07:11:40 +08:00
										 |  |  | } |