updating dockerfiles and minor things

This commit is contained in:
2024-09-22 11:50:48 +02:00
parent 87d679464a
commit cf5d311731
6 changed files with 18 additions and 10 deletions

0
data/.gitkeep Normal file
View File

BIN
data/database.db Normal file

Binary file not shown.

View File

@@ -7,13 +7,13 @@ RUN go mod download
COPY . . COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o main . RUN CGO_ENABLED=1 GOOS=linux go build -o main .
FROM gcr.io/distroless/base-debian11
FROM ubuntu:latest
WORKDIR /app WORKDIR /app
COPY --from=builder /app/main . COPY --from=builder /app/main .
COPY --from=builder /app/dev.env .
EXPOSE 80 EXPOSE 80

View File

@@ -32,7 +32,7 @@ const (
func InitDB() { func InitDB() {
var err error var err error
db, err = sql.Open("sqlite3", "database.db") db, err = sql.Open("sqlite3", "data/database.db")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@@ -2,16 +2,24 @@ package main
import ( import (
"fmt" "fmt"
"os"
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
func main() { func main() {
if ok := godotenv.Load("dev.env"); ok != nil { if value := os.Getenv("ENV"); value == "prod" {
panic(".env not found") 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() InitDB()
err := run() err := run()

View File

@@ -23,14 +23,14 @@ docker build -t "$BACKEND_IMAGE" "$REPO_DIR/proxy" # Assuming proxy is the backe
echo "Building frontend Docker image..." echo "Building frontend Docker image..."
docker build -t "$FRONTEND_IMAGE" "$REPO_DIR/frontend" # Assuming frontend is the frontend directory 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..." echo "Stopping old backend container..."
docker stop "$BACKEND_CONTAINER" docker stop "$BACKEND_CONTAINER"
echo "Removing old backend container..." echo "Removing old backend container..."
docker rm "$BACKEND_CONTAINER" docker rm "$BACKEND_CONTAINER"
fi fi
if [ "$(docker ps -q -f name=$FRONTEND_CONTAINER)" ]; then if [ "$(docker ps -aq -f name=$FRONTEND_CONTAINER)" ]; then
echo "Stopping old frontend container..." echo "Stopping old frontend container..."
docker stop "$FRONTEND_CONTAINER" docker stop "$FRONTEND_CONTAINER"
echo "Removing old frontend container..." echo "Removing old frontend container..."
@@ -38,7 +38,7 @@ if [ "$(docker ps -q -f name=$FRONTEND_CONTAINER)" ]; then
fi fi
echo "Running new backend container..." 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..." echo "Running new frontend container..."
docker run -d -p "$FRONTEND_PORT":80 --name "$FRONTEND_CONTAINER" "$FRONTEND_IMAGE" docker run -d -p "$FRONTEND_PORT":80 --name "$FRONTEND_CONTAINER" "$FRONTEND_IMAGE"