Skip to content

Commit

Permalink
Add support of running the binary within Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed May 24, 2024
1 parent 58e6c72 commit cb6f723
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM alpine:3.19.1

RUN apk --no-cache add tzdata
RUN echo "Asia/Seoul" > /etc/timezone
RUN cp -f /usr/share/zoneinfo/Asia/Seoul /etc/localtime

RUN mkdir /conf
COPY cmd/cm-grasshopper/cm-grasshopper /cm-grasshopper
RUN chmod 755 /cm-grasshopper

USER root
ENTRYPOINT ["./docker-entrypoint.sh"]
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GOPROXY_OPTION := GOPROXY=direct
GO_COMMAND := ${GOPROXY_OPTION} go
GOPATH := $(shell go env GOPATH)

.PHONY: all dependency lint test race coverage coverhtml gofmt update swag swagger build run stop clean help
.PHONY: all dependency lint test race coverage coverhtml gofmt update swag swagger build run run_docker stop stop_docker clean help

all: build

Expand Down Expand Up @@ -119,9 +119,23 @@ run: ## Run the built binary
./cmd/${MODULE_NAME}/${MODULE_NAME} || echo "Trying with sudo..." && sudo ./cmd/${MODULE_NAME}/${MODULE_NAME} & \
fi

run_docker: ## Run the built binary within Docker
@git diff > .diff_current
@STATUS=`diff .diff_last_build .diff_current 2>&1 > /dev/null; echo $$?` && \
GIT_HASH_MINE=`git rev-parse HEAD` && \
GIT_HASH_LAST_BUILD=`cat .git_hash_last_build 2>&1 > /dev/null | true` && \
if [ "$$STATUS" != "0" ] || [ "$$GIT_HASH_MINE" != "$$GIT_HASH_LAST_BUILD" ]; then \
docker rmi -f cm-grasshopper:latest; \
"$(MAKE)" linux; \
fi
@docker compose up -d

stop: ## Stop the built binary
@sudo killall ${MODULE_NAME} | true

stop_docker: ## Stop the Docker container
@docker compose down

clean: ## Remove previous build
@echo Cleaning build...
@rm -f coverage.out
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
cm-honeybee:
container_name: cm-grasshopper
restart: always
privileged: true
build:
context: ./
dockerfile: Dockerfile
image: cm-grasshopper:${TAG:-latest}
entrypoint: /docker-entrypoint.sh
volumes:
- ./docker-entrypoint.sh:/docker-entrypoint.sh:ro
- ./conf/:/conf/:ro
network_mode: "host"
3 changes: 3 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

/cm-grasshopper

0 comments on commit cb6f723

Please sign in to comment.