Skip to content

Build gsbox release #14

Build gsbox release

Build gsbox release #14

name: Build gsbox release
on:
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/gsbox-release
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout external gsbox repository
uses: actions/checkout@v4
with:
repository: gotoeasy/gsbox
- name: Create Dockerfile
run: |
cat > Dockerfile << 'EOF'
# Build stage
FROM golang:bookworm AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
# Copy go mod files first for better caching
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application with optimizations for release
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o gsbox .
# Final stage - minimal image
FROM debian:bookworm-slim
WORKDIR /app
# Install ca-certificates for HTTPS requests (if needed)
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
# Copy the binary from builder
COPY --from=builder /app/gsbox /usr/local/bin/gsbox
# Set the entrypoint
ENTRYPOINT ["gsbox"]
EOF
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=sha,prefix=
type=raw,value={{date 'YYYYMMDD'}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max