<chore>: Update port 3000 & update makefile

Change port and update makefile for Windows
This commit is contained in:
ulflow_phattt2901 2025-05-21 15:12:24 +07:00
parent 86cff0489e
commit d4c11c12be
13 changed files with 53 additions and 45 deletions

View File

@ -90,7 +90,7 @@ jobs:
--name ${{ secrets.CONTAINER_NAME || 'ulflow-api-container' }} \ --name ${{ secrets.CONTAINER_NAME || 'ulflow-api-container' }} \
--network ${{ secrets.DOCKER_NETWORK || 'ulflow-network' }} \ --network ${{ secrets.DOCKER_NETWORK || 'ulflow-network' }} \
--restart always \ --restart always \
-p ${{ secrets.APP_PORT || '8080' }}:8080 \ -p ${{ secrets.APP_PORT || '3000' }}:3000 \
-e APP_ENV=${{ secrets.APP_ENV || 'production' }} \ -e APP_ENV=${{ secrets.APP_ENV || 'production' }} \
-e DB_HOST=${{ secrets.DB_HOST }} \ -e DB_HOST=${{ secrets.DB_HOST }} \
-e DB_USER=${{ secrets.DB_USER }} \ -e DB_USER=${{ secrets.DB_USER }} \
@ -100,7 +100,7 @@ jobs:
-e REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }} \ -e REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }} \
-e API_KEY=${{ secrets.API_KEY }} \ -e API_KEY=${{ secrets.API_KEY }} \
-e ENCRYPTION_KEY=${{ secrets.ENCRYPTION_KEY }} \ -e ENCRYPTION_KEY=${{ secrets.ENCRYPTION_KEY }} \
--health-cmd "${{ secrets.HEALTH_CMD || 'curl -f http://localhost:8080/health || exit 1' }}" \ --health-cmd "${{ secrets.HEALTH_CMD || 'curl -f http://localhost:3000/health || exit 1' }}" \
--health-interval ${{ secrets.HEALTH_INTERVAL || '30s' }} \ --health-interval ${{ secrets.HEALTH_INTERVAL || '30s' }} \
--memory ${{ secrets.CONTAINER_MEMORY || '1g' }} \ --memory ${{ secrets.CONTAINER_MEMORY || '1g' }} \
--cpus ${{ secrets.CONTAINER_CPU || '1' }} \ --cpus ${{ secrets.CONTAINER_CPU || '1' }} \
@ -121,7 +121,7 @@ jobs:
fi fi
# Check health endpoint # Check health endpoint
curl -f http://localhost:${{ secrets.APP_PORT || '8080' }}/health || (echo "::error::Health check failed" && exit 1) curl -f http://localhost:${{ secrets.APP_PORT || '3000' }}/health || (echo "::error::Health check failed" && exit 1)
echo "::notice::Deployment successful!" echo "::notice::Deployment successful!"

View File

