From 27f59c6664e7b4fbb15e3b49735c55417f9f7605 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 22 Feb 2022 08:14:20 +0100 Subject: [PATCH] Updated CI Dockerfile; fixed formatting & vet --- Dockerfile.ci | 7 ++++--- Makefile | 3 +++ src/build.v | 3 +-- src/env.v | 9 ++++++--- src/server/git.v | 6 +++--- src/server/server.v | 1 + src/util.v | 3 +++ 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Dockerfile.ci b/Dockerfile.ci index e0dd5dab..a062d951 100644 --- a/Dockerfile.ci +++ b/Dockerfile.ci @@ -24,9 +24,10 @@ RUN curl --fail \ FROM busybox:1.35.0 ENV PATH=/bin \ - REPO_DIR=/data/repo \ - PKG_DIR=/data/pkgs \ - DOWNLOAD_DIR=/data/downloads + VIETER_REPO_DIR=/data/repo \ + VIETER_PKG_DIR=/data/pkgs \ + VIETER_DOWNLOAD_DIR=/data/downloads \ + VIETER_REPOS_FILE=/data/repos.json COPY --from=builder /app/dumb-init /app/vieter /bin/ diff --git a/Makefile b/Makefile index b1b91f2b..062a47f8 100644 --- a/Makefile +++ b/Makefile @@ -13,11 +13,14 @@ vieter: $(SOURCES) $(V) -g -o vieter $(SRC_DIR) # Debug build using gcc +# The debug build can't use the boehm garbage collector, as that is +# multi-threaded and causes issues when running vieter inside gdb. .PHONY: debug debug: dvieter dvieter: $(SOURCES) $(V_PATH) -showcc -keepc -cg -o dvieter $(SRC_DIR) +# Run the debug build inside gdb .PHONY: gdb gdb: dvieter VIETER_API_KEY=test \ diff --git a/src/build.v b/src/build.v index ab72a592..fc1fe6ff 100644 --- a/src/build.v +++ b/src/build.v @@ -4,7 +4,6 @@ import docker import encoding.base64 import rand import time -import os import json import server import env @@ -16,7 +15,7 @@ fn build() ? { conf := env.load() ? // We get the repos list from the Vieter instance - mut req := http.new_request(http.Method.get, '${conf.address}/api/repos', '') ? + mut req := http.new_request(http.Method.get, '$conf.address/api/repos', '') ? req.add_custom_header('X-Api-Key', conf.api_key) ? res := req.do() ? diff --git a/src/env.v b/src/env.v index 8b92d8dc..bd544cfc 100644 --- a/src/env.v +++ b/src/env.v @@ -22,8 +22,8 @@ pub: pub struct BuildConfig { pub: - api_key string - address string + api_key string + address string } fn get_env_var(field_name string) ?string { @@ -56,7 +56,10 @@ fn get_env_var(field_name string) ?string { } } -// load attempts to create the given type from environment variables. +// load attempts to create the given type from environment variables. For +// each field, the corresponding env var is its name in uppercase prepended +// with the hardcoded prefix. If this one isn't present, it looks for the env +// var with the file_suffix suffix. pub fn load() ?T { res := T{} diff --git a/src/server/git.v b/src/server/git.v index d506c7e9..0147d878 100644 --- a/src/server/git.v +++ b/src/server/git.v @@ -42,7 +42,7 @@ fn write_repos(path string, repos []GitRepo) ? { } ['/api/repos'; get] -pub fn (mut app App) get_repos() web.Result { +fn (mut app App) get_repos() web.Result { if !app.is_authorized() { return app.text('Unauthorized.') } @@ -59,7 +59,7 @@ pub fn (mut app App) get_repos() web.Result { } ['/api/repos'; post] -pub fn (mut app App) post_repo() web.Result { +fn (mut app App) post_repo() web.Result { if !app.is_authorized() { return app.text('Unauthorized.') } @@ -98,7 +98,7 @@ pub fn (mut app App) post_repo() web.Result { } ['/api/repos'; delete] -pub fn (mut app App) delete_repo() web.Result { +fn (mut app App) delete_repo() web.Result { if !app.is_authorized() { return app.text('Unauthorized.') } diff --git a/src/server/server.v b/src/server/server.v index ebb9f3bb..4b31b99e 100644 --- a/src/server/server.v +++ b/src/server/server.v @@ -19,6 +19,7 @@ pub mut: git_mutex shared util.Dummy } +// server starts the web server & starts listening for requests pub fn server() ? { conf := env.load() ? diff --git a/src/util.v b/src/util.v index 24d33fca..49c9d223 100644 --- a/src/util.v +++ b/src/util.v @@ -15,12 +15,15 @@ pub struct Dummy { x int } +// exit_with_message exits the program with a given status code after having +// first printed a specific message to STDERR [noreturn] pub fn exit_with_message(code int, msg string) { eprintln(msg) exit(code) } +// reader_to_file writes the contents of a BufferedReader to a file pub fn reader_to_file(mut reader io.BufferedReader, length int, path string) ? { mut file := os.create(path) ? defer {