Added system/info endpoint, implement tagging
This commit is contained in:
7
Makefile
7
Makefile
@@ -1,8 +1,8 @@
|
|||||||
#!make
|
#!make
|
||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
|
|
||||||
export API_VERSION = $(shell awk -F ' = ' '$$1 ~ /package.version/ { gsub(/[\"]/, "", $$2); printf("%s",$$2) }' api/Cargo.toml)
|
export API_VERSION = $(shell sed -n 's/^version *= *"\([^"]*\)".*/\1/p' api/Cargo.toml)
|
||||||
export UI_VERSION := $(shell awk -F'"' '/"version"/ { print $$4 }' ui/package.json)
|
export UI_VERSION=$(shell sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' ui/package.json)
|
||||||
|
|
||||||
include .env
|
include .env
|
||||||
-include .env.local
|
-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: domain=$(if $(d),$(d),${NGINX_HOST})
|
||||||
cert: ## Generate a cert for the given domain
|
cert: ## Generate a cert for the given domain
|
||||||
./scripts/generate_cert.sh ${domain}
|
./scripts/generate_cert.sh ${domain}
|
||||||
|
|
||||||
|
tag: ## Tag the commits based on versions
|
||||||
|
@./scripts/tag.sh
|
||||||
|
|||||||
2
api/Cargo.lock
generated
2
api/Cargo.lock
generated
@@ -366,7 +366,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "api"
|
name = "api"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-cors",
|
"actix-cors",
|
||||||
"actix-multipart",
|
"actix-multipart",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "api"
|
name = "api"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Ben Sherriff <hello@bensherriff.com>"]
|
authors = ["Ben Sherriff <hello@bensherriff.com>"]
|
||||||
repository = "https://github.com/bensherriff/aviation-weather"
|
repository = "https://github.com/bensherriff/aviation-weather"
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ use rand::distr::Alphanumeric;
|
|||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use rand_chacha::ChaCha20Rng;
|
use rand_chacha::ChaCha20Rng;
|
||||||
|
|
||||||
mod model;
|
mod auth;
|
||||||
mod routes;
|
mod routes;
|
||||||
mod session;
|
mod session;
|
||||||
|
|
||||||
pub use model::*;
|
pub use auth::*;
|
||||||
pub use session::*;
|
pub use session::*;
|
||||||
pub use routes::init_routes;
|
pub use routes::init_routes;
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
use actix_web::{post, web, HttpResponse, ResponseError, HttpRequest, put, get};
|
use actix_web::{post, web, HttpResponse, ResponseError, HttpRequest, put, get};
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::{verify_hash, Session, SESSION_COOKIE_NAME},
|
account::{verify_hash, Session, SESSION_COOKIE_NAME},
|
||||||
error::Error,
|
error::Error,
|
||||||
users::{LoginRequest, RegisterRequest, User, UserResponse},
|
users::{LoginRequest, RegisterRequest, User, UserResponse},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::auth::Auth;
|
use crate::account::Auth;
|
||||||
use crate::users::UpdateUser;
|
use crate::users::UpdateUser;
|
||||||
|
|
||||||
#[post("/register")]
|
#[post("/register")]
|
||||||
@@ -3,7 +3,7 @@ use futures_util::stream::StreamExt as _;
|
|||||||
use crate::{
|
use crate::{
|
||||||
airports::Airport,
|
airports::Airport,
|
||||||
db::Paged,
|
db::Paged,
|
||||||
auth::{Auth, verify_role},
|
account::{Auth, verify_role},
|
||||||
AppState,
|
AppState,
|
||||||
};
|
};
|
||||||
use actix_multipart::Multipart;
|
use actix_multipart::Multipart;
|
||||||
|
|||||||
@@ -4,15 +4,16 @@ use actix_cors::Cors;
|
|||||||
use actix_web::{App, HttpServer, middleware::Logger, web};
|
use actix_web::{App, HttpServer, middleware::Logger, web};
|
||||||
use dotenv::from_filename;
|
use dotenv::from_filename;
|
||||||
use reqwest::Certificate;
|
use reqwest::Certificate;
|
||||||
use crate::auth::hash;
|
use crate::account::hash;
|
||||||
use crate::users::{User, ADMIN_ROLE};
|
use crate::users::{User, ADMIN_ROLE};
|
||||||
|
|
||||||
|
mod account;
|
||||||
mod airports;
|
mod airports;
|
||||||
mod auth;
|
|
||||||
mod db;
|
mod db;
|
||||||
mod error;
|
mod error;
|
||||||
mod metars;
|
mod metars;
|
||||||
mod scheduler;
|
mod scheduler;
|
||||||
|
mod system;
|
||||||
mod users;
|
mod users;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -71,7 +72,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let state = AppState { client };
|
let state = AppState { client };
|
||||||
let host = "0.0.0.0";
|
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 server = match HttpServer::new(move || {
|
||||||
let cors = Cors::default()
|
let cors = Cors::default()
|
||||||
@@ -88,8 +89,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
web::scope("api")
|
web::scope("api")
|
||||||
.configure(airports::init_routes)
|
.configure(airports::init_routes)
|
||||||
.configure(metars::init_routes)
|
.configure(metars::init_routes)
|
||||||
.configure(auth::init_routes)
|
.configure(account::init_routes)
|
||||||
.configure(users::init_routes),
|
.configure(users::init_routes)
|
||||||
|
.configure(system::init_routes),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.bind(format!("{}:{}", host, port))
|
.bind(format!("{}:{}", host, port))
|
||||||
|
|||||||
31
api/src/system/mod.rs
Normal file
31
api/src/system/mod.rs
Normal 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));
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{Postgres, QueryBuilder};
|
use sqlx::{Postgres, QueryBuilder};
|
||||||
use crate::{auth::hash, error::ApiResult};
|
use crate::{account::hash, error::ApiResult};
|
||||||
use crate::db;
|
use crate::db;
|
||||||
|
|
||||||
pub const ADMIN_ROLE: &str = "ADMIN";
|
pub const ADMIN_ROLE: &str = "ADMIN";
|
||||||
|
|||||||
11
bruno/System/Info.bru
Normal file
11
bruno/System/Info.bru
Normal 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
3
bruno/System/folder.bru
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
meta {
|
||||||
|
name: System
|
||||||
|
}
|
||||||
@@ -87,7 +87,7 @@ services:
|
|||||||
<<: *default_restart
|
<<: *default_restart
|
||||||
|
|
||||||
api:
|
api:
|
||||||
image: gitea.bensherriff.com/bsherriff/aviation-api:latest
|
image: gitea.bensherriff.com/bsherriff/aviation-api:0.1.2
|
||||||
container_name: aviation-api
|
container_name: aviation-api
|
||||||
build:
|
build:
|
||||||
context: ./api
|
context: ./api
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ server {
|
|||||||
server_name ${NGINX_HOST};
|
server_name ${NGINX_HOST};
|
||||||
|
|
||||||
location /api/ {
|
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 Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
@@ -13,7 +13,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /minio/ {
|
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 Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
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
|
# Reverse proxy for the UI and default catch-all
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://${NGINX_INTERNAL_HOST}:${UI_PORT}/;
|
proxy_pass http://${NGINX_INTERNAL_HOST}:3000/;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ server {
|
|||||||
# ssl_prefer_server_ciphers on;
|
# ssl_prefer_server_ciphers on;
|
||||||
|
|
||||||
location /api/ {
|
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 Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
@@ -33,7 +33,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /minio/ {
|
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 Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
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
|
# Reverse proxy for the UI and default catch-all
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://${NGINX_INTERNAL_HOST}:${UI_PORT}/;
|
proxy_pass http://${NGINX_INTERNAL_HOST}:3000/;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|||||||
71
scripts/tag.sh
Executable file
71
scripts/tag.sh
Executable 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
|
||||||
Reference in New Issue
Block a user