forked from vieter-v/vieter
Compare commits
No commits in common. "32b900a16b6ce2fa1bc37f0bdaf874ea47a03a16" and "25a7f9fd5130b2d56adba5bd80e92ac339429b9c" have entirely different histories.
32b900a16b
...
25a7f9fd51
|
|
@ -1,15 +0,0 @@
|
||||||
# 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"
|
|
||||||
|
|
@ -28,6 +28,7 @@ pipeline:
|
||||||
checksum:
|
checksum:
|
||||||
- md5
|
- md5
|
||||||
- sha256
|
- sha256
|
||||||
|
prerelease: true
|
||||||
title: ${CI_COMMIT_TAG}
|
title: ${CI_COMMIT_TAG}
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased](https://git.rustybever.be/Chewing_Bever/vieter)
|
## [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)
|
## [0.1.0-rc.1](https://git.rustybever.be/Chewing_Bever/vieter/src/tag/0.1.0-rc.1)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,7 @@ fn main() {
|
||||||
|
|
||||||
// This also creates the directories if needed
|
// This also creates the directories if needed
|
||||||
repo := repo.new(repo_dir, pkg_dir) or {
|
repo := repo.new(repo_dir, pkg_dir) or {
|
||||||
logger.error(err.msg)
|
exit_with_message(1, 'Failed to create required directories.')
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.mkdir_all(dl_dir) or { exit_with_message(1, 'Failed to create download directory.') }
|
os.mkdir_all(dl_dir) or { exit_with_message(1, 'Failed to create download directory.') }
|
||||||
|
|
|
||||||
|
|
@ -178,15 +178,10 @@ fn format_entry(key string, value string) string {
|
||||||
return '\n%$key%\n$value\n'
|
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'
|
|
||||||
}
|
|
||||||
|
|
||||||
// filename returns the correct filename of the package file
|
// filename returns the correct filename of the package file
|
||||||
pub fn (pkg &Pkg) filename() string {
|
pub fn (pkg &Pkg) filename() string {
|
||||||
|
p := pkg.info
|
||||||
|
|
||||||
ext := match pkg.compression {
|
ext := match pkg.compression {
|
||||||
0 { '.tar' }
|
0 { '.tar' }
|
||||||
1 { '.tar.gz' }
|
1 { '.tar.gz' }
|
||||||
|
|
@ -194,7 +189,7 @@ pub fn (pkg &Pkg) filename() string {
|
||||||
else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") }
|
else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") }
|
||||||
}
|
}
|
||||||
|
|
||||||
return '${pkg.full_name()}.pkg$ext'
|
return '$p.name-$p.version-${p.arch}.pkg$ext'
|
||||||
}
|
}
|
||||||
|
|
||||||
// to_desc returns a desc file valid string representation
|
// to_desc returns a desc file valid string representation
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,12 @@ module repo
|
||||||
import os
|
import os
|
||||||
import package
|
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 &
|
// Dummy struct to work around the fact that you can only share structs, maps &
|
||||||
// arrays
|
// arrays
|
||||||
pub struct Dummy {
|
pub struct Dummy {
|
||||||
|
|
@ -14,26 +20,20 @@ pub struct Repo {
|
||||||
mut:
|
mut:
|
||||||
mutex shared Dummy
|
mutex shared Dummy
|
||||||
pub:
|
pub:
|
||||||
// Where to store repository files
|
// Where to store repository files; should exist
|
||||||
repo_dir string [required]
|
repo_dir string [required]
|
||||||
// Where to find packages; packages are expected to all be in the same directory
|
// Where to find packages; packages are expected to all be in the same directory
|
||||||
pkg_dir string [required]
|
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
|
// new creates a new Repo & creates the directories as needed
|
||||||
pub fn new(repo_dir string, pkg_dir string) ?Repo {
|
pub fn new(repo_dir string, pkg_dir string) ?Repo {
|
||||||
if !os.is_dir(repo_dir) {
|
if !os.is_dir(repo_dir) {
|
||||||
os.mkdir_all(repo_dir) or { return error('Failed to create repo directory: $err.msg') }
|
os.mkdir_all(repo_dir) or { return error('Failed to create repo directory.') }
|
||||||
}
|
}
|
||||||
|
|
||||||
if !os.is_dir(pkg_dir) {
|
if !os.is_dir(pkg_dir) {
|
||||||
os.mkdir_all(pkg_dir) or { return error('Failed to create package directory: $err.msg') }
|
os.mkdir_all(pkg_dir) or { return error('Failed to create package directory.') }
|
||||||
}
|
}
|
||||||
|
|
||||||
return Repo{
|
return Repo{
|
||||||
|
|
@ -44,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
|
// add_from_path adds a package from an arbitrary path & moves it into the pkgs
|
||||||
// directory if necessary.
|
// directory if necessary.
|
||||||
pub fn (r &Repo) add_from_path(pkg_path string) ?RepoAddResult {
|
pub fn (r &Repo) add_from_path(pkg_path string) ?bool {
|
||||||
pkg := package.read_pkg(pkg_path) or { return error('Failed to read package file: $err.msg') }
|
pkg := package.read_pkg(pkg_path) or { return error('Failed to read package file: $err.msg') }
|
||||||
|
|
||||||
added := r.add(pkg) ?
|
added := r.add(pkg) ?
|
||||||
|
|
@ -59,10 +59,7 @@ pub fn (r &Repo) add_from_path(pkg_path string) ?RepoAddResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return RepoAddResult{
|
return added
|
||||||
added: added
|
|
||||||
pkg: &pkg
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add adds a given Pkg to the repository
|
// add adds a given Pkg to the repository
|
||||||
|
|
|
||||||
22
src/routes.v
22
src/routes.v
|
|
@ -25,8 +25,6 @@ fn is_pkg_name(s string) bool {
|
||||||
return s.contains('.pkg')
|
return s.contains('.pkg')
|
||||||
}
|
}
|
||||||
|
|
||||||
// healthcheck just returns a string, but can be used to quickly check if the
|
|
||||||
// server is still responsive.
|
|
||||||
['/health'; get]
|
['/health'; get]
|
||||||
pub fn (mut app App) healthcheck() web.Result {
|
pub fn (mut app App) healthcheck() web.Result {
|
||||||
return app.text('Healthy')
|
return app.text('Healthy')
|
||||||
|
|
@ -64,7 +62,7 @@ fn (mut app App) put_package() web.Result {
|
||||||
pkg_path = os.join_path_single(app.dl_dir, rand.uuid_v4())
|
pkg_path = os.join_path_single(app.dl_dir, rand.uuid_v4())
|
||||||
}
|
}
|
||||||
|
|
||||||
app.ldebug("Uploading $length bytes (${pretty_bytes(length.int())}) to '$pkg_path'.")
|
app.ldebug("Uploading $length (${pretty_bytes(length.int())}) bytes to '$pkg_path'.")
|
||||||
|
|
||||||
// This is used to time how long it takes to upload a file
|
// This is used to time how long it takes to upload a file
|
||||||
mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true })
|
mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true })
|
||||||
|
|
@ -82,22 +80,28 @@ fn (mut app App) put_package() web.Result {
|
||||||
return app.text("Content-Type header isn't set.")
|
return app.text("Content-Type header isn't set.")
|
||||||
}
|
}
|
||||||
|
|
||||||
res := app.repo.add_from_path(pkg_path) or {
|
added := app.repo.add_from_path(pkg_path) or {
|
||||||
app.lerror('Error while adding package: $err.msg')
|
app.lerror('Error while adding package: $err.msg')
|
||||||
|
|
||||||
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") }
|
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path'.") }
|
||||||
|
|
||||||
return app.text('Failed to add package.')
|
return app.text('Failed to add package.')
|
||||||
}
|
}
|
||||||
if !res.added {
|
if !added {
|
||||||
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg") }
|
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path'.") }
|
||||||
|
|
||||||
app.lwarn("Duplicate package '$res.pkg.full_name()'.")
|
app.lwarn('Duplicate package.')
|
||||||
|
|
||||||
return app.text('File already exists.')
|
return app.text('File already exists.')
|
||||||
}
|
}
|
||||||
|
|
||||||
app.linfo("Added '$res.pkg.full_name()' to repository.")
|
app.linfo("Added '$pkg_path' to repository.")
|
||||||
|
|
||||||
return app.text('Package added successfully.')
|
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('')
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -511,11 +511,8 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// The healthcheck spams the logs, which isn't very useful
|
lock app.logger {
|
||||||
if head.url != '/health' {
|
app.logger.debug('$head.method $head.url $head.version')
|
||||||
lock app.logger {
|
|
||||||
app.logger.debug('$head.method $head.url $head.version')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// req := http.parse_request(mut reader) or {
|
// req := http.parse_request(mut reader) or {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue