diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/database.db b/data/database.db new file mode 100644 index 0000000..7b65e3d Binary files /dev/null and b/data/database.db differ diff --git a/proxy/Dockerfile b/proxy/Dockerfile index 6830baf..3ef463d 100644 --- a/proxy/Dockerfile +++ b/proxy/Dockerfile @@ -7,13 +7,13 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o main . - -FROM gcr.io/distroless/base-debian11 +RUN CGO_ENABLED=1 GOOS=linux go build -o main . +FROM ubuntu:latest WORKDIR /app COPY --from=builder /app/main . +COPY --from=builder /app/dev.env . EXPOSE 80 diff --git a/proxy/db.go b/proxy/db.go index 505404c..eac6314 100644 --- a/proxy/db.go +++ b/proxy/db.go @@ -32,7 +32,7 @@ const ( func InitDB() { var err error - db, err = sql.Open("sqlite3", "database.db") + db, err = sql.Open("sqlite3", "data/database.db") if err != nil { log.Fatal(err) } diff --git a/proxy/main.go b/proxy/main.go index 2dc5924..7e3c129 100644 --- a/proxy/main.go +++ b/proxy/main.go @@ -2,16 +2,24 @@ package main import ( "fmt" + "os" "github.com/joho/godotenv" ) func main() { - if ok := godotenv.Load("dev.env"); ok != nil { - panic(".env not found") - } + if value := os.Getenv("ENV"); value == "prod" { + if ok := godotenv.Load(".env"); ok != nil { + panic(".env not found") + } + } else { + fmt.Println("Not Produktion Enviorment fallback to dev.env") + if ok := godotenv.Load("dev.env"); ok != nil { + panic("dev.env not found") + } + } InitDB() err := run() diff --git a/start.sh b/start.sh index 80e5a0a..b64f921 100644 --- a/start.sh +++ b/start.sh @@ -23,14 +23,14 @@ docker build -t "$BACKEND_IMAGE" "$REPO_DIR/proxy" # Assuming proxy is the backe echo "Building frontend Docker image..." docker build -t "$FRONTEND_IMAGE" "$REPO_DIR/frontend" # Assuming frontend is the frontend directory -if [ "$(docker ps -q -f name=$BACKEND_CONTAINER)" ]; then +if [ "$(docker ps -aq -f name=$BACKEND_CONTAINER)" ]; then echo "Stopping old backend container..." docker stop "$BACKEND_CONTAINER" echo "Removing old backend container..." docker rm "$BACKEND_CONTAINER" fi -if [ "$(docker ps -q -f name=$FRONTEND_CONTAINER)" ]; then +if [ "$(docker ps -aq -f name=$FRONTEND_CONTAINER)" ]; then echo "Stopping old frontend container..." docker stop "$FRONTEND_CONTAINER" echo "Removing old frontend container..." @@ -38,7 +38,7 @@ if [ "$(docker ps -q -f name=$FRONTEND_CONTAINER)" ]; then fi echo "Running new backend container..." -docker run -d -p "$BACKEND_PORT":80 --name "$BACKEND_CONTAINER" "$BACKEND_IMAGE" +docker run -d -p "$BACKEND_PORT":80 --name "$BACKEND_CONTAINER" -v "$REPO_DIR/data:/app/data" "$BACKEND_IMAGE" echo "Running new frontend container..." docker run -d -p "$FRONTEND_PORT":80 --name "$FRONTEND_CONTAINER" "$FRONTEND_IMAGE"