init project template blueprint with websocket

This commit is contained in:
2025-03-12 11:07:41 +07:00
parent 5a7e718666
commit ec15fe6cb5
4 changed files with 39 additions and 44 deletions

View File

@@ -1,22 +1,42 @@
FROM golang:1.23-alpine AS build
RUN apk add --no-cache curl
FROM golang:1.23 AS builder
# Install curl dan Tailwind dependencies
RUN apt-get update && apt-get install -y curl ca-certificates
WORKDIR /app
# Copy go.mod dan go.sum untuk dependency management
COPY go.mod go.sum ./
RUN go mod download
# Copy seluruh project
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/api
# Install Tailwind CSS untuk generate output.css
RUN go install github.com/a-h/templ/cmd/templ@latest && \
templ generate && \
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss && \
chmod +x tailwindcss && \
./tailwindcss -i cmd/web/assets/css/input.css -o cmd/web/assets/css/output.css
RUN go build -o main cmd/api/main.go
FROM alpine:latest
FROM alpine:3.20.1 AS prod
WORKDIR /app
COPY --from=build /app/main /app/main
EXPOSE ${PORT}
# Set timezone ke Asia/Jakarta
ENV TZ=Asia/Jakarta
# Install dependensi runtime yang diperlukan
RUN apk --no-cache add ca-certificates tzdata
WORKDIR /root/
# Copy binary yang sudah ter-build dari stage sebelumnya
COPY --from=builder /app/main .
COPY --from=builder /app/.env .
# Expose port aplikasi
EXPOSE 8803
# Jalankan aplikasi
CMD ["./main"]

View File

@@ -3,42 +3,14 @@ services:
build:
context: .
dockerfile: Dockerfile
target: prod
restart: unless-stopped
restart: always
ports:
- ${PORT}:${PORT}
- 8803:8803
environment:
APP_ENV: ${APP_ENV}
PORT: ${PORT}
BLUEPRINT_DB_HOST: ${BLUEPRINT_DB_HOST}
BLUEPRINT_DB_PORT: ${BLUEPRINT_DB_PORT}
BLUEPRINT_DB_USERNAME: ${BLUEPRINT_DB_USERNAME}
BLUEPRINT_DB_ROOT_PASSWORD: ${BLUEPRINT_DB_ROOT_PASSWORD}
depends_on:
mongo_bp:
condition: service_healthy
networks:
- blueprint
mongo_bp:
image: mongo:latest
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: ${BLUEPRINT_DB_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${BLUEPRINT_DB_ROOT_PASSWORD}
ports:
- "${BLUEPRINT_DB_PORT}:27017"
volumes:
- mongo_volume_bp:/data/db
healthcheck:
test: ["CMD","mongosh", "--eval", "db.adminCommand('ping')"]
interval: 5s
timeout: 5s
retries: 3
start_period: 15s
networks:
- blueprint
volumes:
mongo_volume_bp:
networks:
blueprint:
TZ: Asia/Jakarta
BLUEPRINT_DB_HOST: 10.10.123.206
BLUEPRINT_DB_PORT: 27017
BLUEPRINT_DB_USER: admin
BLUEPRINT_DB_PASS: stim*rs54
BLUEPRINT_DB_MASTER: master
BLUEPRINT_DB_LOCAL: local

1
go.mod
View File

@@ -9,6 +9,7 @@ require (
github.com/joho/godotenv v1.5.1
github.com/testcontainers/testcontainers-go/modules/mongodb v0.35.0
go.mongodb.org/mongo-driver v1.17.3
nhooyr.io/websocket v1.8.17
)
require (

2
go.sum
View File

@@ -280,4 +280,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y=
nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=