Added Dockerfile & beginning of vweb server

main
Jef Roosens 2022-01-09 09:29:11 +01:00
parent 9a09db0485
commit 65f113cdee
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
7 changed files with 65 additions and 11 deletions

3
.dockerignore 100644
View File

@ -0,0 +1,3 @@
*
!vieter/

3
.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
*.c
data/
vieter/vieter

15
Dockerfile 100644
View File

@ -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" ]

7
Makefile 100644
View File

@ -0,0 +1,7 @@
.PHONY: run
run:
API_KEY=test REPO_DIR=data v run vieter
.PHONY: fmt
fmt:
v fmt -w vieter

View File

@ -1,11 +0,0 @@
module main
import fibonacci
fn main() {
println('Hello, world!')
for i in 1 .. 35 {
println('$i - ${fibonacci.fib(i)}')
}
}

37
vieter/main.v 100644
View File

@ -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)
}