fix: use container names instead of static IPs
This commit is contained in:
parent
7e12e8d831
commit
8561f59beb
4 changed files with 9 additions and 14 deletions
|
|
@ -10,8 +10,7 @@ services:
|
||||||
- /opt/nextworkspace/config/authelia/:/config/
|
- /opt/nextworkspace/config/authelia/:/config/
|
||||||
- /opt/nextworkspace/data/authelia/:/data/
|
- /opt/nextworkspace/data/authelia/:/data/
|
||||||
networks:
|
networks:
|
||||||
nextwks-net:
|
- nextwks-net
|
||||||
ipv4_address: 172.16.0.11
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
nextwks-net:
|
nextwks-net:
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ services:
|
||||||
- /opt/nextworkspace/logs/caddy/:/var/log/caddy/
|
- /opt/nextworkspace/logs/caddy/:/var/log/caddy/
|
||||||
- /opt/nextworkspace/www/:/opt/nextworkspace/www/
|
- /opt/nextworkspace/www/:/opt/nextworkspace/www/
|
||||||
networks:
|
networks:
|
||||||
nextwks-net:
|
- nextwks-net
|
||||||
ipv4_address: 172.16.0.10
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
nextwks-net:
|
nextwks-net:
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,13 @@ services:
|
||||||
- "9000"
|
- "9000"
|
||||||
volumes:
|
volumes:
|
||||||
- /opt/nextworkspace/:/opt/nextworkspace/
|
- /opt/nextworkspace/:/opt/nextworkspace/
|
||||||
- /opt/nextworkspace/data/:/opt/nextworkspace/data/
|
|
||||||
- /opt/nextworkspace/lng/:/opt/nextworkspace/lng/
|
|
||||||
- /opt/nextworkspace/.env:/opt/nextworkspace/.env
|
- /opt/nextworkspace/.env:/opt/nextworkspace/.env
|
||||||
working_dir: /opt/nextworkspace
|
working_dir: /opt/nextworkspace
|
||||||
command: /opt/nextworkspace/nextworkspace
|
command: /opt/nextworkspace/nextworkspace
|
||||||
environment:
|
environment:
|
||||||
- CONFIG_DIR=/opt/nextworkspace/config/nextworkspace
|
- CONFIG_DIR=/opt/nextworkspace/config/nextworkspace
|
||||||
networks:
|
networks:
|
||||||
nextwks-net:
|
- nextwks-net
|
||||||
ipv4_address: 172.16.0.12
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
nextwks-net:
|
nextwks-net:
|
||||||
|
|
|
||||||
12
main.go
12
main.go
|
|
@ -303,7 +303,7 @@ func proxyToUpstream(upstream string) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
func adminHandler(w http.ResponseWriter, r *http.Request) {
|
func adminHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
apiBase := "http://172.16.0.11:8080"
|
apiBase := "http://authelia:8080"
|
||||||
apiToken := os.Getenv("AUTHELIA_SECRET")
|
apiToken := os.Getenv("AUTHELIA_SECRET")
|
||||||
configDir := os.Getenv("CONFIG_DIR")
|
configDir := os.Getenv("CONFIG_DIR")
|
||||||
if configDir == "" {
|
if configDir == "" {
|
||||||
|
|
@ -348,13 +348,13 @@ func adminHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Check service statuses
|
// Check service statuses
|
||||||
autheliaUp := false
|
autheliaUp := false
|
||||||
if resp, err := http.Get("http://172.16.0.11:9091/api/health"); err == nil {
|
if resp, err := http.Get("http://authelia:9091/api/health"); err == nil {
|
||||||
autheliaUp = resp.StatusCode == 200
|
autheliaUp = resp.StatusCode == 200
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
caddyUp := false
|
caddyUp := false
|
||||||
// Check port 80 responds (don't follow HTTPS redirect)
|
// Check port 80 responds (don't follow HTTPS redirect)
|
||||||
if conn, err := net.DialTimeout("tcp", "172.16.0.10:80", 3*time.Second); err == nil {
|
if conn, err := net.DialTimeout("tcp", "caddy:80", 3*time.Second); err == nil {
|
||||||
caddyUp = true
|
caddyUp = true
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
|
@ -511,7 +511,7 @@ type apiUser struct {
|
||||||
|
|
||||||
func fetchAllUsers() ([]apiUser, error) {
|
func fetchAllUsers() ([]apiUser, error) {
|
||||||
apiToken := os.Getenv("AUTHELIA_SECRET")
|
apiToken := os.Getenv("AUTHELIA_SECRET")
|
||||||
req, _ := http.NewRequest("GET", "http://172.16.0.11:8080/api/users", nil)
|
req, _ := http.NewRequest("GET", "http://authelia:8080/api/users", nil)
|
||||||
req.Header.Set("Authorization", "Bearer "+apiToken)
|
req.Header.Set("Authorization", "Bearer "+apiToken)
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -608,7 +608,7 @@ func initials(s string) string {
|
||||||
// --- API proxy for authelia-api ---
|
// --- API proxy for authelia-api ---
|
||||||
|
|
||||||
func apiProxyHandler(w http.ResponseWriter, r *http.Request) {
|
func apiProxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
target, _ := url.Parse("http://172.16.0.11:8080")
|
target, _ := url.Parse("http://authelia:8080")
|
||||||
proxy := httputil.NewSingleHostReverseProxy(target)
|
proxy := httputil.NewSingleHostReverseProxy(target)
|
||||||
// Inject Bearer token for authelia-api auth
|
// Inject Bearer token for authelia-api auth
|
||||||
token := os.Getenv("AUTHELIA_SECRET")
|
token := os.Getenv("AUTHELIA_SECRET")
|
||||||
|
|
@ -638,7 +638,7 @@ func globalSettingsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Check Authelia health
|
// Check Authelia health
|
||||||
autheliaUp := false
|
autheliaUp := false
|
||||||
if resp, err := http.Get("http://172.16.0.11:9091/api/health"); err == nil {
|
if resp, err := http.Get("http://authelia:9091/api/health"); err == nil {
|
||||||
autheliaUp = resp.StatusCode == 200
|
autheliaUp = resp.StatusCode == 200
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue