Skip to content

Commit

Permalink
add docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
Boonyarit Rousamran authored and hokkung committed Jun 27, 2024
1 parent 8ab771e commit 8de1b5b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.22-alpine3.19 AS builder

RUN apk update && \
apk add --no-cache \
git

WORKDIR /app

COPY go.mod go.sum ./
COPY . ./

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '' -a -installsuffix cgo -o go-groceries-api ./cmd/api

FROM alpine:latest

RUN apk update && \
apk add --no-cache ca-certificates && \
apk add --no-cache tzdata

ENV TZ=Asia/Bangkok

WORKDIR /root/

COPY --from=builder /app/go-groceries-api /root/api/main

EXPOSE 8081

ENTRYPOINT ["./api/main"]
18 changes: 18 additions & 0 deletions docker-compose/go-groceries-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.1'
services:
go-groceries-api:
image: go-groceries
container_name: go-groceries-api
restart: always
environment:
APP_NAME: groceries_api
APP_MYSQL_HOST: mysql
APP_MYSQL_PORT: 3306
APP_MYSQL_DB_NAME: grocery
APP_MYSQL_USERNAME: root
APP_MYSQL_PASSWORD: root
APP_SRV_SERVER_ADDR: :8081
ports:
- "8081:8081"

## docker compose -f [FILE_NAME] up
6 changes: 3 additions & 3 deletions docker-compose/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ services:
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
- "3306:3306"
phpmyadmin:
image: phpmyadmin
ports:
- 8080:80
- "8080:80"
depends_on:
- db

## docker compose -f [FILE_NAME] up
## docker compose -f [FILE_NAME] up
3 changes: 2 additions & 1 deletion pkg/env/env.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package env

import (
"fmt"
"github.com/joho/godotenv"
)

func MustLoadEnv() {
err := godotenv.Load()
if err != nil {
panic(err)
fmt.Println("cannot find .env file")
}
}

0 comments on commit 8de1b5b

Please sign in to comment.