Skip to content

Commit

Permalink
multi-stage dockerfile; verbose help
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarefev committed Feb 2, 2024
1 parent 8f75926 commit 5d8d6e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
FROM python:3.12-slim-bullseye
# syntax=docker/dockerfile:1

# Build ipip_check binary
FROM golang:1.19 AS go-build

WORKDIR /opt

COPY ./kubemarine/resources/scripts/source/ipip_check ./

RUN go mod download && \
GOOS=linux CGO_ENABLED=1 go build -ldflags="-linkmode external -extldflags='-static'" -o ipip_check -buildvcs=false

FROM python:3.12-slim-bullseye AS python-build

ARG BUILD_TYPE

Expand All @@ -8,17 +20,10 @@ ENV PYTHONUNBUFFERED 1
ENV ANSIBLE_HOST_KEY_CHECKING False

COPY . /opt/kubemarine/
COPY --from=go-build /opt/ipip_check /opt/kubemarine/kubemarine/resources/scripts/
WORKDIR /opt/kubemarine/

RUN apt update && \
# Install Golang and build ipip_check
apt install -y wget gcc && \
wget https://golang.org/dl/go1.19.8.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.19.8.linux-amd64.tar.gz && \
/usr/local/go/bin/go mod download && \
GOOS=linux CGO_ENABLED=1 /usr/local/go/bin/go build -ldflags="-linkmode external -extldflags='-static'" -o kubemarine/resources/scripts/ipip_check -buildvcs=false kubemarine/resources/scripts/source/ipip_check/ipip_check.go && \
rm -Rf /usr/local/go go1.19.8.linux-amd64.tar.gz && \
apt autoremove -y gcc wget && \
pip3 install --no-cache-dir build && \
python3 -m build -n && \
# In any if branch delete source code, but preserve specific directories for different service aims
Expand Down
5 changes: 0 additions & 5 deletions go.mod

This file was deleted.

14 changes: 0 additions & 14 deletions go.sum

This file was deleted.

25 changes: 17 additions & 8 deletions kubemarine/resources/scripts/source/ipip_check/ipip_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"net"
"os"
//"strconv"
"time"
"flag"
"errors"
Expand All @@ -37,22 +36,33 @@ var (
dport, timeout uint
)

func customUsage() {
fmt.Printf("Usage of %s:\n", os.Args[0])
fmt.Printf("%s -mode client -src 192.168.0.1 -ext 192.168.0.2 -int 240.0.0.1 -dport 54545 -msg Message -timeout 10\n",
os.Args[0])
fmt.Printf("%s -mode server -ext 192.168.0.2 -int 240.0.0.1 -dport 54545 -msg Message -timeout 3\n",
os.Args[0])
fmt.Println("Where:")
flag.PrintDefaults()
}

func parseParam() error {
flag.Usage = customUsage
// Server or client mode. Server gets and parses IPIP pakets, and client sends IPIP pakets
flag.StringVar(&mode, "mode", "", "Server or client mode")
// External source IP (Src IP)
flag.StringVar(&src, "src", "", "External source address")
flag.StringVar(&src, "src", "", "External source IP address")
// External destination IP (DstExt IP)
flag.StringVar(&dstExt, "ext", "", "External destination address")
flag.StringVar(&dstExt, "ext", "", "External destination IP address")
// Internal destination IP (DstInt IP)
flag.StringVar(&dstInt, "int", "", "Internal destination address")
flag.StringVar(&dstInt, "int", "", "Internal destination IP address")
// UDP port number (UDP Dst Port)
flag.UintVar(&dport, "dport", 65000, "Destination UDP port")
flag.UintVar(&timeout, "timeout", 0, "Internal destination address")
flag.StringVar(&msg, "msg", "", "Internal destination address")
flag.UintVar(&timeout, "timeout", 0, "Operation timeout")
flag.StringVar(&msg, "msg", "", "Message as UDP payload")
flag.Parse()
if mode != "server" && mode != "client" {
return errors.New("Unknown mode")
return errors.New("Unknown mode. It might be 'server' or 'client'")
}
srcIP = net.ParseIP(src)
if srcIP == nil && mode == "client" {
Expand Down Expand Up @@ -199,5 +209,4 @@ func main() {
case "client":
runClt()
}
//fmt.Printf("SRC:%s; EXT: %s; INT:%s; PORT: %v; TIMEOUT: %v; MSG: %s\n", srcIP, dstExtIP, dstIntIP, dport, timeout, msg)
}

0 comments on commit 5d8d6e2

Please sign in to comment.