Skip to content

Commit

Permalink
feat: coldstarter (#37)
Browse files Browse the repository at this point in the history
* feat: coldstarter

* fix: Dockerfile.testing

* fix: ci

* fix: ci

* chore: tmate

* fix: CGO

* chore: coldstarter tests

* chore: wait ports test

* chore: install nc

* chore: watch ports

* chore: more debugging

* chore: minor log improvments

* chore: sleep

* chore: temp disable long test

* chore: more logging

* chore: test

* fix: tests context cancel to early

* chore: static build

* chore: replace stupid pcap with unpopular pcap

* chore: entrypoint
  • Loading branch information
MarcStdt authored Aug 31, 2024
1 parent 0fe8edd commit d3497c3
Show file tree
Hide file tree
Showing 41 changed files with 2,469 additions and 120 deletions.
4 changes: 4 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ if [ -z "$input" ] || [[ $input =~ ([^/]+)/([^:]+):([^/]+) ]]; then
then
args+=("--idle")
fi
if [ ! -z "${DRUID_WATCH_PORTS}" ];
then
args+=("--watch-ports")
fi

echo "Running druid with args from env: ${args[@]}"
exec druid "${args[@]}"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install libpcap-dev
run: sudo apt update && sudo apt install -y libpcap-dev
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install libpcap-dev
run: sudo apt update && sudo apt install -y libpcap-dev
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -19,6 +21,8 @@ jobs:
id: version
with:
version_format: "${major}.${minor}.${patch}-${{ env.BRANCH_NAME }}${increment}"
#- name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- run: make test-integration-docker
name: Run integration tests inside Docker
- run: make test
Expand Down
31 changes: 30 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
"serve",
"--cwd",
"${workspaceFolder}/examples/minecraft",
"--watch-ports",
"-p",
"9190"
],
},
{
"name": "Debug Daemon serve --coldstarter (minecraft example)",
"type": "go",
"request": "launch",
"mode": "debug",
"console": "integratedTerminal",
"program": "${workspaceFolder}/main.go",
"args": [
"serve",
"--cwd",
"${workspaceFolder}/examples/minecraft",
"--coldstarter",
"--watch-ports",
"-p",
"9190"
],
Expand Down Expand Up @@ -121,7 +139,7 @@
"registry",
"pull",
"--cwd",
"${workspaceFolder}/examples/scroll-cwd-pull/", "registry-1.docker.io/highcard/scroll-minecraft-forge:1.20.1",
"${workspaceFolder}/examples/scroll-cwd-pull/", "artifacts.druid.gg/druid-team/scroll-minecraft-forge:1.20.1",
],
},
{
Expand All @@ -139,6 +157,17 @@
"${workspaceFolder}/examples/",
],
},
{
"name": "Debug Daemon port",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/main.go",
"args": [
"port",
"3000", "9090"
],
},
{
"name": "Remote Debug Daemon serve",
"type": "go",
Expand Down
8 changes: 1 addition & 7 deletions Dockerfile.testing
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
FROM nginx
WORKDIR /app

RUN apt update
RUN apt install -y ca-certificates wget jq moreutils htop procps nano net-tools gcc make
RUN apt update && apt install -y ca-certificates wget jq moreutils htop procps nano net-tools gcc make libpcap-dev openjdk-17-jdk ant netcat-traditional


RUN wget https://go.dev/dl/go1.21.6.linux-$(dpkg --print-architecture).tar.gz -O go.tar.gz
RUN tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz

RUN apt-get update && \
apt-get install -y openjdk-17-jdk && \
apt-get install -y ant && \
apt-get clean;

#/root/go/bin is not in the path
ENV PATH=$PATH:/root/go/bin
ENV PATH=$PATH:/usr/local/go/bin
Expand Down
46 changes: 46 additions & 0 deletions cmd/port_monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"fmt"
"strconv"
"time"

"github.com/highcard-dev/daemon/internal/core/services"
"github.com/spf13/cobra"
)

var PortMonitorCmd = &cobra.Command{
Use: "port",
Short: "Monitor ports",
Args: cobra.MinimumNArgs(1),
Long: "Utility to monitor ports and show their status and activity",
RunE: func(cmd *cobra.Command, args []string) error {

ports := make([]int, len(args))

for idx, port := range args {
i, err := strconv.Atoi(port)
if err != nil {
return err
}
ports[idx] = i
}

portMonitor := services.NewPortService(ports)

go portMonitor.StartMonitoring(cmd.Context(), watchPortsInterfaces)

for {
ps := portMonitor.GetPorts()
for _, p := range ps {
fmt.Printf("Port %s: %d, last activity %v, open: %t \n", p.Port.Name, p.Port.Port, p.InactiveSince, p.Open)
}
time.Sleep(5 * time.Second)
}

},
}

func init() {
PortMonitorCmd.Flags().StringArrayVarP(&watchPortsInterfaces, "watch-ports-interfaces", "", []string{"lo0"}, "Interfaces to watch for port activity")
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
RootCmd.AddCommand(SemverCmd)
RootCmd.AddCommand(VersionCmd)
RootCmd.AddCommand(ScrollCmd)
RootCmd.AddCommand(PortMonitorCmd)

c, _ := os.Getwd()

Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var RunCmd = &cobra.Command{
logger.Log().Info("Lock file created")
}

_, _, err = scrollService.Bootstrap(ignoreVersionCheck)
_, err = scrollService.Bootstrap(ignoreVersionCheck)

if err != nil {
return fmt.Errorf("error loading scroll: %w", err)
Expand Down
Loading

0 comments on commit d3497c3

Please sign in to comment.