From d4c11c12bea0d87633f6d626663b05f996038482 Mon Sep 17 00:00:00 2001 From: ulflow_phattt2901 Date: Wed, 21 May 2025 15:12:24 +0700 Subject: [PATCH] : Update port 3000 & update makefile Change port and update makefile for Windows --- .gitea/workflows/docker.yml | 6 ++-- Dockerfile | 18 ++++++------ Dockerfile.local | 2 +- Makefile | 41 ++++++++++++++------------- configs/config.yaml | 2 +- docker-compose.prod.yml | 4 +-- docker-compose.yml | 2 +- docs/secrets.md | 4 +-- go.sum | 4 +-- internal/helper/config/load.go | 6 ++-- internal/helper/logger/logger_test.go | 5 +++- templates/.env.example | 2 +- templates/config.example.yaml | 2 +- 13 files changed, 53 insertions(+), 45 deletions(-) diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml index b5da0a0..da3aadc 100644 --- a/.gitea/workflows/docker.yml +++ b/.gitea/workflows/docker.yml @@ -90,7 +90,7 @@ jobs: --name ${{ secrets.CONTAINER_NAME || 'ulflow-api-container' }} \ --network ${{ secrets.DOCKER_NETWORK || 'ulflow-network' }} \ --restart always \ - -p ${{ secrets.APP_PORT || '8080' }}:8080 \ + -p ${{ secrets.APP_PORT || '3000' }}:3000 \ -e APP_ENV=${{ secrets.APP_ENV || 'production' }} \ -e DB_HOST=${{ secrets.DB_HOST }} \ -e DB_USER=${{ secrets.DB_USER }} \ @@ -100,7 +100,7 @@ jobs: -e REFRESH_TOKEN_SECRET=${{ secrets.REFRESH_TOKEN_SECRET }} \ -e API_KEY=${{ secrets.API_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' }} \ --memory ${{ secrets.CONTAINER_MEMORY || '1g' }} \ --cpus ${{ secrets.CONTAINER_CPU || '1' }} \ @@ -121,7 +121,7 @@ jobs: fi # 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!" diff --git a/Dockerfile b/Dockerfile index 072d95f..2f923a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,11 +16,14 @@ COPY go.mod go.sum* ./ # Download dependencies RUN go mod download -# Copy the entire project +# Copy source code 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 -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 FROM alpine:3.19 @@ -38,10 +41,9 @@ RUN adduser -D -g '' appuser RUN mkdir -p /app/config /app/logs /app/storage WORKDIR /app -# Copy binary from builder stage -COPY --from=builder /build/bin/api /app/ -COPY --from=builder /build/config /app/config - +# Copy binary and configs +COPY --from=builder /build/bin/app /app/ +COPY --from=builder /build/configs /app/configs # Set ownership RUN chown -R appuser:appuser /app @@ -49,10 +51,10 @@ RUN chown -R appuser:appuser /app USER appuser # Expose port -EXPOSE 8080 +EXPOSE 3000 # Set environment variable for production ENV APP_ENV=production # Command to run the application -ENTRYPOINT ["/app/api"] +ENTRYPOINT ["./app"] diff --git a/Dockerfile.local b/Dockerfile.local index b112c1a..901398e 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -23,7 +23,7 @@ RUN go mod download COPY . . # Expose port -EXPOSE 8080 +EXPOSE 3000 # Set environment variable for development ENV APP_ENV=development diff --git a/Makefile b/Makefile index 1b0a244..cbda1fb 100644 --- a/Makefile +++ b/Makefile @@ -61,14 +61,14 @@ lint: # Build the application binary build: @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: @echo "Cleaning project..." - rm -rf tmp/ - rm -rf bin/ - rm -rf logs/*.log + if exist tmp rmdir /s /q tmp + if exist bin rmdir /s /q bin + if exist logs rmdir /s /q logs go clean -cache -testcache -modcache @echo "Project cleaned!" @@ -80,13 +80,18 @@ docker-build: # Run application in Docker container docker-run: @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 docker-compose-up: @echo "Starting all services with Docker Compose for local development..." 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 docker-compose-down: @@ -97,7 +102,7 @@ docker-compose-down: docker-compose-prod-up: @echo "Starting all services with Docker Compose for production..." 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 docker-compose-prod-down: @@ -105,19 +110,19 @@ docker-compose-prod-down: docker-compose -f docker-compose.prod.yml down # Setup Git configuration -setup-git: - @echo "Setting up Git configuration..." +setup-git-hooks: + @echo "Setting up Git hooks..." git config --local commit.template .gitea/commit-template.txt - cp .gitea/hooks/pre-commit .git/hooks/ - cp .gitea/hooks/prepare-commit-msg .git/hooks/ - chmod +x .git/hooks/pre-commit - chmod +x .git/hooks/prepare-commit-msg + if not exist .git/hooks mkdir .git/hooks + copy /Y .gitea\hooks\pre-commit .git\hooks\ >nul + copy /Y .gitea\hooks\prepare-commit-msg .git\hooks\ >nul git config --local core.hooksPath .git/hooks @echo "Git setup complete!" # Create git message template setup-git-message: @echo "Creating Git commit message template..." + if not exist .gitea mkdir .gitea mkdir -p .gitea echo "# : \n\n# \n\n#