mirror of
https://gitea.intern.drachenfels.de/ruben/goget.git
synced 2026-02-08 12:48:01 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1049b41cb7 | |||
| 5fdf7a31c8 | |||
| 12c3b5f784 | |||
| 65d6fbe457 | |||
| 0902b8ba3a | |||
| c1d5863162 | |||
| 3891e874ca |
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
FROM docker.io/library/golang:1.17-alpine3.14 as build
|
||||||
|
RUN apk --no-cache add make build-base git
|
||||||
|
ARG GONOSUMDB
|
||||||
|
ARG GOPROXY
|
||||||
|
ARG GOBIN=/opt/bin
|
||||||
|
ARG RELEASE="${RELEASE:-undefined}"
|
||||||
|
WORKDIR /build
|
||||||
|
ADD . .
|
||||||
|
RUN STATIC=true make install
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=build /opt/bin/goget /
|
||||||
25
Makefile
25
Makefile
@ -1,12 +1,17 @@
|
|||||||
BUILD_HASH := $(shell git describe --always --tags --long)
|
COMMIT = $(shell git describe --always --tags --long --dirty)
|
||||||
LDFLAGS := "-X main.version=${BUILD_HASH} -s -w"
|
|
||||||
|
RELEASE ?= $(COMMIT)
|
||||||
|
LDFLAGS := -X main.version=$(RELEASE)
|
||||||
|
|
||||||
|
ifdef STATIC
|
||||||
|
LDFLAGS += -w -s -extldflags=-static
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: fmt install
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
go fmt ./...
|
||||||
|
|
||||||
.PHONY: install
|
|
||||||
install:
|
install:
|
||||||
go fmt ./...
|
go install -ldflags "${LDFLAGS}" ./...
|
||||||
go install -ldflags ${LDFLAGS} ./...
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
go fmt ./...
|
|
||||||
go build -ldflags ${LDFLAGS} ./...
|
|
||||||
|
|||||||
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# goget
|
||||||
|
|
||||||
|
This project is deprecated.
|
||||||
|
Please use the static curl binary from <https://github.com/moparisthebest/static-curl/releases/> instead.
|
||||||
|
This is the offical download site for static binaries listed on <https://curl.se/download.html>.
|
||||||
|
|
||||||
|
E.g to add the static curl binary in a Dockerfile
|
||||||
|
|
||||||
|
```Dockerfile
|
||||||
|
ADD https://github.com/moparisthebest/static-curl/releases/download/v7.85.0/curl-amd64 /usr/local/bin/curl
|
||||||
|
RUN chmod +x /usr/local/bin/curl
|
||||||
|
```
|
||||||
14
build.sh
Executable file
14
build.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/sh -eu
|
||||||
|
|
||||||
|
image="harbor.intern.drachenfels.de/shieldos/goget"
|
||||||
|
version="$(git describe --always --tags --dirty)"
|
||||||
|
|
||||||
|
buildah bud --layers \
|
||||||
|
--build-arg GOPROXY=$GOPROXY \
|
||||||
|
--build-arg GONOSUMDB=$GONOSUMDB \
|
||||||
|
--build-arg RELEASE=$version \
|
||||||
|
-t $image:latest \
|
||||||
|
-t $image:$version
|
||||||
|
|
||||||
|
buildah push $image:latest
|
||||||
|
buildah push $image:$version
|
||||||
22
goget.go
22
goget.go
@ -23,6 +23,7 @@ type client struct {
|
|||||||
ReadTimeout time.Duration
|
ReadTimeout time.Duration
|
||||||
Retries int
|
Retries int
|
||||||
RetryWait time.Duration
|
RetryWait time.Duration
|
||||||
|
NoProxy bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -31,13 +32,14 @@ func main() {
|
|||||||
var showVersion bool
|
var showVersion bool
|
||||||
|
|
||||||
flag.StringVar(&c.User, "http-user", "", "HTTP auth username")
|
flag.StringVar(&c.User, "http-user", "", "HTTP auth username")
|
||||||
flag.StringVar(&c.Password, "http-password", "", "HTTP auth password")
|
flag.StringVar(&c.Password, "http-passwd", "", "HTTP auth password")
|
||||||
flag.IntVar(&c.Retries, "retries", 1, "Number of retries in case of download errors.")
|
flag.IntVar(&c.Retries, "retries", 1, "Number of retries in case of download errors.")
|
||||||
flag.DurationVar(&c.RetryWait, "retry-wait", 2*time.Second, "Time to wait before retrying download.")
|
flag.DurationVar(&c.RetryWait, "retry-wait", 2*time.Second, "Time to wait before retrying download.")
|
||||||
flag.DurationVar(&c.ConnectTimeout, "connect-timeout", 5*time.Second, "TCP connections that take longer to establish will be aborted")
|
flag.DurationVar(&c.ConnectTimeout, "connect-timeout", 5*time.Second, "TCP connections that take longer to establish will be aborted")
|
||||||
flag.DurationVar(&c.ReadTimeout, "read-timeout", 10*time.Second, "TCP connections that that are longer idle will be aborted")
|
flag.DurationVar(&c.ReadTimeout, "read-timeout", 10*time.Second, "TCP connections that that are longer idle will be aborted")
|
||||||
flag.BoolVar(&c.Insecure, "insecure", false, "Disable TLS certificate verification.")
|
flag.BoolVar(&c.Insecure, "insecure", false, "Disable TLS certificate verification.")
|
||||||
flag.BoolVar(&showVersion, "version", false, "Show version and exit.")
|
flag.BoolVar(&showVersion, "version", false, "Show version and exit.")
|
||||||
|
flag.BoolVar(&c.NoProxy, "no-proxy", false, "Ignore *_proxy environment variables.")
|
||||||
|
|
||||||
flag.StringVar(&filename, "filename", "", "Filename / path where to write downloaded file to. Defaults to filename of the URL.")
|
flag.StringVar(&filename, "filename", "", "Filename / path where to write downloaded file to. Defaults to filename of the URL.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -69,12 +71,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err := os.Remove(filename); err != nil {
|
||||||
|
println(err)
|
||||||
|
}
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) DownloadFile(filename string, url string) (err error) {
|
func (c *client) DownloadFile(filename string, url string) (err error) {
|
||||||
println("Downloading %s to file %s\n", url, filename)
|
fmt.Fprintf(os.Stderr, "downloading %s to file %s\n", url, filename)
|
||||||
// Create the target file
|
// Create the target file
|
||||||
out, err := os.Create(filename)
|
out, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -95,10 +100,21 @@ func (c *client) DownloadFile(filename string, url string) (err error) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.NoProxy {
|
||||||
|
tr.Proxy = nil
|
||||||
|
} else {
|
||||||
|
tr.Proxy = http.ProxyFromEnvironment
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{Transport: tr}
|
client := &http.Client{Transport: tr}
|
||||||
|
|
||||||
// Get the data
|
// Get the data
|
||||||
resp, err := client.Get(url)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.SetBasicAuth(c.User, c.Password)
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user