forked from vieter-v/vieter
				
			Added Dockerfile & beginning of vweb server
							parent
							
								
									9a09db0485
								
							
						
					
					
						commit
						65f113cdee
					
				|  | @ -0,0 +1,3 @@ | ||||||
|  | * | ||||||
|  | 
 | ||||||
|  | !vieter/ | ||||||
|  | @ -0,0 +1,3 @@ | ||||||
|  | *.c | ||||||
|  | data/ | ||||||
|  | vieter/vieter | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | FROM thevlang/vlang:alpine-dev AS builder | ||||||
|  | 
 | ||||||
|  | WORKDIR /src | ||||||
|  | COPY vieter ./vieter | ||||||
|  | 
 | ||||||
|  | RUN v -prod vieter | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | FROM alpine:3.15.0 | ||||||
|  | 
 | ||||||
|  | ENV REPO_DIR=/data | ||||||
|  | 
 | ||||||
|  | COPY --from=builder /src/vieter/vieter /usr/local/bin/ | ||||||
|  | 
 | ||||||
|  | ENTRYPOINT [ "/usr/local/bin/vieter" ] | ||||||
|  | @ -0,0 +1,7 @@ | ||||||
|  | .PHONY: run | ||||||
|  | run: | ||||||
|  | 	API_KEY=test REPO_DIR=data v run vieter | ||||||
|  | 
 | ||||||
|  | .PHONY: fmt | ||||||
|  | fmt: | ||||||
|  | 	v fmt -w vieter | ||||||
|  | @ -1,11 +0,0 @@ | ||||||
| module main |  | ||||||
| 
 |  | ||||||
| import fibonacci |  | ||||||
| 
 |  | ||||||
| fn main() { |  | ||||||
| 	println('Hello, world!') |  | ||||||
| 
 |  | ||||||
| 	for i in 1 .. 35 { |  | ||||||
| 		println('$i - ${fibonacci.fib(i)}') |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  | @ -0,0 +1,37 @@ | ||||||
|  | module main | ||||||
|  | 
 | ||||||
|  | import vweb | ||||||
|  | import os | ||||||
|  | 
 | ||||||
|  | const port = 8000 | ||||||
|  | 
 | ||||||
|  | struct App { | ||||||
|  | 	vweb.Context | ||||||
|  | 	api_key  string [required] | ||||||
|  | 	repo_dir string [required] | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | [noreturn] | ||||||
|  | fn exit_with_message(code int, msg string) { | ||||||
|  | 	eprintln(msg) | ||||||
|  | 	exit(code) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | fn main() { | ||||||
|  | 	key := os.getenv_opt('API_KEY') or { exit_with_message(1, 'No API key was provided.') } | ||||||
|  | 	repo_dir := os.getenv_opt('REPO_DIR') or { | ||||||
|  | 		exit_with_message(1, 'No repo directory was configured.') | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// We create the upload directory during startup | ||||||
|  | 	if !os.is_dir(repo_dir) { | ||||||
|  | 		os.mkdir_all(repo_dir) or { exit_with_message(2, 'Failed to create repo directory.') } | ||||||
|  | 
 | ||||||
|  | 		println('Repo directory created.') | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	vweb.run(&App{ | ||||||
|  | 		api_key: key | ||||||
|  | 		repo_dir: repo_dir | ||||||
|  | 	}, port) | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue