diff --git a/.gitignore b/.gitignore index adf8f72..f65ce7f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # Go workspace file go.work +fluxfeed \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5333e05 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE:-golang:1.22} +ARG REPO_NAME +ARG REPO_SHA + +WORKDIR /app + +# Download Go modules +COPY go.mod ./ +RUN go mod download + +COPY *.go ./ + +RUN CGO_ENABLED=0 GOOS=linux go build -o /fluxfeed + +EXPOSE 8080 + +LABEL io.runcible.repo-name="${REPO_NAME}" \ + io.runcible.repo-sha="${REPO_SHA}" + +CMD ["/fluxfeed"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..780ef80 --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +.DEFAULT_GOAL := build +BASE_GOLANG_IMAGE := golang:1.22 +IMAGE_NAME ?= androiddrew/fluxfeed + +fmt: + go fmt ./... +.PHONY:fmt + +lint: fmt + revive ./... +.PHONY:lint + +vet: fmt + go vet ./... +.PHONY:vet + +build: vet + go build -o ./fluxfeed . +.PHONY:build + +clean: + rm -rf ./fluxfeed +.PHONY:clean + +docs: + echo "Starting godocs on http://localhost:8000" + godoc -http=:8000 +.PHONY:docs + +image: + docker buildx build --platform linux/amd64 \ + --build-arg BASE_IMAGE=$(BASE_GOLANG_IMAGE) \ + --build-arg REPO_NAME=$(IMAGE_NAME) \ + --build-arg REPO_SHA=$(shell git rev-parse HEAD) \ + -t $(IMAGE_NAME) ./ +.PHONY: image \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..aa70edb --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.runcible.io/androiddrew/fluxfeed + +go 1.22.5 diff --git a/main.go b/main.go new file mode 100644 index 0000000..ead7e6a --- /dev/null +++ b/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "io" + "os" +) + +const FluxGreeting string = "Welcome to Flux Feed\n" + +func HelloFluxFeed(out io.Writer) { + fmt.Fprint(out, FluxGreeting) +} + +func main() { + HelloFluxFeed(os.Stdout) +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..66d6cfc --- /dev/null +++ b/main_test.go @@ -0,0 +1,18 @@ +package main + +import ( + "bytes" + "testing" +) + +func TestCliGreeting(t *testing.T) { + buffer := &bytes.Buffer{} + + HelloFluxFeed(buffer) + got := buffer.String() + want := FluxGreeting + + if got != want { + t.Errorf("Got %s but wanted %s", got, want) + } +}