Skip to content

Commit

Permalink
agent: 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 22, 2024
1 parent f81d00f commit 5c77817
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
12 changes: 12 additions & 0 deletions agent/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 iptables podman
RUN echo "Asia/Seoul" > /etc/timezone
RUN cp -f /usr/share/zoneinfo/Asia/Seoul /etc/localtime

RUN mkdir /conf
COPY cmd/cm-honeybee-agent/cm-honeybee-agent /cm-honeybee-agent
RUN chmod 755 /cm-honeybee-agent

USER root
ENTRYPOINT ["./docker-entrypoint.sh"]
16 changes: 15 additions & 1 deletion agent/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 linux windows run clean help
.PHONY: all dependency lint test race coverage coverhtml gofmt update swag swagger build linux windows run run_docker stop stop_docker clean help

all: build

Expand Down Expand Up @@ -118,9 +118,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-honeybee-agent: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
18 changes: 18 additions & 0 deletions agent/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
cm-honeybee-agent:
container_name: cm-honeybee-agent
restart: always
privileged: true
build:
context: ./
dockerfile: Dockerfile
image: cm-honeybee-agent:${TAG:-latest}
entrypoint: /docker-entrypoint.sh
volumes:
- ./docker-entrypoint.sh:/docker-entrypoint.sh:ro
- ./conf/:/conf/:ro
- /etc/:/etc/:ro
- /usr/lib/os-release:/usr/lib/os-release:ro
- /var/:/var/:rw
- /run/:/run/:rw
network_mode: "host"
5 changes: 5 additions & 0 deletions agent/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

echo "WARNING: nvidia-smi is not supported in the container"

/cm-honeybee-agent

0 comments on commit 5c77817

Please sign in to comment.