-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Docker configuration and GitHub workflow
Adds: - Dockerfile with multi-stage build and health checks - docker-compose.yml with Prometheus integration - GitHub Container Registry workflow - Example config file - Updated documentation
- Loading branch information
1 parent
5f23f1d
commit 1eb7fa3
Showing
7 changed files
with
211 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Docker Build and Publish | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to GitHub Container Registry | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=sha,prefix= | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,8 @@ go.work.sum | |
|
||
# env file | ||
.env | ||
|
||
# Config files | ||
config.yaml | ||
|
||
hapax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Build stage | ||
FROM golang:1.22-alpine AS builder | ||
|
||
# Install build dependencies | ||
RUN apk add --no-cache git gcc musl-dev | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy go mod and sum files | ||
COPY go.mod go.sum ./ | ||
|
||
# Download dependencies | ||
RUN go mod download | ||
|
||
# Copy source code | ||
COPY . . | ||
|
||
# Build the application | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o hapax ./cmd/hapax | ||
|
||
# Final stage | ||
FROM alpine:3.19 | ||
|
||
# Add non-root user | ||
RUN adduser -D -g '' hapax | ||
|
||
# Install runtime dependencies | ||
RUN apk add --no-cache ca-certificates tzdata curl | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy binary from builder | ||
COPY --from=builder /app/hapax . | ||
|
||
# Copy default config file | ||
COPY config.yaml ./config.yaml | ||
|
||
# Use non-root user | ||
USER hapax | ||
|
||
# Expose ports | ||
EXPOSE 8080 | ||
|
||
# Set healthcheck that waits for initial startup | ||
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \ | ||
CMD curl -f http://localhost:8080/health || exit 1 | ||
|
||
# Run the application | ||
ENTRYPOINT ["./hapax"] | ||
CMD ["--config", "config.yaml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
server: | ||
port: 8080 | ||
read_timeout: 30s | ||
write_timeout: 30s | ||
|
||
llm: | ||
provider: "ollama" # Change to your preferred provider (ollama, openai, etc.) | ||
model: "llama2" # Change to your preferred model | ||
endpoint: "" # Set your provider's endpoint if needed | ||
|
||
logging: | ||
level: "info" | ||
format: "json" | ||
|
||
metrics: | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
version: '3.8' | ||
|
||
services: | ||
hapax: | ||
build: . | ||
ports: | ||
- "8080:8080" | ||
volumes: | ||
- ./config.yaml:/app/config.yaml | ||
environment: | ||
- TZ=UTC | ||
restart: unless-stopped | ||
healthcheck: | ||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/health"] | ||
interval: 30s | ||
timeout: 3s | ||
retries: 3 | ||
networks: | ||
- hapax-net | ||
|
||
prometheus: | ||
image: prom/prometheus:latest | ||
ports: | ||
- "9090:9090" | ||
volumes: | ||
- ./prometheus.yml:/etc/prometheus/prometheus.yml | ||
depends_on: | ||
- hapax | ||
networks: | ||
- hapax-net | ||
|
||
networks: | ||
hapax-net: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
global: | ||
scrape_interval: 15s | ||
evaluation_interval: 15s | ||
|
||
scrape_configs: | ||
- job_name: 'hapax' | ||
static_configs: | ||
- targets: ['hapax:8080'] | ||
metrics_path: '/metrics' |