github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/test/sealer_build_test.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package test 16 17 import ( 18 "os" 19 "path/filepath" 20 21 "github.com/sealerio/sealer/test/suites/build" 22 "github.com/sealerio/sealer/test/suites/image" 23 "github.com/sealerio/sealer/test/suites/registry" 24 "github.com/sealerio/sealer/test/testhelper" 25 "github.com/sealerio/sealer/test/testhelper/settings" 26 27 . "github.com/onsi/ginkgo" 28 ) 29 30 var _ = Describe("sealer build", func() { 31 32 Context("testing build with cmds", func() { 33 BeforeEach(func() { 34 buildPath := filepath.Join(build.WithCmdsBuildDir()) 35 err := os.Chdir(buildPath) 36 testhelper.CheckErr(err) 37 }) 38 AfterEach(func() { 39 err := os.Chdir(settings.DefaultTestEnvDir) 40 testhelper.CheckErr(err) 41 }) 42 43 It("start to build with cmds", func() { 44 imageName := build.GetBuildImageName() 45 cmd := build.NewArgsOfBuild(). 46 SetKubeFile("Kubefile"). 47 SetImageName(imageName). 48 SetContext("."). 49 String() 50 sess, err := testhelper.Start(cmd) 51 testhelper.CheckErr(err) 52 testhelper.CheckExit0(sess, settings.MaxWaiteTime) 53 54 // check: sealer images whether image exist 55 testhelper.CheckBeTrue(build.CheckIsImageExist(imageName)) 56 57 //TODO check image spec content 58 // 1. launch cmds 59 // 2. containerImageList: 60 //docker.io/library/nginx:alpine 61 //docker.io/library/busybox:latest 62 63 // clean: build image 64 image.DoImageOps("rmi", imageName) 65 }) 66 67 }) 68 69 Context("testing build with launch", func() { 70 BeforeEach(func() { 71 buildPath := filepath.Join(build.WithLaunchBuildDir()) 72 err := os.Chdir(buildPath) 73 testhelper.CheckErr(err) 74 }) 75 AfterEach(func() { 76 err := os.Chdir(settings.DefaultTestEnvDir) 77 testhelper.CheckErr(err) 78 }) 79 80 It("start to build with launch", func() { 81 imageName := build.GetBuildImageName() 82 cmd := build.NewArgsOfBuild(). 83 SetKubeFile("Kubefile"). 84 SetImageName(imageName). 85 SetContext("."). 86 String() 87 sess, err := testhelper.Start(cmd) 88 testhelper.CheckErr(err) 89 testhelper.CheckExit0(sess, settings.MaxWaiteTime) 90 91 // check: sealer images whether image exist 92 testhelper.CheckBeTrue(build.CheckIsImageExist(imageName)) 93 94 //TODO check image spec content 95 // 1. launch app names 96 // 2. containerImageList: 97 //docker.io/library/nginx:alpine 98 //docker.io/library/busybox:latest 99 100 // clean: build image 101 image.DoImageOps("rmi", imageName) 102 }) 103 104 }) 105 106 Context("testing build with app cmds", func() { 107 BeforeEach(func() { 108 buildPath := filepath.Join(build.WithAPPCmdsBuildDir()) 109 err := os.Chdir(buildPath) 110 testhelper.CheckErr(err) 111 }) 112 AfterEach(func() { 113 err := os.Chdir(settings.DefaultTestEnvDir) 114 testhelper.CheckErr(err) 115 }) 116 117 It("start to build with app cmds", func() { 118 imageName := build.GetBuildImageName() 119 cmd := build.NewArgsOfBuild(). 120 SetKubeFile("Kubefile"). 121 SetImageName(imageName). 122 SetContext("."). 123 String() 124 sess, err := testhelper.Start(cmd) 125 testhelper.CheckErr(err) 126 testhelper.CheckExit0(sess, settings.MaxWaiteTime) 127 128 // check: sealer images whether image exist 129 testhelper.CheckBeTrue(build.CheckIsImageExist(imageName)) 130 131 //TODO check image spec content 132 // 1. launch app names 133 // 2. launch app cmds: 134 135 // clean: build image 136 image.DoImageOps("rmi", imageName) 137 }) 138 139 }) 140 141 Context("testing build with --image-list flag", func() { 142 BeforeEach(func() { 143 buildPath := filepath.Join(build.WithImageListFlagBuildDir()) 144 err := os.Chdir(buildPath) 145 testhelper.CheckErr(err) 146 }) 147 AfterEach(func() { 148 err := os.Chdir(settings.DefaultTestEnvDir) 149 testhelper.CheckErr(err) 150 }) 151 152 It("start to build with --image-list flag", func() { 153 imageName := build.GetBuildImageName() 154 cmd := build.NewArgsOfBuild(). 155 SetKubeFile("Kubefile"). 156 SetImageName(imageName). 157 SetImageList("imagelist"). 158 SetContext("."). 159 String() 160 sess, err := testhelper.Start(cmd) 161 testhelper.CheckErr(err) 162 testhelper.CheckExit0(sess, settings.MaxWaiteTime) 163 164 // check: sealer images whether image exist 165 testhelper.CheckBeTrue(build.CheckIsImageExist(imageName)) 166 167 //TODO check image spec content 168 // 2. containerImageList: 169 //docker.io/library/nginx:alpine 170 //docker.io/library/busybox:latest 171 172 // clean: build image 173 image.DoImageOps("rmi", imageName) 174 }) 175 176 }) 177 178 Context("testing multi platform build scenario", func() { 179 180 BeforeEach(func() { 181 registry.Login() 182 buildPath := filepath.Join(build.WithMultiArchBuildDir()) 183 err := os.Chdir(buildPath) 184 testhelper.CheckErr(err) 185 186 }) 187 AfterEach(func() { 188 registry.Logout() 189 err := os.Chdir(settings.DefaultTestEnvDir) 190 testhelper.CheckErr(err) 191 }) 192 193 It("multi build only with amd64", func() { 194 imageName := build.GetBuildImageName() 195 cmd := build.NewArgsOfBuild(). 196 SetKubeFile("Kubefile"). 197 SetImageName(imageName). 198 SetPlatforms([]string{"linux/amd64"}). 199 SetContext("."). 200 String() 201 sess, err := testhelper.Start(cmd) 202 203 testhelper.CheckErr(err) 204 testhelper.CheckExit0(sess, settings.MaxWaiteTime) 205 206 // check: sealer images whether image exist 207 testhelper.CheckBeTrue(build.CheckIsImageExist(imageName)) 208 209 // check: push build image 210 image.DoImageOps("push", imageName) 211 212 // clean: build image 213 image.DoImageOps("rmi", imageName) 214 215 }) 216 217 It("multi build only with arm64", func() { 218 imageName := build.GetBuildImageName() 219 cmd := build.NewArgsOfBuild(). 220 SetKubeFile("Kubefile"). 221 SetImageName(imageName). 222 SetPlatforms([]string{"linux/arm64"}). 223 SetContext("."). 224 String() 225 sess, err := testhelper.Start(cmd) 226 testhelper.CheckErr(err) 227 testhelper.CheckExit0(sess, settings.MaxWaiteTime) 228 // check: sealer images whether image exist 229 testhelper.CheckBeTrue(build.CheckIsMultiArchImageExist(imageName)) 230 231 // check: push build image 232 image.DoImageOps("push", imageName) 233 234 // clean: build image 235 image.DoImageOps("rmi", imageName) 236 }) 237 238 It("multi build with amd64 and arm64", func() { 239 imageName := build.GetBuildImageName() 240 cmd := build.NewArgsOfBuild(). 241 SetKubeFile("Kubefile"). 242 SetImageName(imageName). 243 SetPlatforms([]string{"linux/amd64", "linux/arm64"}). 244 SetContext("."). 245 String() 246 sess, err := testhelper.Start(cmd) 247 testhelper.CheckErr(err) 248 testhelper.CheckExit0(sess, settings.MaxWaiteTime) 249 // check: sealer images whether image exist 250 testhelper.CheckBeTrue(build.CheckIsMultiArchImageExist(imageName)) 251 252 // check: push build image 253 image.DoImageOps("push", imageName) 254 255 // clean: build image 256 image.DoImageOps("rmi", imageName) 257 }) 258 259 }) 260 261 })