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 . .
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

View File

@@ -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)
}

View File

@@ -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()

View File

@@ -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"