Skip to content

Commit

Permalink
add Dockerfile and make target
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-kiselenko committed Jul 20, 2024
1 parent bc20162 commit 055e472
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git/
.github
assets/
bin/
test/
tmp/
LICENSE
README.md
Makefile
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Install](#install)
- [Run](#run)
- [Config](#config)
- [Docker](#docker)
- [Prerequisites](#prerequisites)
- [Built with](#built-with)
- [Contribution](#contribution)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 055e472

Please sign in to comment.