Skip to content

Commit

Permalink
feat: add container-push target to Makefile
Browse files Browse the repository at this point in the history
- Introduced `container-push` target for pushing Docker images.
- Enhanced `DetectLocalNetwork` to better handle IP parsing.
  • Loading branch information
eser committed Aug 18, 2024
1 parent 740ebe2 commit 514f91b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: dev build multiarch-build run clean test test-cov test-ci dep lint container-start container-start-prod container-rebuild container-rebuild-prod container-restart container-restart-prod container-stop container-stop-prod container-destroy container-destroy-prod container-update container-update-prod container-dev container-ps container-ps-prod container-logs-all container-logs-all-prod container-logs container-logs-prod container-cli container-cli-prod
.PHONY: dev build multiarch-build run clean test test-cov test-ci dep lint container-start container-start-prod container-rebuild container-rebuild-prod container-restart container-restart-prod container-stop container-stop-prod container-destroy container-destroy-prod container-update container-update-prod container-dev container-ps container-ps-prod container-logs-all container-logs-all-prod container-logs container-logs-prod container-cli container-cli-prod container-push
# .RECIPEPREFIX := $(.RECIPEPREFIX)<space>
BINARY_NAME=service-cli
TESTCOVERAGE_THRESHOLD=0
Expand Down Expand Up @@ -115,3 +115,11 @@ container-cli:

container-cli-prod:
docker compose --file ./deployments/compose.production.yml exec go-service bash

container-push:
ifdef VERSION
docker build --platform=linux/amd64 -t acikyazilim.registry.cpln.io/golang-service-template:v$(VERSION) .
docker push acikyazilim.registry.cpln.io/golang-service-template:v$(VERSION)
else
@echo "VERSION is not set"
endif
19 changes: 14 additions & 5 deletions pkg/bliss/httpfx/middlewares/resolve-address-middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middlewares

import (
"context"
"fmt"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -63,11 +64,19 @@ func ResolveAddressMiddleware() httpfx.Handler {
}

func DetectLocalNetwork(requestAddr string) (bool, error) {
requestAddrs := strings.SplitN(requestAddr, ",", 2)
var requestIp string

requestIp, _, err := net.SplitHostPort(requestAddrs[0])
if err != nil {
return false, err
requestAddrs := strings.SplitN(requestAddr, ",", 2) //nolint:mnd

if strings.ContainsRune(requestAddrs[0], ':') {
host, _, err := net.SplitHostPort(requestAddrs[0])
if err != nil {
return false, fmt.Errorf("failed to split host and port: %w", err)
}

requestIp = host
} else {
requestIp = requestAddrs[0]
}

addrs, err := net.InterfaceAddrs()
Expand Down Expand Up @@ -113,5 +122,5 @@ func GetClientAddrs(req *http.Request) string {

// split comma delimited list into a slice
// (this happens when proxied via elastic load balancer then again through nginx)
return strings.Join(requester, ", ")
return strings.Join(requester, ",")
}

0 comments on commit 514f91b

Please sign in to comment.