Skip to content

Commit

Permalink
refactor: Use new README conventions, modernize build system with `hy…
Browse files Browse the repository at this point in the history
…drun` configuration and CI/CD conventions

Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
  • Loading branch information
pojntfx committed Jul 12, 2024
1 parent b9d19c2 commit 67583de
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 12,335 deletions.
58 changes: 34 additions & 24 deletions .github/workflows/hydrun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@ on:
schedule:
- cron: "0 0 * * 0"

permissions:
contents: write

jobs:
build-linux:
runs-on: ubuntu-latest
runs-on: ${{ matrix.target.runner }}
permissions:
contents: read
strategy:
matrix:
target:
# Tests
- id: test
src: .
os: golang:bullseye
flags: ""
cmd: go test ./...
dst: out/*
os: golang:bookworm
flags: -e '-v /tmp/ccache:/root/.cache/go-build'
cmd: GOFLAGS="-short" ./Hydrunfile test
dst: out/nonexistent
runner: ubuntu-latest

# We don't vendor the binaries

steps:
- name: Maximize build space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Restore ccache
uses: actions/cache/restore@v4
with:
path: |
/tmp/ccache
key: cache-ccache-${{ matrix.target.id }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Set up hydrun
run: |
curl -L -o /tmp/hydrun "https://github.com/pojntfx/hydrun/releases/latest/download/hydrun.linux-$(uname -m)"
Expand All @@ -43,40 +47,46 @@ jobs:
run: hydrun -o ${{ matrix.target.os }} ${{ matrix.target.flags }} "${{ matrix.target.cmd }}"
- name: Fix permissions for output
run: sudo chown -R $USER .
- name: Save ccache
uses: actions/cache/save@v4
with:
path: |
/tmp/ccache
key: cache-ccache-${{ matrix.target.id }}
- name: Upload output
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target.id }}
path: ${{ matrix.target.dst }}

publish-linux:
runs-on: ubuntu-latest
permissions:
contents: write
needs: build-linux

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Download output
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
path: /tmp/out
- name: Extract branch name
id: extract_branch
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
- name: Publish pre-release to GitHub releases
if: ${{ github.ref == 'refs/heads/main' }}
uses: marvinpinto/action-automatic-releases@latest
uses: softprops/action-gh-release@v2
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: release-${{ steps.extract_branch.outputs.branch }}
tag_name: release-${{ steps.extract_branch.outputs.branch }}
prerelease: true
files: |
/tmp/out/*/*
- name: Publish release to GitHub releases
if: startsWith(github.ref, 'refs/tags/v')
uses: marvinpinto/action-automatic-releases@latest
uses: softprops/action-gh-release@v2
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
/tmp/out/*/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out
17 changes: 17 additions & 0 deletions Hydrunfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

# Test
if [ "$1" = "test" ]; then
# Configure Git
git config --global --add safe.directory '*'

# Generate dependencies
make depend

# Run tests
make test

exit 0
fi
48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Public variables
DESTDIR ?=
PREFIX ?= /usr/local
OUTPUT_DIR ?= out
DST ?=

# Private variables
obj = go-nbd-example-client go-nbd-example-server-file go-nbd-example-server-memory
all: $(addprefix build/,$(obj))

# Build
build: $(addprefix build/,$(obj))
$(addprefix build/,$(obj)):
ifdef DST
go build -o $(DST) ./cmd/$(subst build/,,$@)
else
go build -o $(OUTPUT_DIR)/$(subst build/,,$@) ./cmd/$(subst build/,,$@)
endif

# Install
install: $(addprefix install/,$(obj))
$(addprefix install/,$(obj)):
install -D -m 0755 $(OUTPUT_DIR)/$(subst install/,,$@) $(DESTDIR)$(PREFIX)/bin/$(subst install/,,$@)

# Uninstall
uninstall: $(addprefix uninstall/,$(obj))
$(addprefix uninstall/,$(obj)):
rm $(DESTDIR)$(PREFIX)/bin/$(subst uninstall/,,$@)

# Run
$(addprefix run/,$(obj)):
$(subst run/,,$@) $(ARGS)

# Test
test:
go test -timeout 3600s -parallel $(shell nproc) ./...

# Benchmark
benchmark:
go test -timeout 3600s -bench=./... ./...

# Clean
clean:
rm -rf out

# Dependencies
depend:
true
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# go-nbd
<img alt="Project icon" style="vertical-align: middle;" src="./docs/icon.svg" width="128" height="128" align="left">

![Logo](./docs/logo-readme.png)
# go-nbd

Pure Go NBD server and client library.

<br/>

[![hydrun CI](https://github.com/pojntfx/go-nbd/actions/workflows/hydrun.yaml/badge.svg)](https://github.com/pojntfx/go-nbd/actions/workflows/hydrun.yaml)
![Go Version](https://img.shields.io/badge/go%20version-%3E=1.20-61CFDD.svg)
[![Go Reference](https://pkg.go.dev/badge/github.com/pojntfx/go-nbd.svg)](https://pkg.go.dev/github.com/pojntfx/go-nbd)
Expand All @@ -13,7 +15,7 @@ Pure Go NBD server and client library.

go-nbd is a lean NBD server and client library supporting the baseline protocol.

It enables you to ...
It enables you to:

- **Build NBD servers and clients in Go:** Develop Network Block Device servers and clients using the efficient and easy-to-understand Go programming language, without having to fallback to CGo.
- **Expose any `io.ReadWriter` as a block device:** Effortlessly turn a file, byte slice, S3 bucket or other `io.ReadWriter` into a fully-fledged block device.
Expand All @@ -27,7 +29,7 @@ You can add go-nbd to your Go project by running the following:
$ go get github.com/pojntfx/go-nbd/...@latest
```

## Usage
## Tutorial

> TL;DR: Define a backend, expose it with a server, connect a block device with the client and setup/mount the filesystem.
Expand Down Expand Up @@ -186,8 +188,8 @@ To build and start a development version of one of the examples locally, run the
```shell
$ git clone https://github.com/pojntfx/go-nbd.git
$ cd go-nbd
$ rm -f disk.img && truncate -s 10G disk.img && go run ./cmd/go-nbd-example-server-file .
$ go run ./cmd/go-nbd-example-server-memory .
$ mkdir -p out && rm -f out/disk.img && truncate -s 10G out/disk.img && go run ./cmd/go-nbd-example-server-file --file out/disk.img
$ go run ./cmd/go-nbd-example-server-memory

# With the C NBD client
$ sudo umount ~/Downloads/mnt; sudo nbd-client -d /dev/nbd1 && echo 'NBD starting' | sudo tee /dev/kmsg && sudo nbd-client -N default localhost 10809 /dev/nbd1
Expand All @@ -203,6 +205,6 @@ Have any questions or need help? Chat with us [on Matrix](https://matrix.to/#/#g

## License

go-nbd (c) 2023 Felicitas Pojtinger and contributors
go-nbd (c) 2024 Felicitas Pojtinger and contributors

SPDX-License-Identifier: Apache-2.0
Binary file removed docs/icon-dark.png
Binary file not shown.
Loading

0 comments on commit 67583de

Please sign in to comment.