@ -16,11 +16,14 @@ COPY go.mod go.sum* ./
# Download dependencies # Download dependencies
RUN go mod download RUN go mod download
# Copy the entire project # Copy source code
COPY . . COPY . .
# Create the configs directory in the build context
RUN mkdir -p /build/configs && \
cp -r configs/* /build/configs/ 2>/dev/null || :
# Build the application with optimizations # Build the application with optimizations
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /build/bin/api ./cmd/api RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /build/bin/app ./cmd/app
# Final stage # Final stage
FROM alpine:3.19 FROM alpine:3.19
@ -38,10 +41,9 @@ RUN adduser -D -g '' appuser
RUN mkdir -p /app/config /app/logs /app/storage RUN mkdir -p /app/config /app/logs /app/storage
WORKDIR /app WORKDIR /app
# Copy binary from builder stage # Copy binary and configs
COPY --from=builder /build/bin/api /app/ COPY --from=builder /build/bin/app /app/
COPY --from=builder /build/config /app/config COPY --from=builder /build/configs /app/configs
# Set ownership # Set ownership
RUN chown -R appuser:appuser /app RUN chown -R appuser:appuser /app
@ -49,10 +51,10 @@ RUN chown -R appuser:appuser /app
USER appuser USER appuser
# Expose port # Expose port
EXPOSE 8080 EXPOSE 3000
# Set environment variable for production # Set environment variable for production
ENV APP_ENV=production ENV APP_ENV=production
# Command to run the application # Command to run the application
ENTRYPOINT ["/app/api"] ENTRYPOINT ["./app"]

View File

@ -23,7 +23,7 @@ RUN go mod download
COPY . . COPY . .
# Expose port # Expose port
EXPOSE 8080 EXPOSE 3000
# Set environment variable for development # Set environment variable for development
ENV APP_ENV=development ENV APP_ENV=development

View File

@ -61,14 +61,14 @@ lint:
# Build the application binary # Build the application binary
build: build:
@echo "Building application..." @echo "Building application..."
go build -o bin/api cmd/api/main.go go build -o bin/app cmd/app/main.go
# Clean temporary files, build artifacts, and cache # Clean temporary files, build artifacts, and cache
clean: clean:
@echo "Cleaning project..." @echo "Cleaning project..."
rm -rf tmp/ if exist tmp rmdir /s /q tmp
rm -rf bin/ if exist bin rmdir /s /q bin
rm -rf logs/*.log if exist logs rmdir /s /q logs
go clean -cache -testcache -modcache go clean -cache -testcache -modcache
@echo "Project cleaned!" @echo "Project cleaned!"
@ -80,13 +80,18 @@ docker-build:
# Run application in Docker container # Run application in Docker container
docker-run: docker-run:
@echo "Running application in Docker container..." @echo "Running application in Docker container..."
docker run -p 8080:8080 --env-file .env ulflow-starter-kit:latest @if not exist .env (
@echo "Warning: .env file not found. Running with default environment variables..."
docker run -p 3000:3000 ulflow-starter-kit:latest
) else (
docker run -p 3000:3000 --env-file .env ulflow-starter-kit:latest
)
# Run Docker Compose for local development # Run Docker Compose for local development
docker-compose-up: docker-compose-up:
@echo "Starting all services with Docker Compose for local development..." @echo "Starting all services with Docker Compose for local development..."
docker-compose up -d docker-compose up -d
@echo "Services started! API is available at http://localhost:8080" @echo "Services started! API is available at http://localhost:3000"
# Stop Docker Compose services for local development # Stop Docker Compose services for local development
docker-compose-down: docker-compose-down:
@ -97,7 +102,7 @@ docker-compose-down:
docker-compose-prod-up: docker-compose-prod-up:
@echo "Starting all services with Docker Compose for production..." @echo "Starting all services with Docker Compose for production..."
docker-compose -f docker-compose.prod.yml up -d docker-compose -f docker-compose.prod.yml up -d
@echo "Production services started! API is available at http://localhost:8080" @echo "Production services started! API is available at http://localhost:3000"
# Stop Docker Compose services for production # Stop Docker Compose services for production
docker-compose-prod-down: docker-compose-prod-down:
@ -105,19 +110,19 @@ docker-compose-prod-down:
docker-compose -f docker-compose.prod.yml down docker-compose -f docker-compose.prod.yml down
# Setup Git configuration # Setup Git configuration
setup-git: setup-git-hooks:
@echo "Setting up Git configuration..." @echo "Setting up Git hooks..."
git config --local commit.template .gitea/commit-template.txt git config --local commit.template .gitea/commit-template.txt
cp .gitea/hooks/pre-commit .git/hooks/ if not exist .git/hooks mkdir .git/hooks
cp .gitea/hooks/prepare-commit-msg .git/hooks/ copy /Y .gitea\hooks\pre-commit .git\hooks\ >nul
chmod +x .git/hooks/pre-commit copy /Y .gitea\hooks\prepare-commit-msg .git\hooks\ >nul
chmod +x .git/hooks/prepare-commit-msg
git config --local core.hooksPath .git/hooks git config --local core.hooksPath .git/hooks
@echo "Git setup complete!" @echo "Git setup complete!"
# Create git message template # Create git message template
setup-git-message: setup-git-message:
@echo "Creating Git commit message template..." @echo "Creating Git commit message template..."
if not exist .gitea mkdir .gitea
mkdir -p .gitea mkdir -p .gitea
echo "# <type>: <subject>\n\n# <body>\n\n# <footer>\n\n# Types:\n# feat (new feature)\n# fix (bug fix)\n# docs (documentation changes)\n# style (formatting, no code change)\n# refactor (refactoring code)\n# test (adding tests, refactoring tests)\n# chore (updating tasks etc; no production code change)" > .gitea/commit-template.txt echo "# <type>: <subject>\n\n# <body>\n\n# <footer>\n\n# Types:\n# feat (new feature)\n# fix (bug fix)\n# docs (documentation changes)\n# style (formatting, no code change)\n# refactor (refactoring code)\n# test (adding tests, refactoring tests)\n# chore (updating tasks etc; no production code change)" > .gitea/commit-template.txt
git config --local commit.template .gitea/commit-template.txt git config --local commit.template .gitea/commit-template.txt
@ -126,7 +131,9 @@ setup-git-message:
# Clean Docker containers related to this project # Clean Docker containers related to this project
docker-clean: docker-clean:
@echo "Cleaning Docker containers..." @echo "Cleaning Docker containers..."
docker ps -a | grep ulflow-starter-kit | awk '{print $$1}' | xargs -r docker rm -f @if [ -x "$$(command -v docker)" ]; then \
docker ps -aq --filter "name=ulflow-starter-kit" | xargs -r docker rm -f; \
fi
@echo "Docker containers cleaned!" @echo "Docker containers cleaned!"
# Prune all unused Docker resources # Prune all unused Docker resources
@ -143,8 +150,6 @@ ci:
make build make build
make docker-build make docker-build
@echo "CI simulation completed!" @echo "CI simulation completed!"
@echo "Cleaning up after CI..."
make docker-clean
# Run everything (lint, test, build) # Run everything (lint, test, build)
all: lint test build all: lint test build
@ -165,7 +170,3 @@ migrate-down:
# Run application (default: without hot reload) # Run application (default: without hot reload)
run: run:
go run ./cmd/app/main.go go run ./cmd/app/main.go
# Run application with hot reload
dev:
air -c .air.toml

View File

@ -9,7 +9,7 @@ logger:
server: server:
host: "localhost" host: "localhost"
port: 8080 port: 3000
read_timeout: 15 read_timeout: 15
write_timeout: 15 write_timeout: 15
shutdown_timeout: 30 shutdown_timeout: 30

View File

@ -9,7 +9,7 @@ services:
container_name: ulflow-api container_name: ulflow-api
restart: always restart: always
ports: ports:
- "8080:8080" - "3000:3000"
env_file: env_file:
- .env - .env
environment: environment:
@ -27,7 +27,7 @@ services:
condition: on-failure condition: on-failure
max_attempts: 3 max_attempts: 3
healthcheck: healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://localhost:8080/health"] test: ["CMD", "wget", "--spider", "-q", "http://localhost:3000/health"]
interval: 30s interval: 30s
timeout: 10s timeout: 10s
retries: 3 retries: 3

View File

@ -9,7 +9,7 @@ services:
container_name: ulflow-api container_name: ulflow-api
restart: unless-stopped restart: unless-stopped
ports: ports:
- "8080:8080" - "3000:3000"
volumes: volumes:
- .:/app - .:/app
- go-modules:/go/pkg/mod - go-modules:/go/pkg/mod

View File

@ -58,11 +58,11 @@ Bao gồm các job:
|--------|-------|----------| |--------|-------|----------|
| `CONTAINER_NAME` | Tên container | `ulflow-api-container` | | `CONTAINER_NAME` | Tên container | `ulflow-api-container` |
| `DOCKER_NETWORK` | Tên network Docker | `ulflow-network` | | `DOCKER_NETWORK` | Tên network Docker | `ulflow-network` |
| `APP_PORT` | Port để expose | `8080` | | `APP_PORT` | Port để expose | `3000` |
| `APP_ENV` | Môi trường ứng dụng | `production` | | `APP_ENV` | Môi trường ứng dụng | `production` |
| `CONTAINER_MEMORY` | Giới hạn bộ nhớ | `1g` | | `CONTAINER_MEMORY` | Giới hạn bộ nhớ | `1g` |
| `CONTAINER_CPU` | Giới hạn CPU | `1` | | `CONTAINER_CPU` | Giới hạn CPU | `1` |
| `HEALTH_CMD` | Command kiểm tra health | `curl -f http://localhost:8080/health || exit 1` | | `HEALTH_CMD` | Command kiểm tra health | `curl -f http://localhost:3000/health || exit 1` |
| `HEALTH_INTERVAL` | Khoảng thời gian kiểm tra health | `30s` | | `HEALTH_INTERVAL` | Khoảng thời gian kiểm tra health | `30s` |
### Secrets cho Database ### Secrets cho Database

4
go.sum
View File

@ -294,7 +294,7 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20191125130003-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
@ -406,7 +406,7 @@ golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20130007135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View File

@ -64,7 +64,9 @@ func (l *ViperConfigLoader) Load() (*Config, error) {
// Set default logger level // Set default logger level
if os.Getenv("LOG_LEVEL") == "" { if os.Getenv("LOG_LEVEL") == "" {
os.Setenv("LOG_LEVEL", "info") if err := os.Setenv("LOG_LEVEL", "info"); err != nil {
return nil, fmt.Errorf("failed to set LOG_LEVEL: %v", err)
}
} }
// Bind cấu hình vào struct // Bind cấu hình vào struct
@ -92,7 +94,7 @@ func setDefaultValues(v *viper.Viper) {
// Server defaults // Server defaults
v.SetDefault("server.host", "0.0.0.0") v.SetDefault("server.host", "0.0.0.0")
v.SetDefault("server.port", 8080) v.SetDefault("server.port", 3000)
v.SetDefault("server.read_timeout", 15) // seconds v.SetDefault("server.read_timeout", 15) // seconds
v.SetDefault("server.write_timeout", 15) // seconds v.SetDefault("server.write_timeout", 15) // seconds
v.SetDefault("server.shutdown_timeout", 30) // seconds v.SetDefault("server.shutdown_timeout", 30) // seconds

View File

@ -3,6 +3,7 @@ package logger
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"os" "os"
"strings" "strings"
@ -47,7 +48,9 @@ func captureOutput(f func()) string {
f() f()
// Close the writer // Close the writer
w.Close() if err := w.Close(); err != nil {
panic(fmt.Sprintf("failed to close writer: %v", err))
}
// Read the output // Read the output
var buf bytes.Buffer var buf bytes.Buffer

View File

@ -9,7 +9,7 @@ APP_LOGGER_LEVEL=info # debug, info, warn, error
# Server Configuration # Server Configuration
APP_SERVER_HOST=0.0.0.0 APP_SERVER_HOST=0.0.0.0
APP_SERVER_PORT=8080 APP_SERVER_PORT=3000
APP_SERVER_READ_TIMEOUT=15 APP_SERVER_READ_TIMEOUT=15
APP_SERVER_WRITE_TIMEOUT=15 APP_SERVER_WRITE_TIMEOUT=15
APP_SERVER_SHUTDOWN_TIMEOUT=30 APP_SERVER_SHUTDOWN_TIMEOUT=30

View File

@ -9,7 +9,7 @@ logger:
server: server:
host: "0.0.0.0" host: "0.0.0.0"
port: 8080 port: 3000
read_timeout: 15 read_timeout: 15
write_timeout: 15 write_timeout: 15
shutdown_timeout: 30 shutdown_timeout: 30