forked from vieter-v/vieter
				
			Containers now check whether package should be rebuilt
							parent
							
								
									540574b3c3
								
							
						
					
					
						commit
						a7cb08f93d
					
				
							
								
								
									
										16
									
								
								src/build.v
								
								
								
								
							
							
						
						
									
										16
									
								
								src/build.v
								
								
								
								
							|  | @ -81,9 +81,15 @@ fn build() ? { | |||
| 	image_id := create_build_image() ? | ||||
| 
 | ||||
| 	for repo in repos { | ||||
| 		// TODO what to do with PKGBUILDs that build multiple packages? | ||||
| 		commands := [ | ||||
| 			"su builder -c 'git clone --single-branch --depth 1 --branch $repo.branch $repo.url /build/repo'" | ||||
| 			'su builder -c \'cd /build/repo && MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $conf.address/publish; done\'' | ||||
| 			"git clone --single-branch --depth 1 --branch $repo.branch $repo.url repo" | ||||
| 			'cd repo' | ||||
| 			"makepkg --nobuild --nodeps" | ||||
| 			'source PKGBUILD' | ||||
| 			// The build container checks whether the package is already present on the server | ||||
| 			"curl --head --fail $conf.address/\$pkgname-\$pkgver-\$pkgrel-\$(uname -m).pkg.tar.zst && exit 0" | ||||
| 			'MAKEFLAGS="-j\$(nproc)" makepkg -s --noconfirm --needed && for pkg in \$(ls -1 *.pkg*); do curl -XPOST -T "\$pkg" -H "X-API-KEY: \$API_KEY" $conf.address/publish; done' | ||||
| 		] | ||||
| 
 | ||||
| 		// We convert the list of commands into a base64 string, which then gets | ||||
|  | @ -94,7 +100,9 @@ fn build() ? { | |||
| 			image: '$image_id' | ||||
| 			env: ['BUILD_SCRIPT=$cmds_str', 'API_KEY=$conf.api_key'] | ||||
| 			entrypoint: ['/bin/sh', '-c'] | ||||
| 			cmd: ['echo \$BUILD_SCRIPT | base64 -d | /bin/sh -e'] | ||||
| 			cmd: ['echo \$BUILD_SCRIPT | base64 -d | /bin/bash -e'] | ||||
| 			work_dir: '/build' | ||||
| 			user: 'builder:builder' | ||||
| 		} | ||||
| 
 | ||||
| 		id := docker.create_container(c) ? | ||||
|  | @ -112,7 +120,7 @@ fn build() ? { | |||
| 			time.sleep(5000000000) | ||||
| 		} | ||||
| 
 | ||||
| 		docker.remove_container(id) ? | ||||
| 		// docker.remove_container(id) ? | ||||
| 	} | ||||
| 
 | ||||
| 	// Finally, we remove the builder image | ||||
|  |  | |||
|  | @ -20,6 +20,8 @@ pub struct NewContainer { | |||
| 	entrypoint []string [json: Entrypoint] | ||||
| 	cmd        []string [json: Cmd] | ||||
| 	env        []string [json: Env] | ||||
| 	work_dir   string   [json:  WorkingDir] | ||||
| 	user string [json: User] | ||||
| } | ||||
| 
 | ||||
| struct CreatedContainer { | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ import repo | |||
| import time | ||||
| import rand | ||||
| import util | ||||
| import net.http | ||||
| 
 | ||||
| // healthcheck just returns a string, but can be used to quickly check if the | ||||
| // server is still responsive. | ||||
|  | @ -15,7 +16,7 @@ pub fn (mut app App) healthcheck() web.Result { | |||
| } | ||||
| 
 | ||||
| // get_root handles a GET request for a file on the root | ||||
| ['/:filename'; get] | ||||
| ['/:filename'; get; head] | ||||
| fn (mut app App) get_root(filename string) web.Result { | ||||
| 	mut full_path := '' | ||||
| 
 | ||||
|  | @ -27,6 +28,15 @@ fn (mut app App) get_root(filename string) web.Result { | |||
| 		full_path = os.join_path_single(app.repo.pkg_dir, filename) | ||||
| 	} | ||||
| 
 | ||||
| 	// Scuffed way to respond to HEAD requests | ||||
| 	if app.req.method == http.Method.head { | ||||
| 		if os.exists(full_path) { | ||||
| 			return app.ok('') | ||||
| 		} | ||||
| 
 | ||||
| 		return app.not_found() | ||||
| 	} | ||||
| 
 | ||||
| 	return app.file(full_path) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue