From 055e47274bb5e13d20ed17cc5890c552e0bd0cd6 Mon Sep 17 00:00:00 2001 From: roman-kiselenko Date: Sat, 20 Jul 2024 18:56:09 +0300 Subject: [PATCH] add Dockerfile and make target --- .dockerignore | 9 +++++++++ Dockerfile | 18 ++++++++++++++++++ Makefile | 9 +++++++++ README.md | 20 ++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4e46b2e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git/ +.github +assets/ +bin/ +test/ +tmp/ +LICENSE +README.md +Makefile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f5d8713 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.22-alpine3.20 AS builder + +RUN mkdir /app && mkdir -p /usr/local/src/smolgit +WORKDIR /usr/local/src/smolgit + +ADD ./go.mod ./go.sum ./ +RUN go mod download +ADD . ./ + +RUN go build -v -o /build/smolgit + +FROM alpine/git:2.45.2 AS runner + +COPY --from=builder /build/smolgit /usr/bin/smolgit + +EXPOSE 3080 +EXPOSE 3081 +ENTRYPOINT ["/usr/bin/smolgit", "--config", "/etc/smolgit/config.yaml"] \ No newline at end of file diff --git a/Makefile b/Makefile index 029b115..646f09d 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ all: help build: ## Build all the binaries and put the output in bin/ $(GOCMD) build -ldflags "-X main.version=$(BRANCH)-$(HASH)" -o bin/$(PROJECT_NAME) . +build-docker: ## Build an image + docker build -t $(PROJECT_NAME) . + ## Clean: clean: ## Remove build related file @-rm -fr ./bin @@ -26,6 +29,12 @@ clean: ## Remove build related file run: clean build ## Run the smolgit `make run` ./bin/$(PROJECT_NAME) $(ARGS) +run-docker: ## Run smolgit in the container + docker run -it -p 3080:3080 -p 3081:3081 -v $(PWD)/:/etc/smolgit $(PROJECT_NAME) + +config-docker: ## Generate smolgit config + docker run -it $(PROJECT_NAME) config > config.yaml + config: ## Generate default config ./bin/$(PROJECT_NAME) config > ./config.yaml diff --git a/README.md b/README.md index ff0ea10..204f4b2 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ - [Install](#install) - [Run](#run) - [Config](#config) + - [Docker](#docker) - [Prerequisites](#prerequisites) - [Built with](#built-with) - [Contribution](#contribution) @@ -112,6 +113,25 @@ Usage of ./smolgit: path to config (default "./config.yaml") ``` +#### Docker + +In order to run `smolgit` in docker there is the [`Dockerfile`](/Dockerfile). + +1. Build image `make build-docker` +1. Generate `config.yaml` file `make config-docker`, it'll create `config.yaml` in the current directory and mount it for docker. +1. Run `smolgit` in docker: + +```shell +$> make run-docker +docker run -it -p 3080:3080 -p 3081:3081 -v /path-to-smolgit-project/smolgit/:/etc/smolgit smolgit +3:53PM INF set loglevel level=DEBUG +3:53PM INF version version=dev +3:53PM INF initialize web server addr=:3080 +3:53PM INF initialize ssh server addr=:3081 +3:53PM INF start server brand=smolgit address=:3080 +3:53PM INF starting SSH server addr=:3081 +``` + ### Prerequisites - git