Skip to content

Commit

Permalink
Add docker file and docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
naeemaei committed Dec 25, 2022
1 parent 58aa88c commit c808907
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
14 changes: 14 additions & 0 deletions 17-Http/07-MiniProject/.DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.18-alpine as builder

WORKDIR /app

COPY go.* ./
RUN go mod download

COPY . ./

RUN go build -v -o server

COPY ./ ./app/server
EXPOSE 80
CMD ["/app/server"]
24 changes: 12 additions & 12 deletions 17-Http/07-MiniProject/handlers/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func GetMovies(w http.ResponseWriter, req *http.Request) {
}

// parse the movie data into json format
moviesJSON, err := json.Marshal(&movies)
if err != nil {
utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
return
}
// moviesJSON, err := json.Marshal(&movies)
// if err != nil {
// utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
// return
// }

utils.SetResult(w, http.StatusOK, moviesJSON, nil)
utils.SetResult(w, http.StatusOK, movies, nil)
}

func GetMovie(w http.ResponseWriter, req *http.Request) {
Expand All @@ -75,13 +75,13 @@ func GetMovie(w http.ResponseWriter, req *http.Request) {
}

// parse the movie data into json format
movieJSON, err := json.Marshal(&movie)
if err != nil {
utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
return
}
// movieJSON, err := json.Marshal(&movie)
// if err != nil {
// utils.SetResult(w, http.StatusInternalServerError, nil, utils.ApiError{Id: "jsonMarshal", Message: "Error parsing the movie data" + err.Error()})
// return
// }

utils.SetResult(w, http.StatusOK, movieJSON, nil)
utils.SetResult(w, http.StatusOK, movie, nil)
}

func AddMovie(w http.ResponseWriter, req *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion 17-Http/07-MiniProject/management/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func Run() {
mux := http.NewServeMux()
mux.Handle("/users/", &handlers.MovieHandler{})
mux.Handle("/movies/", &handlers.MovieHandler{})
server := &http.Server{
Addr: ":8080",
ReadTimeout: time.Second * 10,
Expand Down
29 changes: 29 additions & 0 deletions 20-Docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'
services:
postgres:
container_name: pgdb
image: postgres
hostname: postgres
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: admin
POSTGRES_DB: TEST_SM
volumes:
- postgres-data:/var/lib/postgresql/data
restart: unless-stopped

pgadmin:
image: dpage/pgadmin4
depends_on:
- postgres
ports:
- "8090:80"
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: admin
restart: unless-stopped

volumes:
postgres-data:

0 comments on commit c808907

Please sign in to comment.