Goit

Simple and lightweight Git web server
git clone http://git.omkov.net/Goit
Log | Tree | Refs | README | Download

AuthorJakob Wakeling <[email protected]>
Date2023-12-17 07:00:10
Commit4c7b0234656c552b576270cddb42e6429d8421f3
Parent6b13ddb62458c060b3fe9db08e470f30d1a7b550

Add a containerfile and associated make recipe

Diffstat

A Containerfile | 20 ++++++++++++++++++++
M Makefile | 10 +++++++---

2 files changed, 27 insertions, 3 deletions

diff --git a/Containerfile b/Containerfile
new file mode 100644
index 0000000..d8447ce
--- /dev/null
+++ b/Containerfile
@@ -0,0 +1,20 @@
+FROM golang:alpine as build
+RUN apk update
+RUN apk upgrade
+RUN apk add --no-cache build-base
+COPY . /app
+WORKDIR /app
+ARG version
+RUN VERSION=$version make build
+
+FROM alpine:latest
+RUN apk update
+RUN apk upgrade
+RUN apk add --no-cache git
+COPY --from=build /app/bin /app/bin
+RUN mkdir -p /run/user/0
+WORKDIR /app
+ENV XDG_CONFIG_HOME=/app/config XDG_DATA_HOME=/app/data XDG_STATE_HOME=/app/state
+EXPOSE 8080
+VOLUME /app/config/goit /app/data/goit /app/state/goit
+ENTRYPOINT ["/app/bin/goit"]
diff --git a/Makefile b/Makefile
index a262d64..df2fcb5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,19 @@
-.PHONY: all build test help
+.PHONY: all build image test help
 all: help
 
 MODULE = "github.com/Jamozed/Goit"
 PROGRAM = "goit"
-VERSION = "0.0.0"
+VERSION ?= "dev"
 
 build: ## Build the project
 	@go build -ldflags "-X $(MODULE)/res.Version=$(VERSION)" -o ./bin/$(PROGRAM) ./src
 
+image: ## Build the project image
+	@docker build -t $(PROGRAM):$(VERSION) --build-arg version=$(VERSION) .
+
 test: ## Run unit tests
 	@go test ./...
 
 help: ## Display help information
-	@grep -E '^[a-zA-Z_-]+:.*?##.*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## *"}; {printf "\033[36m%-6s\033[0m %s\n", $$1, $$2}'
+	@grep -E '^[a-zA-Z_-]+:.*?##.*$$' $(MAKEFILE_LIST) | \
+		awk 'BEGIN {FS = ":.*?## *"}; {printf "\033[36m%-6s\033[0m %s\n", $$1, $$2}'