Signed-off-by: kaedwen <kaedwen@heinrich.blue>
This commit is contained in:
@@ -58,6 +58,20 @@ jobs:
|
|||||||
type=sha,prefix={{branch}}-
|
type=sha,prefix={{branch}}-
|
||||||
type=raw,value=latest,enable={{is_default_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
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
@@ -70,5 +84,19 @@ jobs:
|
|||||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
|
||||||
platforms: linux/amd64
|
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
|
- name: Image digest
|
||||||
run: echo ${{ steps.meta.outputs.digest }}
|
run: |
|
||||||
|
echo "Production: ${{ steps.meta.outputs.digest }}"
|
||||||
|
echo "Debug: ${{ steps.meta-debug.outputs.digest }}"
|
||||||
|
|||||||
@@ -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"]
|
||||||
Reference in New Issue
Block a user