Skip to content

Commit 0bc335c

Browse files
committed
feat: add GitHub Actions workflow for building and releasing binaries
1 parent 38893a8 commit 0bc335c

File tree

3 files changed

+138
-14
lines changed

3 files changed

+138
-14
lines changed

.github/workflows/release.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build and Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
include:
13+
- goos: linux
14+
goarch: amd64
15+
output_name: hoster
16+
17+
- goos: linux
18+
goarch: arm64
19+
output_name: hoster
20+
21+
- goos: darwin
22+
goarch: amd64
23+
output_name: hoster
24+
25+
- goos: darwin
26+
goarch: arm64
27+
output_name: hoster
28+
29+
- goos: windows
30+
goarch: amd64
31+
output_name: hoster.exe
32+
33+
- goos: windows
34+
goarch: arm64
35+
output_name: hoster.exe
36+
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- name: Set up Go
41+
uses: actions/setup-go@v5
42+
with:
43+
go-version: '1.24'
44+
45+
- name: Build binary
46+
env:
47+
GOOS: ${{ matrix.goos }}
48+
GOARCH: ${{ matrix.goarch }}
49+
CGO_ENABLED: 0
50+
run: |
51+
go build \
52+
-ldflags="-X main.Version=${{ github.event.release.tag_name }}" \
53+
-o ${{ matrix.output_name }} \
54+
main.go
55+
56+
- name: Create archive (Linux/macOS)
57+
if: matrix.goos != 'windows'
58+
run: |
59+
tar -czf hoster_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz ${{ matrix.output_name }}
60+
61+
- name: Create archive (Windows)
62+
if: matrix.goos == 'windows'
63+
shell: pwsh
64+
run: |
65+
Compress-Archive -Path ${{ matrix.output_name }} -DestinationPath hoster_${{ matrix.goos }}_${{ matrix.goarch }}.zip
66+
67+
- name: Upload to release
68+
uses: softprops/action-gh-release@v2
69+
with:
70+
files: |
71+
hoster_${{ matrix.goos }}_${{ matrix.goarch }}.*
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

README.md

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,53 @@ Docker Hoster watches for container lifecycle events and automatically:
2222

2323
### Prerequisites
2424

25-
- Go 1.16 or higher
2625
- Docker running on the system
2726
- Root/sudo access (required to modify `/etc/hosts`)
2827

29-
### Build from Source
28+
### Option 1: Download Pre-built Binary (Recommended)
29+
30+
Pre-built binaries are available for Linux, macOS, and Windows on the [releases page](https://github.com/zignd/hoster/releases).
31+
32+
**For Linux/macOS:**
33+
34+
```bash
35+
# Download the appropriate binary for your platform
36+
# For Linux x86_64:
37+
wget https://github.com/zignd/hoster/releases/download/vX.Y.Z/hoster_linux_amd64.tar.gz
38+
tar -xzf hoster_linux_amd64.tar.gz
39+
40+
# For Linux ARM64:
41+
wget https://github.com/zignd/hoster/releases/download/vX.Y.Z/hoster_linux_arm64.tar.gz
42+
tar -xzf hoster_linux_arm64.tar.gz
43+
44+
# For macOS Intel (x86_64):
45+
wget https://github.com/zignd/hoster/releases/download/vX.Y.Z/hoster_darwin_amd64.tar.gz
46+
tar -xzf hoster_darwin_amd64.tar.gz
47+
48+
# For macOS Apple Silicon (ARM64):
49+
wget https://github.com/zignd/hoster/releases/download/vX.Y.Z/hoster_darwin_arm64.tar.gz
50+
tar -xzf hoster_darwin_arm64.tar.gz
51+
52+
# Make it executable
53+
chmod +x hoster
54+
55+
# Optionally, move to a location in your PATH
56+
sudo mv hoster /usr/local/bin/
57+
```
58+
59+
**For Windows:**
60+
61+
Download the `.zip` file for your architecture from the [releases page](https://github.com/zignd/hoster/releases), extract it, and place the executable in your preferred location or add it to your PATH.
62+
63+
**Check the installed version:**
64+
65+
```bash
66+
hoster --version
67+
```
68+
69+
### Option 2: Build from Source
70+
71+
Requires Go 1.16 or higher.
3072

3173
```bash
3274
git clone <repository-url>
@@ -42,27 +84,36 @@ go build -o hoster main.go
4284
Run with default settings (requires root):
4385

4486
```bash
45-
sudo ./hoster
87+
sudo hoster
4688
```
4789

90+
**Note:** If you haven't moved the binary to a directory in your PATH, use `./hoster` instead when running from the current directory.
91+
4892
### Command Line Options
4993

5094
View all available options:
5195

5296
```bash
53-
./hoster --help
97+
hoster --help
98+
```
99+
100+
Check the version:
101+
102+
```bash
103+
hoster --version
54104
```
55105

56106
Available flags:
57107

58-
- `--help` - Display help message and exit
108+
- `--help` - Show help message with usage examples and exit
109+
- `--version` - Display version information and exit
59110
- `--hosts <path>` - Path to the hosts file (default: `/etc/hosts`)
60111
- `--socket <path>` - Path to the Docker socket (default: `/var/run/docker.sock`)
61112

62113
Example with custom paths:
63114

64115
```bash
65-
sudo ./hoster --hosts /custom/hosts --socket /var/run/docker.sock
116+
sudo hoster --hosts /custom/hosts --socket /var/run/docker.sock
66117
```
67118

68119
### Running as a Service
@@ -226,14 +277,6 @@ docker run -d --name test nginx
226277
grep test /etc/hosts
227278
```
228279

229-
## License
230-
231-
[Add your license here]
232-
233280
## Contributing
234281

235282
Contributions are welcome! Please feel free to submit issues or pull requests.
236-
237-
## Author
238-
239-
[Add your name/contact here]

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/docker/docker/client"
1717
)
1818

19+
var Version = "dev" // Will be overridden at build time
20+
1921
const (
2022
enclosingPattern = "#-----------Docker-Hoster-Domains----------\n"
2123
defaultHostsPath = "/etc/hosts"
@@ -240,9 +242,15 @@ func main() {
240242
hostsPath := flag.String("hosts", defaultHostsPath, "Path to the hosts file")
241243
dockerSocket := flag.String("socket", defaultSocket, "Path to the Docker socket")
242244
showHelp := flag.Bool("help", false, "Show help message")
245+
showVersion := flag.Bool("version", false, "Display version and exit")
243246

244247
flag.Parse()
245248

249+
if *showVersion {
250+
fmt.Println("hoster version", Version)
251+
os.Exit(0)
252+
}
253+
246254
if *showHelp {
247255
fmt.Println("Docker Hoster - Automatically manage /etc/hosts entries for Docker containers")
248256
fmt.Println()

0 commit comments

Comments
 (0)