From 2b1b122ee333fcf3f8a86c86f9094fc0fce90943 Mon Sep 17 00:00:00 2001 From: Stanislas Lange Date: Tue, 6 Jul 2021 22:13:45 +0000 Subject: [PATCH 1/2] refactor: go back to Go BREAKING CHANGE: rip Rust --- .github/workflows/push.yml | 47 +----- README.md | 7 +- Cargo.lock => archive/rust/Cargo.lock | 0 Cargo.toml => archive/rust/Cargo.toml | 0 {src => archive/rust/src}/main.rs | 0 {src => archive/rust/src}/routes/c.rs | 0 {src => archive/rust/src}/routes/cmd.rs | 0 {src => archive/rust/src}/routes/go.rs | 0 {src => archive/rust/src}/routes/health.rs | 0 {src => archive/rust/src}/routes/mod.rs | 0 {src => archive/rust/src}/routes/python.rs | 0 {src => archive/rust/src}/run/c.rs | 0 {src => archive/rust/src}/run/command.rs | 0 {src => archive/rust/src}/run/go.rs | 0 {src => archive/rust/src}/run/mod.rs | 0 {src => archive/rust/src}/run/python.rs | 0 build-rootfs.sh | 2 +- old-golang/build-static.sh => build-static.sh | 0 exec.go | 39 +++++ old-golang/go.mod => go.mod | 4 + old-golang/go.sum => go.sum | 20 +++ handle_c.go | 32 ++++ handle_cpp.go | 32 ++++ handle_golang.go | 49 ++++++ handle_python.go | 11 ++ main.go | 158 ++++++++++++++++++ old-golang/main.go | 154 ----------------- 27 files changed, 357 insertions(+), 198 deletions(-) rename Cargo.lock => archive/rust/Cargo.lock (100%) rename Cargo.toml => archive/rust/Cargo.toml (100%) rename {src => archive/rust/src}/main.rs (100%) rename {src => archive/rust/src}/routes/c.rs (100%) rename {src => archive/rust/src}/routes/cmd.rs (100%) rename {src => archive/rust/src}/routes/go.rs (100%) rename {src => archive/rust/src}/routes/health.rs (100%) rename {src => archive/rust/src}/routes/mod.rs (100%) rename {src => archive/rust/src}/routes/python.rs (100%) rename {src => archive/rust/src}/run/c.rs (100%) rename {src => archive/rust/src}/run/command.rs (100%) rename {src => archive/rust/src}/run/go.rs (100%) rename {src => archive/rust/src}/run/mod.rs (100%) rename {src => archive/rust/src}/run/python.rs (100%) rename old-golang/build-static.sh => build-static.sh (100%) create mode 100644 exec.go rename old-golang/go.mod => go.mod (69%) rename old-golang/go.sum => go.sum (79%) create mode 100644 handle_c.go create mode 100644 handle_cpp.go create mode 100644 handle_golang.go create mode 100644 handle_python.go create mode 100644 main.go delete mode 100644 old-golang/main.go diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a991d03..a172f48 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -8,49 +8,18 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v1 - - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 with: - toolchain: stable - override: true - target: x86_64-unknown-linux-musl - - run: cargo build --release --verbose + go-version: '1.16' + - name: Run build + run: bash build-static.sh - name: upload artifact of build output uses: actions/upload-artifact@v2 with: name: build - path: target/release/agent - - test: - name: test - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v1 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - profile: minimal - - run: cargo test --verbose - - rustfmt: - name: rustfmt - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v1 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - profile: minimal - components: rustfmt - - name: Check formatting - run: cargo fmt -- --check + path: agent commitlint: runs-on: ubuntu-latest @@ -64,7 +33,7 @@ jobs: release: name: Publish new release - needs: [build, test, rustfmt, commitlint] + needs: [build, commitlint] if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index f4632dd..1e85014 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,13 @@ To build the filesystem of the agent VM, see details in https://github.com/codeb ## Build ```sh -cargo build +go build ``` -With musl (for Alpine Linux): +Static (for Alpine Linux): ```sh -rustup target add x86_64-unknown-linux-musl -cargo build --target x86_64-unknown-linux-musl +go build -tags netgo -ldflags '-extldflags "-static"' ``` ## Run diff --git a/Cargo.lock b/archive/rust/Cargo.lock similarity index 100% rename from Cargo.lock rename to archive/rust/Cargo.lock diff --git a/Cargo.toml b/archive/rust/Cargo.toml similarity index 100% rename from Cargo.toml rename to archive/rust/Cargo.toml diff --git a/src/main.rs b/archive/rust/src/main.rs similarity index 100% rename from src/main.rs rename to archive/rust/src/main.rs diff --git a/src/routes/c.rs b/archive/rust/src/routes/c.rs similarity index 100% rename from src/routes/c.rs rename to archive/rust/src/routes/c.rs diff --git a/src/routes/cmd.rs b/archive/rust/src/routes/cmd.rs similarity index 100% rename from src/routes/cmd.rs rename to archive/rust/src/routes/cmd.rs diff --git a/src/routes/go.rs b/archive/rust/src/routes/go.rs similarity index 100% rename from src/routes/go.rs rename to archive/rust/src/routes/go.rs diff --git a/src/routes/health.rs b/archive/rust/src/routes/health.rs similarity index 100% rename from src/routes/health.rs rename to archive/rust/src/routes/health.rs diff --git a/src/routes/mod.rs b/archive/rust/src/routes/mod.rs similarity index 100% rename from src/routes/mod.rs rename to archive/rust/src/routes/mod.rs diff --git a/src/routes/python.rs b/archive/rust/src/routes/python.rs similarity index 100% rename from src/routes/python.rs rename to archive/rust/src/routes/python.rs diff --git a/src/run/c.rs b/archive/rust/src/run/c.rs similarity index 100% rename from src/run/c.rs rename to archive/rust/src/run/c.rs diff --git a/src/run/command.rs b/archive/rust/src/run/command.rs similarity index 100% rename from src/run/command.rs rename to archive/rust/src/run/command.rs diff --git a/src/run/go.rs b/archive/rust/src/run/go.rs similarity index 100% rename from src/run/go.rs rename to archive/rust/src/run/go.rs diff --git a/src/run/mod.rs b/archive/rust/src/run/mod.rs similarity index 100% rename from src/run/mod.rs rename to archive/rust/src/run/mod.rs diff --git a/src/run/python.rs b/archive/rust/src/run/python.rs similarity index 100% rename from src/run/python.rs rename to archive/rust/src/run/python.rs diff --git a/build-rootfs.sh b/build-rootfs.sh index 73181d1..86f72b8 100755 --- a/build-rootfs.sh +++ b/build-rootfs.sh @@ -9,7 +9,7 @@ mount rootfs.ext4 /tmp/my-rootfs docker run -i --rm \ -v /tmp/my-rootfs:/my-rootfs \ - -v "$(pwd)/target/x86_64-unknown-linux-musl/release/agent:/usr/local/bin/agent" \ + -v "$(pwd)/agent:/usr/local/bin/agent" \ -v "$(pwd)/openrc-service.sh:/etc/init.d/agent" \ alpine sh Date: Wed, 7 Jul 2021 00:15:06 +0200 Subject: [PATCH 2/2] chore: update dependabot config for golang --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9525b5e..e9ad69a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,6 +1,6 @@ version: 2 updates: -- package-ecosystem: cargo +- package-ecosystem: gomod directory: "/" schedule: interval: weekly