Skip to content

Commit

Permalink
Build Docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Dec 11, 2023
1 parent e469a33 commit 3028ccb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build
on:
pull_request:
push:

permissions:
contents: read
packages: write

jobs:
build-server:
runs-on: ubuntu-latest
name: Build
steps:

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ~1.21.5
check-latest: true

- name: Build binary
run: |
make build
- name: Log in to the GitHub container registry
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
tags: ghcr.io/kastelo/syncthing-autoacceptd:latest
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM gcr.io/distroless/static:nonroot
LABEL org.opencontainers.image.title "Syncthing Auto Accept Daemon"
LABEL org.opencontainers.image.url "https://kastelo.net/"
LABEL org.opencontainers.image.vendor "Kastelo AB"
LABEL org.opencontainers.image.source "https://github.com/kastelo/syncthing-autoacceptd"
ARG TARGETARCH
COPY bin/syncthing-autoacceptd-linux-$TARGETARCH /bin/syncthing-autoacceptd
ENTRYPOINT ["/bin/syncthing-autoacceptd"]
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
ldflags:="-X kastelo.dev/syncthing-autoacceptd/internal/build.GitVersion=$(shell git describe)"

.PHONY: install
install:
@go install -v -ldflags $(ldflags) ./cmd/syncthing-autoacceptd

.PHONY: build
build: proto
build: build-linux-amd64 build-linux-arm64

build-linux-amd64:
@mkdir -p bin
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -ldflags $(ldflags) -o bin/syncthing-autoacceptd-linux-amd64 ./cmd/syncthing-autoacceptd

build-linux-arm64:
@mkdir -p bin
@go build -v -ldflags $(ldflags) -o bin/syncthing-autoacceptd ./cmd/autoacceptd
@GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -v -ldflags $(ldflags) -o bin/syncthing-autoacceptd-linux-arm64 ./cmd/syncthing-autoacceptd

.PHONY: proto
proto:
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions cmd/autoacceptd/main.go → cmd/syncthing-autoacceptd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
var errMalformedEvent = errors.New("malformed event")

type CLI struct {
Address string `short:"a" help:"Address of Syncthing API" default:"127.0.0.1:8384" env:"SYNCTHING_AUTOACCEPTD__ADDRESS"`
APIKey string `short:"k" help:"Key for the Syncthing API" required:"true" env:"SYNCTHING_AUTOACCEPTD__API_KEY"`
Config string `short:"c" type:"existingfile" help:"Path to autoacceptd.conf" default:"~/.config/syncthing-autoacceptd/autoacceptd.conf" env:"SYNCTHING_AUTOACCEPTD_CONFIG"`
Debug bool `short:"d" help:"Enable debug logging" env:"SYNCTHING_AUTOACCEPTD_DEBUG"`
Address string `short:"a" help:"Address of Syncthing API" default:"127.0.0.1:8384" env:"SYNCTHING_AUTOACCEPTD_ADDRESS"`
APIKey string `short:"k" help:"Key for the Syncthing API" required:"true" env:"SYNCTHING_AUTOACCEPTD_APIKEY"`
Patterns string `short:"p" type:"existingfile" help:"Path to patterns.conf" required:"true" env:"SYNCTHING_AUTOACCEPTD_PATTERNS_FILE"`
Debug bool `short:"d" help:"Enable debug logging" env:"SYNCTHING_AUTOACCEPTD_DEBUG"`
}

func main() {
Expand Down Expand Up @@ -53,7 +53,7 @@ func main() {

// Read and validate config file
var patterns config.Configuration
bs, err := os.ReadFile(cli.Config)
bs, err := os.ReadFile(cli.Patterns)
if err != nil {
l.Error("Failed to read config", "error", err)
os.Exit(2)
Expand Down

0 comments on commit 3028ccb

Please sign in to comment.