From 69ba2f4232a22c6535ddb75bc6e28a4518bb7778 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Sat, 13 Dec 2025 13:13:15 +0100 Subject: [PATCH] Update --- Makefile | 8 +- api-gateway/etc/haproxy-aux.cfg | 40 -------- api-gateway/jwt_auth.lua | 136 ---------------------------- deploy/init.sh | 4 + deploy/{ => scripts}/image-build.sh | 5 +- deploy/{ => scripts}/image-push.sh | 1 + 6 files changed, 12 insertions(+), 182 deletions(-) delete mode 100644 api-gateway/etc/haproxy-aux.cfg delete mode 100644 api-gateway/jwt_auth.lua create mode 100644 deploy/init.sh rename deploy/{ => scripts}/image-build.sh (51%) rename deploy/{ => scripts}/image-push.sh (80%) diff --git a/Makefile b/Makefile index 62b562b..2e6051f 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,13 @@ SRC_DIR := ./src ## DEPLOY PART build-image-dev: - - sh ${DEPLOY_DIR}/image-build.sh dev + - sh ${DEPLOY_DIR}/scripts/image-build.sh dev build-image-prod: - - sh ${DEPLOY_DIR}/image-build.sh + - sh ${DEPLOY_DIR}/scripts/image-build.sh push-image-dev: - - sh ${DEPLOY_DIR}/image-push.sh dev + - sh ${DEPLOY_DIR}/scripts/image-push.sh dev push-image-prod: - - sh ${DEPLOY_DIR}/image-push.sh + - sh ${DEPLOY_DIR}/scripts/image-push.sh diff --git a/api-gateway/etc/haproxy-aux.cfg b/api-gateway/etc/haproxy-aux.cfg deleted file mode 100644 index 2ad4906..0000000 --- a/api-gateway/etc/haproxy-aux.cfg +++ /dev/null @@ -1,40 +0,0 @@ -# errorfile 400 /etc/haproxy/errors/400.html -# errorfile 401 /etc/haproxy/errors/401.html -# errorfile 403 /etc/haproxy/errors/403.html -# errorfile 404 /etc/haproxy/errors/404.html -# errorfile 408 /etc/haproxy/errors/408.html -# errorfile 429 /etc/haproxy/errors/429.html -# errorfile 500 /etc/haproxy/errors/500.html -# errorfile 502 /etc/haproxy/errors/502.html -# errorfile 503 /etc/haproxy/errors/503.html -# errorfile 504 /etc/haproxy/errors/504.html - -global - daemon - maxconn 256 - - log 127.0.0.1 local0 debug - - # lua-load /etc/haproxy/lua/jwt_auth.lua - -defaults - mode http - log global - option httplog - timeout connect 5s - timeout client 50s - timeout server 50s - -# frontend http-in - # bind *:8443 - # mode http - - # http-response set-header X-Custom-HAProxy-Header "rojter" - # http-request lua.jwt_auth if { path_beg /api } - # option httplog - - # default_backend local - -# backend local -# mode http -# server server 127.0.0.1:8080 diff --git a/api-gateway/jwt_auth.lua b/api-gateway/jwt_auth.lua deleted file mode 100644 index 9c65944..0000000 --- a/api-gateway/jwt_auth.lua +++ /dev/null @@ -1,136 +0,0 @@ --- package.path = "/usr/local/lib/lua/5.4/?.lua;" .. package.path - -local jwt = require "resty/jwt" - -function jwt_auth_req(txn) - -- print_r(txn.http:req_get_headers()["Authorization"]) - - -- local auth_header = txn.http:req_get_headers()["authorization"] - -- if not auth_header then - -- txn.http:respond(401, "Unauthorized") - -- return false - -- end - - -- local token = auth_header:match("Bearer%s+(.+)") - -- if not token then - -- txn.http:respond(401, "Unauthorized") - -- return false - -- end - - -- -- Replace with your secret or public key - -- local secret = "your-secret-key" - - -- local jwt_obj = jwt:verify(secret, token) - -- if not jwt_obj.verified then - -- txn.http:respond(401, "Unauthorized") - -- return false - -- end - - -- -- Optionally, check claims, expiration, etc. - -- return true -end - -function jwt_auth_res(txn) - -- txn.http:res_add_header("Some-Header", "haproxy lua header") - -- print_r(txn.http:res_get_headers()) -end - -core.register_action("jwt_auth", { "http-req" }, jwt_auth_req, 0) -core.register_action("jwt_auth", { "http-res" }, jwt_auth_res, 0) - --- Copyright 2016 Thierry Fournier - --- function color(index, str) --- return "\x1b[" .. index .. "m" .. str .. "\x1b[00m" --- end - --- function nocolor(index, str) --- return str --- end - --- function sp(count) --- local spaces = "" --- while count > 0 do --- spaces = spaces .. " " --- count = count - 1 --- end --- return spaces --- end - --- function escape(str) --- local s = "" --- for i = 1, #str do --- local c = str:sub(i,i) --- ascii = string.byte(c, 1) --- if ascii > 126 or ascii < 20 then --- s = s .. string.format("\\x%02x", ascii) --- else --- s = s .. c --- end --- end --- return s --- end - --- function print_rr(p, indent, c, wr, hist) --- local i = 0 --- local nl = "" - --- if type(p) == "table" then --- wr(c("33", "(table)") .. " " .. c("36", tostring(p)) .. " [") - --- for idx, value in ipairs(hist) do --- if value == p then --- wr(" " .. c("35", "/* recursion */") .. " ]") --- return --- end --- end --- hist[indent + 1] = p - --- mt = getmetatable(p) --- if mt ~= nil then --- wr("\n" .. sp(indent+1) .. c("31", "METATABLE") .. ": ") --- print_rr(mt, indent+1, c, wr, hist) --- end - --- for k,v in pairs(p) do --- if i > 0 then --- nl = "\n" --- else --- wr("\n") --- end --- wr(nl .. sp(indent+1)) --- if type(k) == "number" then --- wr(c("32", tostring(k))) --- else --- wr("\"" .. c("32", escape(tostring(k))) .. "\"") --- end --- wr(": ") --- print_rr(v, indent+1, c, wr, hist) --- i = i + 1 --- end --- if i == 0 then --- wr(" " .. c("35", "/* empty */") .. " ]") --- else --- wr("\n" .. sp(indent) .. "]") --- end - --- hist[indent + 1] = nil - --- elseif type(p) == "string" then --- wr(c("33", "(string)") .. " \"" .. c("36", escape(p)) .. "\"") --- else --- wr(c("33", "(" .. type(p) .. ")") .. " " .. c("36", tostring(p))) --- end --- end - --- function print_r(p, col, wr) --- if col == nil then col = true end --- if wr == nil then wr = function(msg) io.stdout:write(msg) end end --- local hist = {} --- if col == true then --- print_rr(p, 0, color, wr, hist) --- else --- print_rr(p, 0, nocolor, wr, hist) --- end --- wr("\n") --- end \ No newline at end of file diff --git a/deploy/init.sh b/deploy/init.sh new file mode 100644 index 0000000..3a345bc --- /dev/null +++ b/deploy/init.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +git cl git@github.com:apache/apisix.git api-gatway/ +git cl git@github.com:apache/apisix-docker.git api-gateway/apisix/ diff --git a/deploy/image-build.sh b/deploy/scripts/image-build.sh similarity index 51% rename from deploy/image-build.sh rename to deploy/scripts/image-build.sh index b9b0644..521cc86 100755 --- a/deploy/image-build.sh +++ b/deploy/scripts/image-build.sh @@ -2,6 +2,7 @@ # RUN IN REPO ROOT DIR !! export IMAGE_NAME="git.ego.freeddns.org/egommerce/api-gateway" +# export IMAGE_NAME="localhost:32000/egommerce/api-gateway" export BUILD_TIME=$(date +"%Y%m%d%H%M%S") TARGET=${1:-latest} @@ -9,9 +10,9 @@ TARGET=${1:-latest} echo "Building: $IMAGE_NAME:$TARGET" if [ $TARGET = "dev" ] then - docker build --build-arg BUILD_TIME --rm --no-cache -t "$IMAGE_NAME:dev" . # >/dev/null 2>&1 + docker build --rm --no-cache -t "$IMAGE_NAME:dev" . # >/dev/null 2>&1 else - docker build --build-arg BUILD_TIME --rm --cache-from "$IMAGE_NAME:$TARGET" -t "$IMAGE_NAME:$TARGET" . >/dev/null 2>&1 + docker build --rm --cache-from "$IMAGE_NAME:$TARGET" -t "$IMAGE_NAME:$TARGET" . >/dev/null 2>&1 fi echo "Done." diff --git a/deploy/image-push.sh b/deploy/scripts/image-push.sh similarity index 80% rename from deploy/image-push.sh rename to deploy/scripts/image-push.sh index d721dbd..123fc59 100755 --- a/deploy/image-push.sh +++ b/deploy/scripts/image-push.sh @@ -2,6 +2,7 @@ # RUN IN REPO ROOT DIR !! export IMAGE_NAME="git.ego.freeddns.org/egommerce/api-gateway" +# export IMAGE_NAME="localhost:32000/egommerce/api-gateway" TARGET=${1:-latest}