Skip to content

Commit

Permalink
env and makefile fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesut GENEZ committed Jun 14, 2024
1 parent c8c54b5 commit 720b8cf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PROJECT_ENDPOINT=http://localhost:9090
APP_NAME=cdn
APP_PORT=8080
APP_URL=http://localhost:$(APP_PORT)

MINIO_ENDPOINT=cdn-minio:9000
MINIO_ROOT_USER=minio
Expand Down
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"strings"

Expand Down Expand Up @@ -103,7 +104,8 @@ func main() {
return c.SendFile("./public/index.html")
})

log.Fatal(app.Listen(":9090"))
port := fmt.Sprintf(":%s", service.GetEnv("APP_PORT"))
log.Fatal(app.Listen(port))

}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
container_name: cdn-golang
restart: always
ports:
- "9090:9090"
- "${APP_PORT}:${APP_PORT}"
logging:
driver: none
volumes:
Expand Down
4 changes: 2 additions & 2 deletions handler/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (i image) UploadImageWithUrl(c *fiber.Ctx) error {
// Upload with PutObject
minioResult, err := i.minioService.PutObject(ctx, bucket, objectName, res.Body, int64(fileSize), minio.PutObjectOptions{ContentType: contentType})

url = service.GetEnv("PROJECT_ENDPOINT")
url = service.GetEnv("APP_URL")
url = strings.TrimSuffix(url, "/")
link := url + "/" + bucket + "/" + objectName

Expand Down Expand Up @@ -322,7 +322,7 @@ func (i image) commonUpload(c *fiber.Ctx, ctx context.Context, path, bucket stri
return service.Response(c, fiber.StatusBadRequest, false, err.Error(), nil)
}

url := service.GetEnv("PROJECT_ENDPOINT")
url := service.GetEnv("APP_URL")
url = strings.TrimSuffix(url, "/")
link := url + "/" + bucket + "/" + objectName

Expand Down
40 changes: 35 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,38 @@ down:
clean:
docker rmi $(docker images -f "dangling=true" -q)

run_api:
docker run -d --restart=always -p 8080:9090 --name cdn-golang --network=cdn_cdn cdn-golang bash -c "go build -o CdnApp && ./CdnApp"

run_minio:
docker run -d --restart always -p 9000:9000 -p 9001:9001 --name cdn-minio --volume=minio:/var/lib/minio -e MINIO_ROOT_USER='${MINIO_ROOT_USER}' -e MINIO_ROOT_PASSWORD='${MINIO_ROOT_PASSWORD}' minio/minio server --console-address ":9001" /var/lib/minio
run_api: create_volume create_network
docker run -d \
-v ./:/app \
--restart=always \
--name cdn-golang \
--log-driver none \
--network=$(APP_NAME) \
-p $(APP_PORT):$(APP_PORT) \
cdn-golang bash -c "go build -o CdnApp && ./CdnApp"

run_minio: create_network
docker run -d \
-p 9000:9000 \
-p 9001:9001 \
--name cdn-minio \
--restart always \
--network=$(APP_NAME) \
--volume=minio:/var/lib/minio \
-e MINIO_ROOT_USER='${MINIO_ROOT_USER}' \
-e MINIO_ROOT_PASSWORD='${MINIO_ROOT_PASSWORD}' \
minio/minio server --console-address ":9001" /var/lib/minio

create_network:
@if ! docker network inspect $(APP_NAME) >/dev/null 2>&1; then \
docker network create $(APP_NAME); \
else \
echo "Network '$(APP_NAME)' already exists, using existing network."; \
fi

create_volume:
@if ! docker volume inspect $(APP_NAME) >/dev/null 2>&1; then \
docker volume create $(APP_NAME); \
else \
echo "Volume '$(APP_NAME)' already exists, skipping creation."; \
fi

0 comments on commit 720b8cf

Please sign in to comment.