From 0a52786c869ba66c8b8c8c42d2653ee7ff5b16e8 Mon Sep 17 00:00:00 2001 From: kaedwen Date: Sat, 4 Jul 2026 20:55:56 +0200 Subject: [PATCH] build debug Signed-off-by: kaedwen --- .gitea/workflows/docker.yaml | 30 +++++++++++++++- Dockerfile.debug | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.debug diff --git a/.gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml index d868a9f..18fe42c 100644 --- a/.gitea/workflows/docker.yaml +++ b/.gitea/workflows/docker.yaml @@ -58,6 +58,20 @@ jobs: type=sha,prefix={{branch}}- type=raw,value=latest,enable={{is_default_branch}} + - name: Extract metadata for debug image + id: meta-debug + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch,suffix=-debug + type=ref,event=pr,suffix=-debug + type=semver,pattern={{version}},suffix=-debug + type=semver,pattern={{major}}.{{minor}},suffix=-debug + type=semver,pattern={{major}},suffix=-debug + type=sha,prefix={{branch}}-,suffix=-debug + type=raw,value=debug,enable={{is_default_branch}} + - name: Build and push Docker image uses: docker/build-push-action@v5 with: @@ -70,5 +84,19 @@ jobs: cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max platforms: linux/amd64 + - name: Build and push debug Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile.debug + push: true + tags: ${{ steps.meta-debug.outputs.tags }} + labels: ${{ steps.meta-debug.outputs.labels }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-debug + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-debug,mode=max + platforms: linux/amd64 + - name: Image digest - run: echo ${{ steps.meta.outputs.digest }} + run: | + echo "Production: ${{ steps.meta.outputs.digest }}" + echo "Debug: ${{ steps.meta-debug.outputs.digest }}" diff --git a/Dockerfile.debug b/Dockerfile.debug new file mode 100644 index 0000000..71d3fe5 --- /dev/null +++ b/Dockerfile.debug @@ -0,0 +1,67 @@ +# Debug build with shell and tools +FROM golang:1.26-alpine AS builder + +WORKDIR /build + +# Install build dependencies +RUN apk add --no-cache git + +# Copy go mod files +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build the application (static binary, no CGO, migrations embedded) +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ + -a \ + -installsuffix cgo \ + -ldflags="-w -s -extldflags '-static'" \ + -o aitrade \ + ./cmd/aitrade + +# Build healthcheck utility +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ + -ldflags="-w -s -extldflags '-static'" \ + -o healthcheck \ + ./cmd/healthcheck + +# Debug runtime stage - Alpine with shell and debugging tools +FROM alpine:latest + +# Install debugging tools +RUN apk add --no-cache \ + bash \ + curl \ + wget \ + netcat-openbsd \ + bind-tools \ + busybox-extras \ + ca-certificates \ + sqlite \ + tzdata + +# Set working directory +WORKDIR /app + +# Copy binary from builder (migrations are embedded in binary) +COPY --from=builder /build/aitrade /app/aitrade +COPY --from=builder /build/healthcheck /app/healthcheck + +# Create non-root user +RUN addgroup -g 1000 appuser && \ + adduser -D -u 1000 -G appuser appuser && \ + chown -R appuser:appuser /app + +USER appuser + +# Expose web port +EXPOSE 8080 + +# Health check using custom binary +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD ["/app/healthcheck", "localhost", "8080"] + +# Run application +ENTRYPOINT ["/app/aitrade"]