Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions .github/workflows/godir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: godir

on:
push:
branches:
- main
- master
paths:
- 'godir/**'
- '.github/workflows/godir.yml'
tags:
- 'godir/v*'
pull_request:
paths:
- 'godir/**'
- '.github/workflows/godir.yml'

permissions:
contents: read
packages: write

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/godir

jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: godir
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
cache-dependency-path: godir/go.sum

- name: Verify dependencies
run: go mod verify

- name: Run go vet
run: go vet ./...

- name: Run tests
run: go test -v ./...

build:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/godir/v'))
outputs:
image_tag: ${{ steps.meta.outputs.version }}
steps:
- uses: actions/checkout@v4

- 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
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=match,pattern=godir/v(.*),group=1
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/godir/v') }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: godir
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

container-test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull image
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.image_tag }}

- name: Start container
run: |
docker run -d --name godir-test \
-p 8080:8080 \
-v ${{ github.workspace }}/perl_mongers.xml:/perl_mongers.xml:ro \
-e ROOT=/ \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.image_tag }}
sleep 3

- name: Test health endpoint
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/health)
if [ "$response" != "200" ]; then
echo "Health check failed with status $response"
docker logs godir-test
exit 1
fi
echo "Health check passed"
Comment on lines +115 to +123
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The container test only verifies the health endpoint but doesn't test the actual redirect functionality or error cases. After starting the container, the test should also verify that redirects work correctly using the test entry (zztestloop.pm.org) to ensure the container is functioning properly end-to-end.

Copilot uses AI. Check for mistakes.

- name: Test redirect functionality
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: tokyo.pm.org" http://localhost:8080/)
if [ "$response" != "301" ]; then
echo "Redirect test failed with status $response"
docker logs godir-test
exit 1
fi
echo "Redirect test passed"

- name: Stop container
if: always()
run: docker stop godir-test || true

# Build preview images for PRs when labeled
build-preview:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy-preview')
environment: preview
steps:
- uses: actions/checkout@v4

- 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: Build and push preview
uses: docker/build-push-action@v6
with:
context: godir
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Cleanup PR images when PR is closed
cleanup-preview:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.action == 'closed'
permissions:
packages: write
steps:
- name: Delete PR image
uses: actions/delete-package-versions@v5
with:
package-name: godir
package-type: container
delete-only-untagged-versions: false
min-versions-to-keep: 0
ignore-versions: '^(?!pr-${{ github.event.pull_request.number }}$).*$'
continue-on-error: true
12 changes: 7 additions & 5 deletions godir/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM golang:1.23-alpine AS builder
FROM golang:1.25-alpine AS builder

WORKDIR /go/src/app

COPY go.mod .
#COPY go.sum .
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/godir .

FROM scratch

LABEL org.opencontainers.image.source="https://github.com/perlorg/www.pm.org"
LABEL org.opencontainers.image.description="Perl Mongers redirect service"

COPY --from=builder /tmp/godir /godir
CMD ["/godir"]
ENTRYPOINT ["/godir"]
4 changes: 2 additions & 2 deletions godir/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

PACKAGE=<docker registry>/godir
PACKAGE=ghcr.io/perlorg/godir
VERSION=1.0


# traditional configuration that uses Dockerfile

docker-image: .docker-image

.docker-image: Dockerfile *.go go.mod #go.sum
.docker-image: Dockerfile *.go go.mod go.sum
docker build -t $(PACKAGE):latest .
touch .docker-image

Expand Down
37 changes: 36 additions & 1 deletion godir/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
# godir

[![Build Status](https://github.com/perlorg/www.pm.org/actions/workflows/godir.yml/badge.svg)](https://github.com/perlorg/www.pm.org/actions/workflows/godir.yml)

godir is a server that reads `perl_mongers.xml`, and serves redirects if the
`<web>` element points away from pm.org.

Config lives in the perl k8s repo.
## Container Image

```
ghcr.io/perlorg/godir
```

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `PORT` | `8080` | HTTP port to listen on |
| `ROOT` | `.` | Directory containing `perl_mongers.xml` |
| `LOG_LEVEL` | `INFO` | Logging verbosity: DEBUG, INFO, WARN, ERROR |

## Endpoints

| Path | Description |
|------|-------------|
| `/` | Redirect handler - extracts subdomain and redirects to group's web URL |
| `/health` | Health check - returns `200 OK` with body "ok" |

## Running

```bash
# Local development
ROOT=.. go run .

# Docker
docker run -p 8080:8080 -v /path/to/perl_mongers.xml:/perl_mongers.xml -e ROOT=/ ghcr.io/perlorg/godir
```

## Config

Kubernetes config lives in the perl k8s repo.
37 changes: 33 additions & 4 deletions godir/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
module pm.org/godir

go 1.22.5
go 1.25

require (
github.com/kouhin/envflag v0.0.0-20150818174321-0e9a86061649
github.com/samber/slog-http v1.4.2
go.ntppool.org/common v0.7.1
)

require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
github.com/remychantenay/slog-otel v1.3.2 // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/samber/slog-multi v1.2.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/bridges/otelslog v0.8.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 // indirect
go.opentelemetry.io/otel/log v0.9.0 // indirect
go.opentelemetry.io/otel/metric v1.33.0 // indirect
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.9.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.33.0 // indirect
go.opentelemetry.io/otel/trace v1.33.0 // indirect
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/text v0.29.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241223144023-3abc09e42ca8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect
google.golang.org/grpc v1.69.2 // indirect
google.golang.org/protobuf v1.36.1 // indirect
)
Loading