commit 0487e3771a2053d19ee40a8dcd1181630b072ad9 Author: valitovgaziz Date: Sun Aug 4 22:40:36 2024 +0500 init commit. Makefile. Dokerimage, Dockerfile, Docker-compose.yaml diff --git a/.env b/.env new file mode 100644 index 0000000..cfa95af --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +DB_USER=postgres +DB_PASSWORD=postgres +DB_NAME=postgres +DB_PORT=5432 +HOST_DB=db +SERVER_PORT=8000 \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c5992eb --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +build: + @docker compose build + +run: build + @docker compose up + +clean: + @docker builder prune + +.DEFAULT_GOAL=run \ No newline at end of file diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 0000000..0a7bda9 --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.22.5 + +WORKDIR /app + +COPY . . + +RUN go mod tidy + +RUN go build -o bin/api.exe cmd/main.go + +ENTRYPOINT [ "bin/api.exe" ] \ No newline at end of file diff --git a/api/bin/api.exe b/api/bin/api.exe new file mode 100644 index 0000000..4dc983e Binary files /dev/null and b/api/bin/api.exe differ diff --git a/api/cmd/main.go b/api/cmd/main.go new file mode 100644 index 0000000..3471ade --- /dev/null +++ b/api/cmd/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "net/http" + + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" +) + +func main() { + r := chi.NewRouter() + r.Use(middleware.Logger) + r.Get("/", func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("welcome developer")) + }) + http.ListenAndServe(":8000", r) +} diff --git a/api/go.mod b/api/go.mod new file mode 100644 index 0000000..eda5c8a --- /dev/null +++ b/api/go.mod @@ -0,0 +1,5 @@ +module api + +go 1.22.5 + +require github.com/go-chi/chi/v5 v5.1.0 diff --git a/api/go.sum b/api/go.sum new file mode 100644 index 0000000..823cdbb --- /dev/null +++ b/api/go.sum @@ -0,0 +1,2 @@ +github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= +github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..a89d5de --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,31 @@ +services: + + # db: + # image: postgres:16 + # env_file: + # - .env + # environment: + # - POSTGRES_USER=${DB_USER} + # - POSTGRES_PASSWORD=${DB_PASSWORD} + # - POSTGRES_DB=${DB_NAME} + # ports: + # - "${DB_PORT}:${DB_PORT}" + # volumes: + # - postgres-db:/var/lib/postgresql/data + + + api: + build: + context: ./api + dockerfile: Dockerfile + env_file: + - .env + ports: + - "${SERVER_PORT}:${SERVER_PORT}" + volumes: + - .:/usr/src/app + # depends_on: + # - db + +# volumes: +# postgres-db: \ No newline at end of file