Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-kuendig authored Dec 27, 2023
2 parents 517b495 + 87e9884 commit 8940ee6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
updates:
# Go mods
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"

# Enable version updates for Docker
- package-ecosystem: "docker"
# Look for a `Dockerfile` in the `root` directory
directory: "/"
# Check for updates once a week
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
time: "04:00"
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
pull_request:
push:
branches:
- master

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3

docker:
name: docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build the docker image
run: |
docker build -t testing/serverless-registry-proxy .
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-alpine AS build
FROM golang:1.20.1-alpine AS build
RUN apk add --no-cache git ca-certificates
WORKDIR /src/app
COPY . .
Expand All @@ -9,7 +9,7 @@ RUN apk add --no-cache ca-certificates
COPY --from=build /app /app

# uncomment the following two lines if you're exposing a private GCR registry
# COPY key.json /app/key.json
# ENV GOOGLE_APPLICATION_CREDENTIALS /app/key.json
# COPY key.json /key.json
# ENV GOOGLE_APPLICATION_CREDENTIALS /key.json

ENTRYPOINT [ "/app" ]
3 changes: 3 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"description": "prefix for your images in the target registry (i.e. GCP project ID)",
"required": false
}
},
"options": {
"allow-unauthenticated": true
}
}
15 changes: 6 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ import (
)

const (
defaultGCRHost = "gcr.io"
ctxKeyOriginalHost = myContextKey("original-host")
)

var (
re = regexp.MustCompile(`^/v2/`)
realm = regexp.MustCompile(`realm="(.*?)"`)
ctxKeyOriginalHost = "original-host"
)

type myContextKey string

type registryConfig struct {
host string
repoPrefix string
Expand Down Expand Up @@ -79,6 +80,8 @@ func main() {
return nil
}

host := os.Getenv("HOST")

port := os.Getenv("PORT")
if port == "" {
log.Fatal("PORT environment variable not specified")
Expand Down Expand Up @@ -127,7 +130,7 @@ func main() {
mux.Handle("/v2/", registryAPIProxy(reg, auth))
mux.Handle("/storage/", &StorageProxy{proxy})

addr := ":" + port
addr := fmt.Sprintf("%s:%s", host, port)
handler := captureHostHeader(mux)
log.Printf("starting to listen on %s", addr)
if cert, key := os.Getenv("TLS_CERT"), os.Getenv("TLS_KEY"); cert != "" && key != "" {
Expand Down Expand Up @@ -216,12 +219,6 @@ func registryAPIProxy(cfg registryConfig, auth authenticator) http.HandlerFunc {
}).ServeHTTP
}

// handleRegistryAPIVersion signals docker-registry v2 API on /v2/ endpoint.
func handleRegistryAPIVersion(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Docker-Distribution-API-Version", "registry/2.0")
fmt.Fprint(w, "ok")
}

// rewriteRegistryV2URL rewrites request.URL like /v2/* that come into the server
// into https://[GCR_HOST]/v2/[PROJECT_ID]/*. It leaves /v2/ as is.
func rewriteRegistryV2URL(c registryConfig) func(*http.Request) {
Expand Down

0 comments on commit 8940ee6

Please sign in to comment.