diff --git a/Dockerfile b/Dockerfile index 49e22ea..a300b20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ WORKDIR /app COPY go.mod go.sum* ./ RUN go mod download COPY *.go ./ +COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o main . # Etap minifikacji diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7201b98 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + app: + container_name: ${PROJECT_NAME:-fast-links} + build: + context: . + dockerfile: Dockerfile + ports: + - "${PORT:-8080}:8080" + volumes: + - app-data:/data + environment: + - PORT=8080 + - DATA_FILE_PATH=/data/data.db + restart: unless-stopped + +# Definiujemy wolumen Docker +volumes: + app-data: diff --git a/main.go b/main.go index 2ff596c..219d117 100644 --- a/main.go +++ b/main.go @@ -8,24 +8,17 @@ import ( "log" "mkedziora/fast-links/kvstore" "net/http" + "os" "strconv" "time" ) -// var ( -// dataMap map[string]DataEntry -// mu sync.Mutex -// ) - -// func init() { -// dataMap = make(map[string]DataEntry) -// } - var store *kvstore.KVStore func init() { var err error - store, err = kvstore.NewKVStore("data.db") + filePath := os.Getenv("DATA_FILE_PATH") + store, err = kvstore.NewKVStore(filePath) if err != nil { log.Fatalf("Failed to create KVStore: %v", err) } diff --git a/public/app.html b/public/app.html index 8e053a0..bec8feb 100644 --- a/public/app.html +++ b/public/app.html @@ -13,7 +13,18 @@