Skip to content

Commit

Permalink
chore: docker file, healthcheck route
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyoptimist committed Jan 27, 2024
1 parent e9ca2ab commit bd48c5b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ vet:
build:
CGO_ENABLED=0 GOOS=linux go build -o ./bin/ ./...
db_migrate:
go run ./cmd/api/migrate/default.go
go run ./cmd/migrator/main.go
docs_generate:
rm -rf docs/* && swag init
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ make db_migrate

## Development

Create a dotenv file.
Create `.env` file.

```bash
cp .env.example .env
Expand Down Expand Up @@ -43,7 +43,7 @@ Binaries will be generated inside `PROJECT_ROOT/bin/`

[gin-swagger](https://github.com/swaggo/gin-swagger) is used for API documentation.

To browse docs, open `BASE_URL/swagger/index.html`.
To browse the API documentation, open `BASE_URL/swagger/index.html`.

Generate/update docs:

Expand Down
6 changes: 4 additions & 2 deletions deployments/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ version: "3"

services:
api:
container_name: api
build: .
container_name: gin-api
build:
context: ../
dockerfile: ./prod.Dockerfile
ports:
- "8080:8080"
restart: unless-stopped
12 changes: 6 additions & 6 deletions deployments/Dockerfile → deployments/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
## STEP 1 - BUILD
## STAGE 1 - BUILD
##

FROM golang:1.20 as builder
Expand All @@ -23,22 +23,22 @@ RUN go mod verify

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/app .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/server ./cmd/server

##
## STEP 2 - DEPLOY
## STAGE 2 - DEPLOY
##

FROM scratch

COPY --from=builder /source/bin/app /app
COPY --from=builder /source/bin/server /server

COPY .env /.env
ENV TWELVE_FACTOR_MODE true

COPY --from=builder /etc/passwd /etc/passwd

USER 1001

EXPOSE 8080

ENTRYPOINT ["/app"]
ENTRYPOINT ["/server"]
8 changes: 7 additions & 1 deletion internal/router/router.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package router

import (
"net/http"

"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
Expand All @@ -13,9 +15,13 @@ func RegisterRoutes() *gin.Engine {
router := gin.New()

router.Use(gin.Logger())

router.Use(gin.Recovery())

// Health check route
router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "OK")
})

v1 := router.Group("/api")
{
authGroup := v1.Group("/auth")
Expand Down

0 comments on commit bd48c5b

Please sign in to comment.