Skip to content

Commit be328d7

Browse files
committed
experiment with Docker
1 parent 5a799c4 commit be328d7

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

.goreleaser.yml

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ before:
88
builds:
99
- goos: [linux, freebsd, windows, darwin]
1010
goarch: [amd64, arm64]
11+
env:
12+
- CGO_ENABLED=0
1113
ignore:
1214
- goos: freebsd
1315
goarch: arm64
@@ -22,6 +24,15 @@ archive:
2224
windows: win
2325
amd64: 64-bit
2426

27+
dockers:
28+
- binary: http-over-ssh
29+
goos: linux
30+
goarch: amd64
31+
image_templates:
32+
- "digineo/http-over-ssh:latest"
33+
- "digineo/http-over-ssh:{{ .Version }}"
34+
skip_push: true
35+
2536
release:
2637
prerelease: auto
2738

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM alpine:latest
2+
3+
RUN apk --no-cache add tzdata ca-certificates \
4+
&& mkdir /data
5+
6+
COPY http-over-ssh /
7+
8+
ENV ZONEINFO /zoneinfo.zip
9+
ENV HOS_USER root
10+
ENV HOS_TIMEOUT 10s
11+
ENV HOS_KEY_DIR /data
12+
ENV HOS_LISTEN :8080
13+
EXPOSE 8080
14+
15+
WORKDIR /data
16+
ENTRYPOINT ["/http-over-ssh"]
17+

main.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,26 @@ var home = func() string {
2222
return os.Getenv("HOME")
2323
}()
2424

25+
var sshKeyDir = or(os.Getenv("HOS_KEY_DIR"), filepath.Join(home, ".ssh"))
26+
2527
var sshKeys = []string{
26-
filepath.Join(home, ".ssh/id_rsa"),
27-
filepath.Join(home, ".ssh/id_ed25519"),
28+
filepath.Join(sshKeyDir, "id_rsa"),
29+
filepath.Join(sshKeyDir, "id_ed25519"),
2830
}
2931

3032
// command line flags
3133
var (
32-
listen = "[::1]:8080"
33-
sshUser = "root"
34-
sshTimeout = 10 * time.Second
34+
listen = or(os.Getenv("HOS_LISTEN"), "[::1]:8080")
35+
sshUser = or(os.Getenv("HOS_USER"), "root")
36+
sshTimeout = func() time.Duration {
37+
dur := os.Getenv("HOS_TIMEOUT")
38+
if dur != "" {
39+
if d, err := time.ParseDuration(dur); err != nil {
40+
return d
41+
}
42+
}
43+
return 10 * time.Second
44+
}()
3545
)
3646

3747
// build flags
@@ -75,3 +85,10 @@ func main() {
7585

7686
log.Fatal(http.Serve(listener, proxy))
7787
}
88+
89+
func or(s, alt string) string {
90+
if s != "" {
91+
return s
92+
}
93+
return alt
94+
}

0 commit comments

Comments
 (0)