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 e2660d3 commit 03f6541
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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-cicada/cm-cicada /cm-cicada
RUN mkdir -p /lib/airflow/example/
COPY lib/airflow/example /lib/airflow/example
RUN chmod 755 /cm-cicada

USER root
ENTRYPOINT ["./docker-entrypoint.sh"]
17 changes: 14 additions & 3 deletions 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_airflow stop_airflow run stop clean_dags clean help
.PHONY: all dependency lint test race coverage coverhtml gofmt update swag swagger build run_airflow stop_airflow run run_docker stop stop_docker clean help

all: build

Expand Down Expand Up @@ -90,11 +90,22 @@ run: run_airflow ## Run Airflow server and the built binary
fi
@cp -RpPf conf cmd/${MODULE_NAME}/ && ./cmd/${MODULE_NAME}/${MODULE_NAME}* || echo "Trying with sudo..." && sudo ./cmd/${MODULE_NAME}/${MODULE_NAME}* &

run_docker: run_airflow ## Run Airflow server and 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-cicada:latest; \
"$(MAKE)"; \
fi
@docker compose up -d

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

clean_dags: ## Clean DAGs folder
@sudo rm -rf _airflow/airflow-home/dags/*-*-*-*
stop_docker: stop_airflow ## Stop the Docker containers
@docker compose down

clean: ## Remove previous build
@echo Cleaning build...
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
cm-cicada:
container_name: cm-cicada
restart: always
privileged: true
build:
context: ./
dockerfile: Dockerfile
image: cm-cicada:${TAG:-latest}
entrypoint: /docker-entrypoint.sh
volumes:
- ./docker-entrypoint.sh:/docker-entrypoint.sh:ro
- ./conf/:/conf/:ro
- ./_airflow:/_airflow:rw
- ./CM-CICADA.db:/CM-CICADA.db:rw
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-cicada

0 comments on commit 03f6541

Please sign in to comment.