Skip to content

Commit

Permalink
feat(dl): support download file with file_regex param (#169)
Browse files Browse the repository at this point in the history
example:

curl -v
"http://localhost:8000/oci-file/hub.pingcap.net/pingcap/tidb/package?tag=v8.3.0_linux_amd64&
file_regex=tidb-lightning-.%2A%5B.%5Dsha256"

to download the file with regex pattern `tidb-lightning-.*[.]sha256`.

Signed-off-by: wuhuizuo <wuhuizuo@126.com>

Signed-off-by: wuhuizuo <wuhuizuo@126.com>
  • Loading branch information
wuhuizuo authored Sep 18, 2024
1 parent eadd400 commit 09f428e
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 116 deletions.
2 changes: 1 addition & 1 deletion dl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.4 AS builder
FROM golang:1.23.1 AS builder

COPY . /app
RUN --mount=type=cache,target=/go/pkg/mod cd /app && go build -o server ./cmd/server
Expand Down
24 changes: 18 additions & 6 deletions dl/design/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,21 @@ var _ = Service("oci", func() {

Method("download-file", func() {
Payload(func() {
Field(1, "repository", String, "OCI artifact repository")
Field(2, "tag", String, "OCI artifact tag")
Field(3, "file", String, "file name in OCI artifact")
Required("repository", "tag", "file")
Field(1, "repository", String, "OCI artifact repository", func() {
Example("hub.pingcap.net/pingcap/tidb/package")
})
Field(2, "tag", String, "OCI artifact tag", func() {
Example("v8.1.0_darwin_arm64")
})
Field(3, "file", String, "file name in OCI artifact", func() {
Example("tidb-v7.5.0-darwin-arm64.tar.gz")
})
Field(4, "file_regex", String, "file name regexp pattern", func() {
Format(FormatRegexp)
Example("tidb-.+[.]tar[.]gz")
})

Required("repository", "tag")
})

// The use of Result here illustrates how HTTP headers can still be
Expand All @@ -79,8 +90,9 @@ var _ = Service("oci", func() {

HTTP(func() {
GET("/oci-file/{*repository}")
Param("file:file", String, "file name in OCI artifact")
Param("tag:tag", String, "OCI artifact tag")
Param("tag", String, "OCI artifact tag")
Param("file", String, "file name in OCI artifact")
Param("file_regex", String, "file name regex pattern in OCI artifact")

// Bypass response body encoder code generation to alleviate need for
// loading the entire response body in memory.
Expand Down
22 changes: 12 additions & 10 deletions dl/gen/http/cli/server/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 21 additions & 6 deletions dl/gen/http/oci/client/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion dl/gen/http/oci/client/encode_decode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions dl/gen/http/oci/server/encode_decode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions dl/gen/http/oci/server/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dl/gen/http/openapi.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"swagger":"2.0","info":{"title":"Download OCI artifacts Service","description":"Service for downloading files from OCI artifact","version":"0.0.1"},"host":"localhost:8000","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/healthz":{"get":{"tags":["health"],"summary":"healthz health","operationId":"health#healthz","responses":{"200":{"description":"OK response.","schema":{"type":"boolean"}}},"schemes":["http"]}},"/livez":{"get":{"tags":["health"],"summary":"livez health","operationId":"health#livez","responses":{"200":{"description":"OK response.","schema":{"type":"boolean"}}},"schemes":["http"]}},"/oci-file-sha256/{repository}":{"get":{"tags":["oci"],"summary":"download-file-sha256 oci","operationId":"oci#download-file-sha256","produces":["application/plain-text"],"parameters":[{"name":"file","in":"query","description":"file name in OCI artifact","required":true,"type":"string"},{"name":"tag","in":"query","description":"OCI artifact tag","required":true,"type":"string"},{"name":"repository","in":"path","description":"OCI artifact repository","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","headers":{"Content-Disposition":{"description":"Content-Disposition header for downloading","type":"string"},"Content-Length":{"description":"Length is the downloaded content length in bytes.","type":"int64"}}}},"schemes":["http"]}},"/oci-file/{repository}":{"get":{"tags":["oci"],"summary":"download-file oci","operationId":"oci#download-file","produces":["application/octet-stream"],"parameters":[{"name":"file","in":"query","description":"file name in OCI artifact","required":true,"type":"string"},{"name":"tag","in":"query","description":"OCI artifact tag","required":true,"type":"string"},{"name":"repository","in":"path","description":"OCI artifact repository","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","headers":{"Content-Disposition":{"description":"Content-Disposition header for downloading","type":"string"},"Content-Length":{"description":"Length is the downloaded content length in bytes.","type":"int64"}}}},"schemes":["http"]}},"/oci-files/{repository}":{"get":{"tags":["oci"],"summary":"list-files oci","operationId":"oci#list-files","parameters":[{"name":"tag","in":"query","description":"OCI artifact tag","required":true,"type":"string"},{"name":"repository","in":"path","description":"OCI artifact repository","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"array","items":{"type":"string","example":"Nam quibusdam recusandae dolor voluptas."}}}},"schemes":["http"]}},"/s3-obj/{bucket}/{key}":{"get":{"tags":["ks3"],"summary":"download-object ks3","operationId":"ks3#download-object","produces":["application/octet-stream"],"parameters":[{"name":"bucket","in":"path","description":"bucket name","required":true,"type":"string"},{"name":"key","in":"path","description":"object key","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","headers":{"Content-Disposition":{"description":"Content-Disposition header for downloading","type":"string"},"Content-Length":{"description":"Length is the downloaded content length in bytes.","type":"int64"}}}},"schemes":["http"]}}}}
{"swagger":"2.0","info":{"title":"Download OCI artifacts Service","description":"Service for downloading files from OCI artifact","version":"0.0.1"},"host":"localhost:8000","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/healthz":{"get":{"tags":["health"],"summary":"healthz health","operationId":"health#healthz","responses":{"200":{"description":"OK response.","schema":{"type":"boolean"}}},"schemes":["http"]}},"/livez":{"get":{"tags":["health"],"summary":"livez health","operationId":"health#livez","responses":{"200":{"description":"OK response.","schema":{"type":"boolean"}}},"schemes":["http"]}},"/oci-file-sha256/{repository}":{"get":{"tags":["oci"],"summary":"download-file-sha256 oci","operationId":"oci#download-file-sha256","produces":["application/plain-text"],"parameters":[{"name":"file","in":"query","description":"file name in OCI artifact","required":true,"type":"string"},{"name":"tag","in":"query","description":"OCI artifact tag","required":true,"type":"string"},{"name":"repository","in":"path","description":"OCI artifact repository","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","headers":{"Content-Disposition":{"description":"Content-Disposition header for downloading","type":"string"},"Content-Length":{"description":"Length is the downloaded content length in bytes.","type":"int64"}}}},"schemes":["http"]}},"/oci-file/{repository}":{"get":{"tags":["oci"],"summary":"download-file oci","operationId":"oci#download-file","produces":["application/octet-stream"],"parameters":[{"name":"tag","in":"query","description":"OCI artifact tag","required":true,"type":"string"},{"name":"file","in":"query","description":"file name in OCI artifact","required":false,"type":"string"},{"name":"file_regex","in":"query","description":"file name regex pattern in OCI artifact","required":false,"type":"string","format":"regexp"},{"name":"repository","in":"path","description":"OCI artifact repository","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","headers":{"Content-Disposition":{"description":"Content-Disposition header for downloading","type":"string"},"Content-Length":{"description":"Length is the downloaded content length in bytes.","type":"int64"}}}},"schemes":["http"]}},"/oci-files/{repository}":{"get":{"tags":["oci"],"summary":"list-files oci","operationId":"oci#list-files","parameters":[{"name":"tag","in":"query","description":"OCI artifact tag","required":true,"type":"string"},{"name":"repository","in":"path","description":"OCI artifact repository","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"array","items":{"type":"string","example":"Et aut labore veniam et maiores qui."}}}},"schemes":["http"]}},"/s3-obj/{bucket}/{key}":{"get":{"tags":["ks3"],"summary":"download-object ks3","operationId":"ks3#download-object","produces":["application/octet-stream"],"parameters":[{"name":"bucket","in":"path","description":"bucket name","required":true,"type":"string"},{"name":"key","in":"path","description":"object key","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","headers":{"Content-Disposition":{"description":"Content-Disposition header for downloading","type":"string"},"Content-Length":{"description":"Length is the downloaded content length in bytes.","type":"int64"}}}},"schemes":["http"]}}}}
16 changes: 11 additions & 5 deletions dl/gen/http/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,22 @@ paths:
produces:
- application/octet-stream
parameters:
- name: tag
in: query
description: OCI artifact tag
required: true
type: string
- name: file
in: query
description: file name in OCI artifact
required: true
required: false
type: string
- name: tag
- name: file_regex
in: query
description: OCI artifact tag
required: true
description: file name regex pattern in OCI artifact
required: false
type: string
format: regexp
- name: repository
in: path
description: OCI artifact repository
Expand Down Expand Up @@ -135,7 +141,7 @@ paths:
type: array
items:
type: string
example: Nam quibusdam recusandae dolor voluptas.
example: Et aut labore veniam et maiores qui.
schemes:
- http
/s3-obj/{bucket}/{key}:
Expand Down
Loading

0 comments on commit 09f428e

Please sign in to comment.