Skip to content

Commit

Permalink
docker
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsuthar69 committed Oct 3, 2024
1 parent 69fc1c7 commit 82e8aec
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.env
tmp
tailwindcss
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:1.23

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN curl -L https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o /usr/local/bin/tailwindcss

RUN chmod +x /usr/local/bin/tailwindcss

RUN go install github.com/a-h/templ/cmd/templ@latest

RUN which templ && templ --version

RUN templ generate

RUN tailwindcss -i ./static/css/input.css -o ./static/css/style.css --minify

RUN go build -o main ./main.go

EXPOSE 8080

CMD ["./main"]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ air

## Installation Guide

1. Using Docker

```
docker pull amitsuthar69/gotth:1.0
```

```
docker run -p 8080:8080 amitsuthar69/gotth:1.0
```

OR

2. Build from source

### Clone repository

```
git clone https://github.com/amitsuthar69/GoTTH.git
```

### Air for Live Reload

```bash
Expand Down
5 changes: 1 addition & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package server
import (
"fmt"
"net/http"
"os"
"strconv"
"time"

_ "github.com/joho/godotenv/autoload"
Expand All @@ -18,8 +16,7 @@ type Server struct {
db database.Service
}

func NewServer() *http.Server {
port, _ := strconv.Atoi(os.Getenv("PORT"))
func NewServer(port int) *http.Server {
NewServer := &Server{
port: port,

Expand Down
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@ package main
import (
"fmt"
"gotth/internal/server"
"log"
"os"
"strconv"
)

func main() {
portStr := os.Getenv("PORT")
if portStr == "" {
portStr = "8080" // Default port
}

port, err := strconv.Atoi(portStr)
if err != nil {
log.Fatalf("Failed to parse PORT: %v", err)
}

server := server.NewServer()
server := server.NewServer(port)

err := server.ListenAndServe()
err = server.ListenAndServe()
if err != nil {
panic(fmt.Sprintf("cannot start server: %s", err))
}
Expand Down

0 comments on commit 82e8aec

Please sign in to comment.