Skip to content

Commit

Permalink
feat: add linux systemd service
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir committed Sep 29, 2024
1 parent 0d0a298 commit e0c81aa
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
12 changes: 12 additions & 0 deletions .github/contatto.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Contatto proxy server
After=network.target

[Service]
Type=simple
ExecStart=/bin/contatto -f /etc/contatto.toml
Restart=on-failure
RestartSec=1min

[Install]
WantedBy=multi-user.target
17 changes: 11 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ jobs:
- uses: actions/checkout@v4
- name: build matrix
run: |
mkdir -p etc
make test
mkdir -p etc/systemd/system
mv conf/contatto.toml etc/contatto.toml
mv .github/contatto.service etc/systemd/system/contatto.service
file_list=(bin/contatto etc/contatto.toml etc/systemd/system/contatto.service)
echo package files: ${file_list[*]}
make build GO='GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go'
tar czvf contatto-linux-amd64.tar.gz ./bin/ ./etc/contatto.toml
tar czf contatto-linux-amd64.tar.gz ${file_list[*]}
make clean
make build GO='GOOS=linux GOARCH=arm CGO_ENABLED=0 go'
tar czvf contatto-linux-arm.tar.gz ./bin/ ./etc/contatto.toml
tar czf contatto-linux-arm.tar.gz ${file_list[*]}
make clean
make build GO='GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go'
tar czvf contatto-linux-arm64.tar.gz ./bin/ ./etc/contatto.toml
tar czf contatto-linux-arm64.tar.gz ${file_list[*]}
make clean
make build GO='GOOS=linux GOARCH=mips CGO_ENABLED=0 go'
tar czvf contatto-linux-mips.tar.gz ./bin/ ./etc/contatto.toml
tar czf contatto-linux-mips.tar.gz ${file_list[*]}
make clean
make build GO='GOOS=linux GOARCH=mipsle CGO_ENABLED=0 go'
tar czvf contatto-linux-mipsle.tar.gz ./bin/ ./etc/contatto.toml
tar czf contatto-linux-mipsle.tar.gz ${file_list[*]}
make clean
- uses: ncipollo/release-action@v1
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ test:
${GO} vet ./...
${GO} test ./...

build: test
build:
${GO} build -trimpath -ldflags "\
-X main.version=$(shell git describe --tags --always) \
-X main.date=$(shell date +%Y-%m-%d)" \
-X github.com/wweir/contatto/conf.Version=$(shell git describe --tags --always) \
-X github.com/wweir/contatto/conf.Date=$(shell date +%Y-%m-%d)" \
-o bin/contatto .
run: build
./bin/contatto proxy --debug -c contatto.toml
Expand Down
4 changes: 2 additions & 2 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"gopkg.in/yaml.v3"
)

var Branch, Version, Date string
var Version, Date string

type Config struct {
Addr string
Expand Down Expand Up @@ -63,7 +63,7 @@ func ReadConfig(file string) (*Config, error) {
return nil, fmt.Errorf("mapstructure config: %w", err)
}

slog.Info("Starting with config", "branch", Branch, "version", Version, "date", Date, "config", c)
slog.Info("Starting with config", "version", Version, "date", Date, "config", c)

for host, registry := range c.Registry {
if registry.registry == "" {
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

var cli struct {
Config string `short:"c" required:"" default:"/etc/contatto.toml"`
Debug bool `help:"debug mode"`
Debug bool `help:"Enable debug logging"`

Install *InstallCmd `cmd:"" help:"install contatto"`
Proxy *ProxyCmd `cmd:"" help:"run as registry proxy"`
Proxy *ProxyCmd `cmd:"" help:"Execute Contatto as a registry proxy."`
}

func main() {
Expand All @@ -27,7 +27,8 @@ func main() {

ctx := kong.Parse(&cli,
kong.UsageOnError(),
kong.Description(fmt.Sprintf(`Contatto %s (%s %s)`, conf.Version, conf.Branch, conf.Date)),
kong.Description(fmt.Sprintf(
`Contatto %s(%s) is a container registry transparent proxy.`, conf.Version, conf.Date)),
)

config, err := conf.ReadConfig(cli.Config)
Expand Down

0 comments on commit e0c81aa

Please sign in to comment.