8
flake.lock
generated
8
flake.lock
generated
@@ -511,11 +511,11 @@
|
|||||||
"secrets": {
|
"secrets": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1757861884,
|
"lastModified": 1757873556,
|
||||||
"narHash": "sha256-s0cInWk/yrj0eY7Iee722ME9/bfjpUj9aKMlnb6q/t4=",
|
"narHash": "sha256-WYrV46if1XsiQKOQEMNtHdAPeFDeu7YBdcoNSXc3sf8=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "383cf08fa55a46c8aa1c5faf57160bf594e5feaa",
|
"rev": "21ab0b0a59264b1da501f90725bf2c03e07ae941",
|
||||||
"revCount": 41,
|
"revCount": 43,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "ssh://git@karaolidis.com/karaolidis/nix-secrets.git"
|
"url": "ssh://git@karaolidis.com/karaolidis/nix-secrets.git"
|
||||||
},
|
},
|
||||||
|
@@ -0,0 +1,62 @@
|
|||||||
|
{ user, home }:
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
inputs,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
hmConfig = config.home-manager.users.${user};
|
||||||
|
inherit (hmConfig.virtualisation.quadlet) volumes networks;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
home-manager.users.${user} = {
|
||||||
|
sops = {
|
||||||
|
secrets."blog/apiKey".sopsFile = "${inputs.secrets}/hosts/jupiter/secrets.yaml";
|
||||||
|
|
||||||
|
templates.blog-receiver-env.content = ''
|
||||||
|
AUTH_KEY=${hmConfig.sops.placeholder."blog/apiKey"}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
virtualisation.quadlet = {
|
||||||
|
volumes.blog = { };
|
||||||
|
|
||||||
|
containers = {
|
||||||
|
blog.containerConfig = {
|
||||||
|
image = "docker-archive:${pkgs.dockerImages.nginx}";
|
||||||
|
networks = [ networks.traefik.ref ];
|
||||||
|
volumes = [ "${volumes.blog.ref}:/var/www/nginx:ro" ];
|
||||||
|
labels = [
|
||||||
|
"traefik.enable=true"
|
||||||
|
"traefik.http.routers.blog.rule=Host(`blog.karaolidis.com`)"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
blog-receiver = {
|
||||||
|
containerConfig = {
|
||||||
|
image = "docker-archive:${pkgs.dockerImages.nginx-receiver}";
|
||||||
|
networks = [ networks.traefik.ref ];
|
||||||
|
volumes = [ "${volumes.blog.ref}:/var/www/nginx" ];
|
||||||
|
environments = {
|
||||||
|
TARGET_DIR = "/var/www/nginx";
|
||||||
|
SUBPATH = "/upload";
|
||||||
|
};
|
||||||
|
environmentFiles = [ hmConfig.sops.templates.blog-receiver-env.path ];
|
||||||
|
labels = [
|
||||||
|
"traefik.enable=true"
|
||||||
|
"traefik.http.routers.blog-receiver.rule=Host(`blog.karaolidis.com`) && PathPrefix(`/upload`)"
|
||||||
|
|
||||||
|
"traefik.http.middlewares.redirect-root-to-blog.redirectregex.regex=^https://(www\.)?karaolidis\.com(/.*)?$"
|
||||||
|
"traefik.http.middlewares.redirect-root-to-blog.redirectregex.replacement=https://blog.karaolidis.com$${2}"
|
||||||
|
"traefik.http.middlewares.redirect-root-to-blog.redirectregex.permanent=false"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
unitConfig.After = [ "sops-nix.service" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@@ -12,6 +12,7 @@ in
|
|||||||
imports = [
|
imports = [
|
||||||
(import ./attic { inherit user home; })
|
(import ./attic { inherit user home; })
|
||||||
(import ./authelia { inherit user home; })
|
(import ./authelia { inherit user home; })
|
||||||
|
(import ./blog { inherit user home; })
|
||||||
(import ./comentario { inherit user home; })
|
(import ./comentario { inherit user home; })
|
||||||
(import ./gitea { inherit user home; })
|
(import ./gitea { inherit user home; })
|
||||||
(import ./grafana { inherit user home; })
|
(import ./grafana { inherit user home; })
|
||||||
|
@@ -17,6 +17,7 @@ pkgs.dockerTools.buildImage {
|
|||||||
name = "root";
|
name = "root";
|
||||||
paths = with pkgs; [
|
paths = with pkgs; [
|
||||||
git
|
git
|
||||||
|
git-lfs
|
||||||
curl
|
curl
|
||||||
jq
|
jq
|
||||||
nix
|
nix
|
||||||
|
@@ -27,11 +27,14 @@ var (
|
|||||||
maxUploadSize int64 = 1 << 30 // 1GB
|
maxUploadSize int64 = 1 << 30 // 1GB
|
||||||
|
|
||||||
deployLock sync.Mutex
|
deployLock sync.Mutex
|
||||||
|
|
||||||
|
infoLog = log.New(os.Stdout, "", log.LstdFlags)
|
||||||
|
errorLog = log.New(os.Stderr, "", log.LstdFlags)
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if authenticationKey == "" || targetDirectory == "" {
|
if authenticationKey == "" || targetDirectory == "" {
|
||||||
log.Fatal("AUTH_KEY and TARGET_DIR must be set")
|
errorLog.Fatal("AUTH_KEY and TARGET_DIR must be set")
|
||||||
}
|
}
|
||||||
|
|
||||||
if port == "" {
|
if port == "" {
|
||||||
@@ -43,15 +46,15 @@ func main() {
|
|||||||
basePath = "/" + subPath
|
basePath = "/" + subPath
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("starting server on :%s, endpoint %q, target directory %q", port, basePath, targetDirectory)
|
infoLog.Printf("starting server on :%s, endpoint %q, target directory %q", port, basePath, targetDirectory)
|
||||||
http.HandleFunc(basePath, withRecovery(handle))
|
http.HandleFunc(basePath, withRecovery(handle))
|
||||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
errorLog.Fatal(http.ListenAndServe(":"+port, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handle(w http.ResponseWriter, r *http.Request) {
|
func handle(w http.ResponseWriter, r *http.Request) {
|
||||||
remoteIP := realIP(r)
|
remoteIP := realIP(r)
|
||||||
|
|
||||||
log.Printf("incoming %q request on %q from %s", r.Method, r.URL.Path, remoteIP)
|
infoLog.Printf("incoming %q request on %q from %s", r.Method, r.URL.Path, remoteIP)
|
||||||
|
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
@@ -60,7 +63,7 @@ func handle(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
auth := r.Header.Get("Authorization")
|
auth := r.Header.Get("Authorization")
|
||||||
if subtle.ConstantTimeCompare([]byte(auth), []byte(authenticationKey)) != 1 {
|
if subtle.ConstantTimeCompare([]byte(auth), []byte(authenticationKey)) != 1 {
|
||||||
log.Printf("unauthorized request from %s", remoteIP)
|
errorLog.Printf("unauthorized request from %s", remoteIP)
|
||||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -112,7 +115,7 @@ func handle(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer os.RemoveAll(extractDir)
|
defer os.RemoveAll(extractDir)
|
||||||
|
|
||||||
if err := extractor.Extract(ctx, archiveStream, extract(extractDir)); err != nil {
|
if err := extractor.Extract(ctx, archiveStream, extract(extractDir)); err != nil {
|
||||||
log.Printf("failed to extract archive: %v", err)
|
errorLog.Printf("failed to extract archive: %v", err)
|
||||||
http.Error(w, "bad archive", http.StatusBadRequest)
|
http.Error(w, "bad archive", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -131,7 +134,7 @@ func handle(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
log.Printf("upload successful from %s", remoteIP)
|
infoLog.Printf("upload successful from %s", remoteIP)
|
||||||
}
|
}
|
||||||
|
|
||||||
func realIP(r *http.Request) string {
|
func realIP(r *http.Request) string {
|
||||||
@@ -235,7 +238,7 @@ func withRecovery(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if v := recover(); v != nil {
|
if v := recover(); v != nil {
|
||||||
log.Printf("panic: %v", v)
|
errorLog.Printf("panic: %v", v)
|
||||||
http.Error(w, "internal error", http.StatusInternalServerError)
|
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Submodule submodules/secrets updated: 383cf08fa5...21ab0b0a59
Reference in New Issue
Block a user