From 65f113cdeeb0bc35dc620f68af0bdc92fa90f3fd Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 9 Jan 2022 09:29:11 +0100 Subject: [PATCH] Added Dockerfile & beginning of vweb server --- .dockerignore | 3 +++ .gitignore | 3 +++ Dockerfile | 15 ++++++++++++++ Makefile | 7 +++++++ pieter/main.v | 11 ---------- {pieter => vieter}/fibonacci.v | 0 vieter/main.v | 37 ++++++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile delete mode 100644 pieter/main.v rename {pieter => vieter}/fibonacci.v (100%) create mode 100644 vieter/main.v diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4bfc405 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +* + +!vieter/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e07ad95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.c +data/ +vieter/vieter diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a3f0b30 --- /dev/null +++ b/Dockerfile @@ -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" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8270706 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: run +run: + API_KEY=test REPO_DIR=data v run vieter + +.PHONY: fmt +fmt: + v fmt -w vieter diff --git a/pieter/main.v b/pieter/main.v deleted file mode 100644 index 76ebcd7..0000000 --- a/pieter/main.v +++ /dev/null @@ -1,11 +0,0 @@ -module main - -import fibonacci - -fn main() { - println('Hello, world!') - - for i in 1 .. 35 { - println('$i - ${fibonacci.fib(i)}') - } -} diff --git a/pieter/fibonacci.v b/vieter/fibonacci.v similarity index 100% rename from pieter/fibonacci.v rename to vieter/fibonacci.v diff --git a/vieter/main.v b/vieter/main.v new file mode 100644 index 0000000..cc930c4 --- /dev/null +++ b/vieter/main.v @@ -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) +}