diff --git a/.gitea/workflows/build-container.yaml b/.gitea/workflows/build-container.yaml new file mode 100644 index 0000000..00909fd --- /dev/null +++ b/.gitea/workflows/build-container.yaml @@ -0,0 +1,31 @@ +name: Build Cat Web App Container + +on: + push: + branches: + - main + +jobs: + build: + runs-on: gitea-runner + steps: + - name: Checkout code + run: | + git clone https://gitea.montgomeryspot.com/myorg/myrepo.git + cd myrepo + + - name: Build container image + run: | + cd myrepo + podman build -f Containerfile -t myorg/catapp:latest . + + # Optional: Push to registry +# - name: Push to registry +# env: +# REGISTRY_USER: ${{ secrets.REGISTRY_USER }} +# REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }} +# run: | +# podman login myregistry.example.com -u $REGISTRY_USER -p $REGISTRY_PASS +# podman tag myorg/catapp:latest myregistry.example.com/myorg/catapp:latest +# podman push myregistry.example.com/myorg/catapp:latest + diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..a7862ea --- /dev/null +++ b/Containerfile @@ -0,0 +1,13 @@ +# Stage 1: Build the Go binary +FROM golang:1.21-alpine AS builder +WORKDIR /app +COPY . . +RUN go build -o catapp . + +# Stage 2: Minimal runtime image +FROM alpine:latest +WORKDIR /app +COPY --from=builder /app/catapp . +EXPOSE 8080 +CMD ["./catapp"] + diff --git a/main.go b/main.go new file mode 100644 index 0000000..433df9f --- /dev/null +++ b/main.go @@ -0,0 +1,67 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" + "html/template" +) + +type CatAPIResponse []struct { + URL string `json:"url"` +} + +var tpl = template.Must(template.New("index").Parse(` + + +
+ +