From 25a7f9fd5130b2d56adba5bd80e92ac339429b9c Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 1 Feb 2022 00:17:56 +0100 Subject: [PATCH 1/7] Updated changelog [CI SKIP] --- .woodpecker/.gitea.yml | 2 +- CHANGELOG.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.woodpecker/.gitea.yml b/.woodpecker/.gitea.yml index 7e2a7cbf..7fda6d97 100644 --- a/.woodpecker/.gitea.yml +++ b/.woodpecker/.gitea.yml @@ -25,7 +25,7 @@ pipeline: settings: base_url: https://git.rustybever.be files: ${CI_COMMIT_SHA}/* - checksums: + checksum: - md5 - sha256 prerelease: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 017cbffa..397a1a10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://git.rustybever.be/Chewing_Bever/vieter) +## [0.1.0-rc.1](https://git.rustybever.be/Chewing_Bever/vieter/src/tag/0.1.0-rc.1) + ### Added * Ability to publish packages From c3cacee55d603733f6b322b911a4bac87883eb0e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 1 Feb 2022 22:47:29 +0100 Subject: [PATCH 2/7] Added deploy webhook --- .woodpecker/.deploy.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .woodpecker/.deploy.yml diff --git a/.woodpecker/.deploy.yml b/.woodpecker/.deploy.yml new file mode 100644 index 00000000..56e6c2f9 --- /dev/null +++ b/.woodpecker/.deploy.yml @@ -0,0 +1,15 @@ +# Deploys the newest development image to my server +branches: [dev] +platform: linux/amd64 +depends_on: + - docker + +skip_clone: true + +pipeline: + webhook: + image: chewingbever/vlang:latest + secrets: + - webhook + commands: + - curl -XPOST -s "$WEBHOOK" From eb91e73510c46571a29e109691ac7d6c40eef0bf Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 2 Feb 2022 13:09:03 +0100 Subject: [PATCH 3/7] Some slight log improvements --- src/main.v | 3 ++- src/repo/repo.v | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main.v b/src/main.v index c3c5ed95..59f6941e 100644 --- a/src/main.v +++ b/src/main.v @@ -88,7 +88,8 @@ fn main() { // This also creates the directories if needed repo := repo.new(repo_dir, pkg_dir) or { - exit_with_message(1, 'Failed to create required directories.') + logger.error(err.msg) + exit(1) } os.mkdir_all(dl_dir) or { exit_with_message(1, 'Failed to create download directory.') } diff --git a/src/repo/repo.v b/src/repo/repo.v index ded30ba3..1fdcc60e 100644 --- a/src/repo/repo.v +++ b/src/repo/repo.v @@ -3,12 +3,6 @@ module repo import os import package -// subpath where the uncompressed version of the files archive is stored -const files_subpath = 'files' - -// subpath where the uncompressed version of the repo archive is stored -const repo_subpath = 'repo' - // Dummy struct to work around the fact that you can only share structs, maps & // arrays pub struct Dummy { @@ -20,7 +14,7 @@ pub struct Repo { mut: mutex shared Dummy pub: - // Where to store repository files; should exist + // Where to store repository files repo_dir string [required] // Where to find packages; packages are expected to all be in the same directory pkg_dir string [required] @@ -29,11 +23,11 @@ pub: // new creates a new Repo & creates the directories as needed pub fn new(repo_dir string, pkg_dir string) ?Repo { if !os.is_dir(repo_dir) { - os.mkdir_all(repo_dir) or { return error('Failed to create repo directory.') } + os.mkdir_all(repo_dir) or { return error('Failed to create repo directory: $err.msg') } } if !os.is_dir(pkg_dir) { - os.mkdir_all(pkg_dir) or { return error('Failed to create package directory.') } + os.mkdir_all(pkg_dir) or { return error('Failed to create package directory: $err.msg') } } return Repo{ From 3ad960fd5928adfb623698693ddf78c003077adb Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 2 Feb 2022 13:10:55 +0100 Subject: [PATCH 4/7] Filter healthcheck out of logs --- src/web/web.v | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/web/web.v b/src/web/web.v index bbb909f4..9621a2d6 100644 --- a/src/web/web.v +++ b/src/web/web.v @@ -511,9 +511,12 @@ fn handle_conn(mut conn net.TcpConn, mut app T, routes map[string]Route) { return } - lock app.logger { - app.logger.debug('$head.method $head.url $head.version') - } + // The healthcheck spams the logs, which isn't very useful + if head.url != '/health' { + lock app.logger { + app.logger.debug('$head.method $head.url $head.version') + } + } // req := http.parse_request(mut reader) or { // // Prevents errors from being thrown when BufferedReader is empty From a29592ef36a91931eadf505c88c66b3dea246a2c Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 2 Feb 2022 13:24:31 +0100 Subject: [PATCH 5/7] Logs now show names of added packages --- src/main.v | 4 ++-- src/package.v | 9 ++++++--- src/repo/repo.v | 13 +++++++++++-- src/routes.v | 20 +++++++------------- src/web/web.v | 12 ++++++------ 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main.v b/src/main.v index 59f6941e..cddd9aec 100644 --- a/src/main.v +++ b/src/main.v @@ -88,8 +88,8 @@ fn main() { // This also creates the directories if needed repo := repo.new(repo_dir, pkg_dir) or { - logger.error(err.msg) - exit(1) + logger.error(err.msg) + exit(1) } os.mkdir_all(dl_dir) or { exit_with_message(1, 'Failed to create download directory.') } diff --git a/src/package.v b/src/package.v index 03103c98..34350ecd 100644 --- a/src/package.v +++ b/src/package.v @@ -178,10 +178,13 @@ fn format_entry(key string, value string) string { return '\n%$key%\n$value\n' } +pub fn (pkg &Pkg) full_name() string { + p := pkg.info + return '$p.name-$p.version-$p.arch' +} + // filename returns the correct filename of the package file pub fn (pkg &Pkg) filename() string { - p := pkg.info - ext := match pkg.compression { 0 { '.tar' } 1 { '.tar.gz' } @@ -189,7 +192,7 @@ pub fn (pkg &Pkg) filename() string { else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") } } - return '$p.name-$p.version-${p.arch}.pkg$ext' + return '${pkg.full_name()}.pkg$ext' } // to_desc returns a desc file valid string representation diff --git a/src/repo/repo.v b/src/repo/repo.v index 1fdcc60e..554b744c 100644 --- a/src/repo/repo.v +++ b/src/repo/repo.v @@ -20,6 +20,12 @@ pub: pkg_dir string [required] } +pub struct RepoAddResult { +pub: + added bool [required] + pkg &package.Pkg [required] +} + // new creates a new Repo & creates the directories as needed pub fn new(repo_dir string, pkg_dir string) ?Repo { if !os.is_dir(repo_dir) { @@ -38,7 +44,7 @@ pub fn new(repo_dir string, pkg_dir string) ?Repo { // add_from_path adds a package from an arbitrary path & moves it into the pkgs // directory if necessary. -pub fn (r &Repo) add_from_path(pkg_path string) ?bool { +pub fn (r &Repo) add_from_path(pkg_path string) ?RepoAddResult { pkg := package.read_pkg(pkg_path) or { return error('Failed to read package file: $err.msg') } added := r.add(pkg) ? @@ -53,7 +59,10 @@ pub fn (r &Repo) add_from_path(pkg_path string) ?bool { } } - return added + return RepoAddResult{ + added: added + pkg: &pkg + } } // add adds a given Pkg to the repository diff --git a/src/routes.v b/src/routes.v index 45e7fa55..13cc8c76 100644 --- a/src/routes.v +++ b/src/routes.v @@ -62,7 +62,7 @@ fn (mut app App) put_package() web.Result { pkg_path = os.join_path_single(app.dl_dir, rand.uuid_v4()) } - app.ldebug("Uploading $length (${pretty_bytes(length.int())}) bytes to '$pkg_path'.") + app.ldebug("Uploading $length bytes (${pretty_bytes(length.int())}) to '$pkg_path'.") // This is used to time how long it takes to upload a file mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true }) @@ -80,28 +80,22 @@ fn (mut app App) put_package() web.Result { return app.text("Content-Type header isn't set.") } - added := app.repo.add_from_path(pkg_path) or { + res := app.repo.add_from_path(pkg_path) or { app.lerror('Error while adding package: $err.msg') - os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path'.") } + os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") } return app.text('Failed to add package.') } - if !added { - os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path'.") } + if !res.added { + os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") } - app.lwarn('Duplicate package.') + app.lwarn("Duplicate package '$res.pkg.full_name()'.") return app.text('File already exists.') } - app.linfo("Added '$pkg_path' to repository.") + app.linfo("Added '$res.pkg.full_name()' to repository.") return app.text('Package added successfully.') } - -// add_package PUT a new package to the server -['/add'; put] -pub fn (mut app App) add_package() web.Result { - return app.text('') -} diff --git a/src/web/web.v b/src/web/web.v index 9621a2d6..b1e8b92a 100644 --- a/src/web/web.v +++ b/src/web/web.v @@ -511,12 +511,12 @@ fn handle_conn(mut conn net.TcpConn, mut app T, routes map[string]Route) { return } - // The healthcheck spams the logs, which isn't very useful - if head.url != '/health' { - lock app.logger { - app.logger.debug('$head.method $head.url $head.version') - } - } + // The healthcheck spams the logs, which isn't very useful + if head.url != '/health' { + lock app.logger { + app.logger.debug('$head.method $head.url $head.version') + } + } // req := http.parse_request(mut reader) or { // // Prevents errors from being thrown when BufferedReader is empty From eb57febdd31388a268931b2c6b72b8b71ae6878e Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 2 Feb 2022 13:34:28 +0100 Subject: [PATCH 6/7] We must please make vet --- .woodpecker/.gitea.yml | 1 - CHANGELOG.md | 2 ++ src/package.v | 2 ++ src/routes.v | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.woodpecker/.gitea.yml b/.woodpecker/.gitea.yml index 7fda6d97..c492d345 100644 --- a/.woodpecker/.gitea.yml +++ b/.woodpecker/.gitea.yml @@ -28,7 +28,6 @@ pipeline: checksum: - md5 - sha256 - prerelease: true title: ${CI_COMMIT_TAG} when: event: tag diff --git a/CHANGELOG.md b/CHANGELOG.md index 397a1a10..80781dd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://git.rustybever.be/Chewing_Bever/vieter) +* Improved logging + ## [0.1.0-rc.1](https://git.rustybever.be/Chewing_Bever/vieter/src/tag/0.1.0-rc.1) ### Added diff --git a/src/package.v b/src/package.v index 34350ecd..4e3b97f8 100644 --- a/src/package.v +++ b/src/package.v @@ -178,6 +178,8 @@ fn format_entry(key string, value string) string { return '\n%$key%\n$value\n' } +// full_name returns the properly formatted name for the package, including +// version & architecture pub fn (pkg &Pkg) full_name() string { p := pkg.info return '$p.name-$p.version-$p.arch' diff --git a/src/routes.v b/src/routes.v index 13cc8c76..8b7ddebe 100644 --- a/src/routes.v +++ b/src/routes.v @@ -25,6 +25,8 @@ fn is_pkg_name(s string) bool { return s.contains('.pkg') } +// healthcheck just returns a string, but can be used to quickly check if the +// server is still responsive. ['/health'; get] pub fn (mut app App) healthcheck() web.Result { return app.text('Healthy') From b72e9ad49bf1994732416d9e08976779450c484c Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 2 Feb 2022 13:55:05 +0100 Subject: [PATCH 7/7] Updated changelog [CI SKIP] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80781dd2..3824088c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://git.rustybever.be/Chewing_Bever/vieter) +## [0.1.0](https://git.rustybever.be/Chewing_Bever/vieter/src/tag/0.1.0) + +### Changed + * Improved logging ## [0.1.0-rc.1](https://git.rustybever.be/Chewing_Bever/vieter/src/tag/0.1.0-rc.1)