refactor: Revise Dockerfile - Remove entrypoint.sh (#598)
* chore: Formatting * chore: Formatting (fix indent) * refactor: Remove entrypoint * chore: Remove `entrypoint.sh` from `.goreleaser.yaml` * tests: Replace `entrypoint.sh` script usage in `e2eentry.sh` * Set default plugin argument from environment variable in main function and update Dockerfile to remove CMD instruction * Add user and group setup for testing in Dockerfile and update e2e entry script * Update cmd/sshpiperd/main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update cmd/sshpiperd/main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove test user and group creation from Dockerfile and move it to e2e entry script; update plugin argument handling in main function * Update Dockerfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Skip empty plugin directory entries in main function --------- Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
2edfa6b4c3
commit
ca311e15cd
6 changed files with 51 additions and 27 deletions
|
|
@ -154,8 +154,6 @@ dockers:
|
|||
build_flag_templates:
|
||||
- "--platform=linux/amd64"
|
||||
- "--build-arg=EXTERNAL=1"
|
||||
extra_files:
|
||||
- entrypoint.sh
|
||||
skip_push: "{{ .Env.SKIP_PUSH }}"
|
||||
- image_templates:
|
||||
- "farmer1992/sshpiperd:v{{ .Version }}-arm64"
|
||||
|
|
@ -170,8 +168,6 @@ dockers:
|
|||
build_flag_templates:
|
||||
- "--platform=linux/arm64"
|
||||
- "--build-arg=EXTERNAL=1"
|
||||
extra_files:
|
||||
- entrypoint.sh
|
||||
skip_push: "{{ .Env.SKIP_PUSH }}"
|
||||
# full
|
||||
- image_templates:
|
||||
|
|
@ -182,8 +178,6 @@ dockers:
|
|||
build_flag_templates:
|
||||
- "--platform=linux/amd64"
|
||||
- "--build-arg=EXTERNAL=1"
|
||||
extra_files:
|
||||
- entrypoint.sh
|
||||
skip_push: "{{ .Env.SKIP_PUSH }}"
|
||||
- image_templates:
|
||||
- "farmer1992/sshpiperd:full-v{{ .Version }}-arm64"
|
||||
|
|
@ -194,8 +188,6 @@ dockers:
|
|||
build_flag_templates:
|
||||
- "--platform=linux/arm64"
|
||||
- "--build-arg=EXTERNAL=1"
|
||||
extra_files:
|
||||
- entrypoint.sh
|
||||
skip_push: "{{ .Env.SKIP_PUSH }}"
|
||||
docker_manifests:
|
||||
- name_template: "farmer1992/sshpiperd:v{{ .Version }}"
|
||||
|
|
|
|||
18
Dockerfile
18
Dockerfile
|
|
@ -1,12 +1,10 @@
|
|||
FROM docker.io/golang:1.24-bookworm as builder
|
||||
|
||||
FROM docker.io/golang:1.24-bookworm AS builder
|
||||
ARG VER=devel
|
||||
ARG BUILDTAGS
|
||||
ARG EXTERNAL=0
|
||||
|
||||
ENV CGO_ENABLED=0
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
RUN \
|
||||
--mount=target=/src,type=bind,source=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
|
|
@ -22,13 +20,14 @@ RUN \
|
|||
go build -o /sshpiperd/plugins -tags "${BUILDTAGS}" ./plugin/... ./e2e/testplugin/...
|
||||
fi
|
||||
HEREDOC
|
||||
ADD entrypoint.sh /sshpiperd
|
||||
|
||||
FROM builder as testrunner
|
||||
|
||||
FROM builder AS testrunner
|
||||
COPY --from=farmer1992/openssh-static:V_9_8_P1 /usr/bin/ssh /usr/bin/ssh-9.8p1
|
||||
COPY --from=farmer1992/openssh-static:V_8_0_P1 /usr/bin/ssh /usr/bin/ssh-8.0p1
|
||||
|
||||
FROM docker.io/busybox
|
||||
|
||||
FROM docker.io/busybox AS sshpiperd
|
||||
ARG USERID=1000
|
||||
ARG GROUPID=1000
|
||||
RUN <<HEREDOC
|
||||
|
|
@ -43,7 +42,8 @@ HEREDOC
|
|||
COPY --from=builder --chown=${USERID} /sshpiperd/ /sshpiperd
|
||||
|
||||
# Runtime setup:
|
||||
ENV SSHPIPERD_SERVER_KEY_GENERATE_MODE=notexist PLUGIN=workingdir
|
||||
ENTRYPOINT ["/sshpiperd/sshpiperd"]
|
||||
|
||||
USER ${USERID}:${GROUPID}
|
||||
EXPOSE 2222
|
||||
|
||||
ENTRYPOINT ["/sshpiperd/entrypoint.sh"]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"time"
|
||||
|
|
@ -264,6 +265,46 @@ func main() {
|
|||
var plugins []*plugin.GrpcPlugin
|
||||
|
||||
args := ctx.Args().Slice()
|
||||
|
||||
// If no command-line arguments are provided, fall back to the PLUGIN environment variable.
|
||||
if len(args) == 0 {
|
||||
pluginEnv := os.Getenv("PLUGIN")
|
||||
if pluginEnv != "" {
|
||||
|
||||
exePath, err := os.Executable()
|
||||
exeDir := ""
|
||||
if err == nil {
|
||||
exeDir = fmt.Sprintf("%s/", filepath.Dir(exePath))
|
||||
}
|
||||
|
||||
pluginDirs := []string{
|
||||
filepath.Join(exeDir, "plugins"),
|
||||
os.Getenv("SSHPIPERD_PLUGIN_PATH"),
|
||||
}
|
||||
|
||||
found := false
|
||||
|
||||
for _, dir := range pluginDirs {
|
||||
if dir == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
pluginexe := filepath.Join(dir, pluginEnv)
|
||||
if _, err := os.Stat(pluginexe); err == nil {
|
||||
args = append(args, pluginexe)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
if path, err := exec.LookPath(pluginEnv); err == nil {
|
||||
args = append(args, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
remain := args
|
||||
|
||||
for len(remain) > 0 {
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ services:
|
|||
- SSHPIPERD_E2E_TEST=1
|
||||
- SSHPIPERD_DEBUG=${SSHPIPERD_DEBUG}
|
||||
- SSHPIPERD_ALLOWED_PROXY_ADDRESSES=0.0.0.0/0
|
||||
- SSHPIPERD_SERVER_KEY_GENERATE_MODE=notexist
|
||||
- DOCKER_API_VERSION=1.40
|
||||
build:
|
||||
context: ../
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
# use entrypoint.sh to generate the ssh_host_ed25519_key
|
||||
PLUGIN="dummy_badname/" bash /sshpiperd/entrypoint.sh 2>/dev/null
|
||||
|
||||
groupadd -f testgroup && \
|
||||
useradd -m -G testgroup testgroupuser
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -eo pipefail
|
||||
|
||||
PLUGIN=${PLUGIN:-workingdir}
|
||||
export SSHPIPERD_SERVER_KEY_GENERATE_MODE=${SSHPIPERD_SERVER_KEY_GENERATE_MODE:-notexist}
|
||||
|
||||
exec /sshpiperd/sshpiperd "${@:-/sshpiperd/plugins/$PLUGIN}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue