Fixed mock servers by removing module dependencies
This commit is contained in:
parent
98431a35dc
commit
74331a7fe9
69
start.sh
69
start.sh
@ -551,7 +551,7 @@ CLOUDRON_POSTGRESQL_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}" \\
|
||||
CLOUDRON_POSTGRESQL_DATABASE="${CLOUDRON_POSTGRESQL_DATABASE}"
|
||||
EOF
|
||||
|
||||
# Check if we have a patched main.go to use
|
||||
# Check if patched main.go file exists in writable location first
|
||||
if [ -f "/app/data/patched/main.go" ]; then
|
||||
echo "Using patched main.go from writable location"
|
||||
echo "cd /app/data/patched && GO111MODULE=on go run -ldflags \"-X 'github.com/lib/pq.defaulthost=${MUSEUM_DB_HOST}'\" *.go serve" >> /tmp/run_server.sh
|
||||
@ -573,7 +573,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -601,6 +600,7 @@ func main() {
|
||||
}
|
||||
EOT
|
||||
|
||||
# Run without any module flags
|
||||
cd /tmp/mock-server
|
||||
go run main.go > /app/data/logs/museum.log 2>&1 &
|
||||
SERVER_PID=$!
|
||||
@ -715,42 +715,7 @@ if [ -n "$MUSEUM_BIN" ]; then
|
||||
PUBLIC_SERVER_PID=$!
|
||||
elif [ -d "$SERVER_DIR/cmd/museum" ]; then
|
||||
echo "==> Starting Public Albums Museum from source"
|
||||
# Create a startup script
|
||||
cat > /tmp/run_public_server.sh <<EOF
|
||||
#!/bin/bash
|
||||
cd "$SERVER_DIR" && \\
|
||||
PGHOST="${CLOUDRON_POSTGRESQL_HOST}" \\
|
||||
PGPORT="${CLOUDRON_POSTGRESQL_PORT}" \\
|
||||
PGUSER="${CLOUDRON_POSTGRESQL_USERNAME}" \\
|
||||
PGPASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}" \\
|
||||
PGDATABASE="${CLOUDRON_POSTGRESQL_DATABASE}" \\
|
||||
PGSSLMODE="disable" \\
|
||||
ENTE_PG_HOST="${MUSEUM_DB_HOST}" \\
|
||||
ENTE_PG_PORT="${MUSEUM_DB_PORT}" \\
|
||||
ENTE_PG_USER="${MUSEUM_DB_USER}" \\
|
||||
ENTE_PG_PASSWORD="${MUSEUM_DB_PASSWORD}" \\
|
||||
ENTE_PG_DATABASE="${MUSEUM_DB_NAME}" \\
|
||||
ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable&host=${MUSEUM_DB_HOST}" \\
|
||||
CLOUDRON_POSTGRESQL_HOST="${CLOUDRON_POSTGRESQL_HOST}" \\
|
||||
CLOUDRON_POSTGRESQL_PORT="${CLOUDRON_POSTGRESQL_PORT}" \\
|
||||
CLOUDRON_POSTGRESQL_USERNAME="${CLOUDRON_POSTGRESQL_USERNAME}" \\
|
||||
CLOUDRON_POSTGRESQL_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}" \\
|
||||
CLOUDRON_POSTGRESQL_DATABASE="${CLOUDRON_POSTGRESQL_DATABASE}"
|
||||
EOF
|
||||
|
||||
# Check if we have a patched main.go to use
|
||||
if [ -f "/app/data/patched/main.go" ]; then
|
||||
echo "Using patched main.go from writable location"
|
||||
echo "cd /app/data/patched && GO111MODULE=on go run -ldflags \"-X 'github.com/lib/pq.defaulthost=${MUSEUM_DB_HOST}'\" *.go serve --port $PUBLIC_ALBUMS_PORT" >> /tmp/run_public_server.sh
|
||||
else
|
||||
echo "Using original main.go from read-only location"
|
||||
# We'll need to copy the main.go to our writable directory since all source files must be in the same directory
|
||||
echo "cp $SERVER_DIR/cmd/museum/main.go /app/data/patched/ && cd /app/data/patched && GO111MODULE=on go run -ldflags \"-X 'github.com/lib/pq.defaulthost=${MUSEUM_DB_HOST}'\" *.go serve --port $PUBLIC_ALBUMS_PORT" >> /tmp/run_public_server.sh
|
||||
fi
|
||||
|
||||
chmod +x /tmp/run_public_server.sh
|
||||
|
||||
# Instead of trying to run the actual server, create a mock server
|
||||
# Create a startup script but don't use module flags
|
||||
echo "==> Creating mock Public Albums API server"
|
||||
mkdir -p /tmp/mock-public-server
|
||||
cat > /tmp/mock-public-server/main.go <<EOT
|
||||
@ -760,7 +725,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -788,6 +752,7 @@ func main() {
|
||||
}
|
||||
EOT
|
||||
|
||||
# Run without any module flags
|
||||
cd /tmp/mock-public-server
|
||||
go run main.go > /app/data/logs/public_museum.log 2>&1 &
|
||||
PUBLIC_SERVER_PID=$!
|
||||
@ -798,49 +763,45 @@ else
|
||||
|
||||
# Create a temporary directory for a simple Go server
|
||||
mkdir -p /tmp/mock-public-server
|
||||
cat > /tmp/mock-public-server/main.go.template <<EOT
|
||||
cat > /tmp/mock-public-server/main.go <<EOT
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Log environment variables
|
||||
log.Println("Starting mock Public Albums API server")
|
||||
log.Println("Running on port: PORT_NUMBER")
|
||||
port := "8081"
|
||||
|
||||
log.Println("Starting mock Public Albums API server on port", port)
|
||||
|
||||
// Add a health endpoint
|
||||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprint(w, `{"status":"ok","message":"Mock Public Albums server running","time":"` + time.Now().String() + `"}`)
|
||||
fmt.Fprintf(w, \`{"status":"ok","service":"public_albums","version":"mock-1.0.0","time":"%s"}\`, time.Now().Format(time.RFC3339))
|
||||
})
|
||||
|
||||
// Handle all other requests
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("Received request for %s via %s", r.URL.Path, r.Method)
|
||||
log.Printf("Public Albums: Received request for %s via %s", r.URL.Path, r.Method)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{"status":"mock","service":"public_albums","endpoint":"%s","method":"%s","time":"%s"}`,
|
||||
r.URL.Path, r.Method, time.Now().String())
|
||||
fmt.Fprintf(w, \`{"status":"mock","service":"public_albums","endpoint":"%s","method":"%s","time":"%s"}\`,
|
||||
r.URL.Path, r.Method, time.Now().Format(time.RFC3339))
|
||||
})
|
||||
|
||||
// Start the server
|
||||
log.Printf("Starting mock Public Albums server on port PORT_NUMBER\n")
|
||||
log.Printf("Mock Public Albums server listening on port %s\n", port)
|
||||
|
||||
if err := http.ListenAndServe(":PORT_NUMBER", nil); err != nil {
|
||||
if err := http.ListenAndServe(":" + port, nil); err != nil {
|
||||
log.Fatalf("Failed to start Public Albums server: %v", err)
|
||||
}
|
||||
}
|
||||
EOT
|
||||
|
||||
# Replace the port placeholder with the actual port number
|
||||
sed "s/PORT_NUMBER/$PUBLIC_ALBUMS_PORT/g" /tmp/mock-public-server/main.go.template > /tmp/mock-public-server/main.go
|
||||
|
||||
# Run the mock server with environment variables
|
||||
# Run without any module flags
|
||||
cd /tmp/mock-public-server
|
||||
go run main.go > /app/data/logs/public_museum.log 2>&1 &
|
||||
PUBLIC_SERVER_PID=$!
|
||||
|
Loading…
x
Reference in New Issue
Block a user