-
Notifications
You must be signed in to change notification settings - Fork 58
Modernize godir: Go 1.25, CI/CD, health endpoint #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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" | ||
|
|
||
| - 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 | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -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"] |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,41 @@ | ||
| # godir | ||
|
|
||
| [](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. |
This file contains hidden or 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 |
|---|---|---|
| @@ -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 | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.