Added system/info endpoint, implement tagging

This commit is contained in:
2025-04-13 09:11:52 -04:00
parent c354ea6d78
commit d5bc4cafb8
17 changed files with 143 additions and 22 deletions

View File

@@ -1,8 +1,8 @@
#!make
SHELL := /bin/bash
export API_VERSION = $(shell awk -F ' = ' '$$1 ~ /package.version/ { gsub(/[\"]/, "", $$2); printf("%s",$$2) }' api/Cargo.toml)
export UI_VERSION := $(shell awk -F'"' '/"version"/ { print $$4 }' ui/package.json)
export API_VERSION = $(shell sed -n 's/^version *= *"\([^"]*\)".*/\1/p' api/Cargo.toml)
export UI_VERSION=$(shell sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' ui/package.json)
include .env
-include .env.local
@@ -128,3 +128,6 @@ push: ## Build and push a specific docker image (`make push f=httpd`)
cert: domain=$(if $(d),$(d),${NGINX_HOST})
cert: ## Generate a cert for the given domain
./scripts/generate_cert.sh ${domain}
tag: ## Tag the commits based on versions
@./scripts/tag.sh

2
api/Cargo.lock generated
View File

@@ -366,7 +366,7 @@ dependencies = [
[[package]]
name = "api"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"actix-cors",
"actix-multipart",

View File

@@ -1,6 +1,6 @@
[package]
name = "api"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Ben Sherriff <hello@bensherriff.com>"]
repository = "https://github.com/bensherriff/aviation-weather"

View File

@@ -6,11 +6,11 @@ use rand::distr::Alphanumeric;
use rand::prelude::*;
use rand_chacha::ChaCha20Rng;
mod model;
mod auth;
mod routes;
mod session;
pub use model::*;
pub use auth::*;
pub use session::*;
pub use routes::init_routes;

View File

@@ -1,11 +1,11 @@
use actix_web::{post, web, HttpResponse, ResponseError, HttpRequest, put, get};
use crate::{
auth::{verify_hash, Session, SESSION_COOKIE_NAME},
account::{verify_hash, Session, SESSION_COOKIE_NAME},
error::Error,
users::{LoginRequest, RegisterRequest, User, UserResponse},
};
use crate::auth::Auth;
use crate::account::Auth;
use crate::users::UpdateUser;
#[post("/register")]

View File

@@ -3,7 +3,7 @@ use futures_util::stream::StreamExt as _;
use crate::{
airports::Airport,
db::Paged,
auth::{Auth, verify_role},
account::{Auth, verify_role},
AppState,
};
use actix_multipart::Multipart;

View File

@@ -4,15 +4,16 @@ use actix_cors::Cors;
use actix_web::{App, HttpServer, middleware::Logger, web};
use dotenv::from_filename;
use reqwest::Certificate;
use crate::auth::hash;
use crate::account::hash;
use crate::users::{User, ADMIN_ROLE};
mod account;
mod airports;
mod auth;
mod db;
mod error;
mod metars;
mod scheduler;
mod system;
mod users;
#[derive(Debug, Clone)]
@@ -71,7 +72,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let state = AppState { client };
let host = "0.0.0.0";
let port = env::var("API_PORT").unwrap_or("5000".to_string());
let port = "5000";
let server = match HttpServer::new(move || {
let cors = Cors::default()
@@ -88,8 +89,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
web::scope("api")
.configure(airports::init_routes)
.configure(metars::init_routes)
.configure(auth::init_routes)
.configure(users::init_routes),
.configure(account::init_routes)
.configure(users::init_routes)
.configure(system::init_routes),
)
})
.bind(format!("{}:{}", host, port))

31
api/src/system/mod.rs Normal file
View File

@@ -0,0 +1,31 @@
use std::env;
use actix_web::{get, web, HttpResponse};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct SystemInfo {
version: String,
healthy: bool,
}
#[get("/info")]
async fn info() -> HttpResponse {
let mut healthy = true;
let version = match env::var("API_VERSION") {
Ok(v) => v,
Err(_) => {
healthy = false;
String::from("unknown")
}
};
dbg!(&version);
let info = SystemInfo { version, healthy };
HttpResponse::Ok().json(info)
}
pub fn init_routes(config: &mut web::ServiceConfig) {
config.service(web::scope("/system").service(info));
}

View File

@@ -1,7 +1,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::{Postgres, QueryBuilder};
use crate::{auth::hash, error::ApiResult};
use crate::{account::hash, error::ApiResult};
use crate::db;
pub const ADMIN_ROLE: &str = "ADMIN";

11
bruno/System/Info.bru Normal file
View File

@@ -0,0 +1,11 @@
meta {
name: Info
type: http
seq: 1
}
get {
url: {{API_URL}}/system/info
body: none
auth: inherit
}

3
bruno/System/folder.bru Normal file
View File

@@ -0,0 +1,3 @@
meta {
name: System
}

View File

@@ -87,7 +87,7 @@ services:
<<: *default_restart
api:
image: gitea.bensherriff.com/bsherriff/aviation-api:latest
image: gitea.bensherriff.com/bsherriff/aviation-api:0.1.2
container_name: aviation-api
build:
context: ./api

View File

@@ -5,7 +5,7 @@ server {
server_name ${NGINX_HOST};
location /api/ {
proxy_pass http://${NGINX_INTERNAL_HOST}:${API_PORT}/api/;
proxy_pass http://${NGINX_INTERNAL_HOST}:5000/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -13,7 +13,7 @@ server {
}
location /minio/ {
proxy_pass http://${NGINX_INTERNAL_HOST}:${MINIO_PORT_INTERNAL}/;
proxy_pass http://${NGINX_INTERNAL_HOST}:9001/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -22,7 +22,7 @@ server {
# Reverse proxy for the UI and default catch-all
location / {
proxy_pass http://${NGINX_INTERNAL_HOST}:${UI_PORT}/;
proxy_pass http://${NGINX_INTERNAL_HOST}:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View File

@@ -25,7 +25,7 @@ server {
# ssl_prefer_server_ciphers on;
location /api/ {
proxy_pass http://${NGINX_INTERNAL_HOST}:${API_PORT}/api/;
proxy_pass http://${NGINX_INTERNAL_HOST}:5000/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -33,7 +33,7 @@ server {
}
location /minio/ {
proxy_pass http://${NGINX_INTERNAL_HOST}:${MINIO_PORT_INTERNAL}/;
proxy_pass http://${NGINX_INTERNAL_HOST}:9001/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -42,7 +42,7 @@ server {
# Reverse proxy for the UI and default catch-all
location / {
proxy_pass http://${NGINX_INTERNAL_HOST}:${UI_PORT}/;
proxy_pass http://${NGINX_INTERNAL_HOST}:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

71
scripts/tag.sh Executable file
View File

@@ -0,0 +1,71 @@
#!/bin/bash
force=0
push=0
API_VERSION=$(sed -n 's/^version *= *"\([^"]*\)".*/\1/p' "$(pwd)"/api/Cargo.toml)
UI_VERSION=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$(pwd)"/ui/package.json)
# Parse arguments to detect the force (-f/--force) and push (-p/--push) flags
for arg in "$@"; do
case $arg in
-f|--force)
force=1
shift
;;
-p|--push)
push=1
shift
;;
esac
done
changed_files=$(git diff --name-only "$(git rev-parse HEAD^)")
# Processing UI changes
if echo "$changed_files" | grep -q "^ui/"; then
ui_tag="ui-${UI_VERSION}"
if git rev-parse "$ui_tag" >/dev/null 2>&1; then
if [ $force -eq 1 ]; then
echo "Force updating tag ${ui_tag} for UI to commit $(git rev-parse HEAD)"
git tag -fa "${ui_tag}" -m "UI changes in commit $(git rev-parse HEAD)"
if [ $push -eq 1 ]; then
echo "Force pushing tag ${ui_tag} to remote"
git push -f origin "${ui_tag}"
fi
else
echo "Tag ${ui_tag} already exists, skipping UI tagging"
fi
else
echo "Tagging UI with ${ui_tag}"
git tag -a "${ui_tag}" -m "UI changes in commit $(git rev-parse HEAD)"
if [ $push -eq 1 ]; then
echo "Pushing tag ${ui_tag} to remote"
git push origin "${ui_tag}"
fi
fi
fi
# Processing API changes
if echo "$changed_files" | grep -q "^api/"; then
api_tag="api-${API_VERSION}"
if git rev-parse "$api_tag" >/dev/null 2>&1; then
if [ $force -eq 1 ]; then
echo "Force updating tag ${api_tag} for API to commit $(git rev-parse HEAD)"
git tag -fa "${api_tag}" -m "API changes in commit $(git rev-parse HEAD)"
if [ $push -eq 1 ]; then
echo "Force pushing tag ${api_tag} to remote"
git push -f origin "${api_tag}"
fi
else
echo "Tag ${api_tag} already exists, skipping API tagging"
fi
else
echo "Tagging API with ${api_tag}"
git tag -a "${api_tag}" -m "API changes in commit $(git rev-parse HEAD)"
if [ $push -eq 1 ]; then
echo "Pushing tag ${api_tag} to remote"
git push origin "${api_tag}"
fi
fi
fi