Skip to content

Commit 38695a2

Browse files
authored
Compliance with XDG (#619)
1 parent 3a6bf29 commit 38695a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+856
-810
lines changed

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ tmp/*
1919
# Goland
2020
.idea
2121

22-
# local development
23-
!local/cert
24-
local/cert/*
25-
!local/cert/openssl.conf
22+
# Directory for local development
23+
local/

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ WORKDIR /home/${USER}
4545

4646
COPY --from=go-builder /app/bin/dagu /usr/local/bin/
4747

48-
RUN mkdir -p .dagu/dags
48+
RUN mkdir -p .config/dagu/dags
4949

5050
# Add the hello_world.yaml file
51-
COPY <<EOF .dagu/dags/hello_world.yaml
51+
COPY <<EOF .config/dagu/dags/hello_world.yaml
5252
schedule: "* * * * *"
5353
steps:
5454
- name: hello world

Makefile

+114-67
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,130 @@
1-
.PHONY: build server scheduler test proto certs swagger https
1+
.PHONY: run run-server run-server-https run-scheduler test lint build certs swagger
22

3-
########## Arguments ##########
3+
##############################################################################
4+
# Arguments
5+
##############################################################################
46

57
VERSION=
68

7-
########## Variables ##########
9+
##############################################################################
10+
# Variables
11+
##############################################################################
812

913
# This Makefile's directory
1014
SCRIPT_DIR=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
15+
16+
# Directories for miscellaneous files for the local environment
1117
LOCAL_DIR=$(SCRIPT_DIR)/local
18+
LOCAL_BIN_DIR=$(LOCAL_DIR)/bin
1219

13-
SRC_DIR=$(SCRIPT_DIR)
14-
DST_DIR=$(SRC_DIR)/internal
20+
# Configuration directory
21+
CONFIG_DIR=$(SCRIPT_DIR)/config
1522

23+
# Local build settings
24+
BIN_DIR=$(SCRIPT_DIR)/bin
1625
BUILD_VERSION=$(shell date +'%y%m%d%H%M%S')
1726
LDFLAGS=-X 'main.version=$(BUILD_VERSION)'
1827

19-
DOCKER_CMD := docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm64/v8 --builder container --build-arg VERSION=$(VERSION) --push --no-cache
28+
# Application name
2029

21-
DEV_CERT_SUBJ_CA="/C=TR/ST=ASIA/L=TOKYO/O=DEV/OU=DAGU/CN=*.dagu.dev/emailAddress[email protected]"
22-
DEV_CERT_SUBJ_SERVER="/C=TR/ST=ASIA/L=TOKYO/O=DEV/OU=SERVER/CN=*.server.dev/emailAddress[email protected]"
23-
DEV_CERT_SUBJ_CLIENT="/C=TR/ST=ASIA/L=TOKYO/O=DEV/OU=CLIENT/CN=*.client.dev/emailAddress[email protected]"
24-
DEV_CERT_SUBJ_ALT="subjectAltName=DNS:localhost"
30+
APP_NAME=dagu
2531

26-
PKG_SWAGGER=github.com/go-swagger/go-swagger/cmd/swagger
27-
PKG_GOLANGCI_LINT=github.com/golangci/golangci-lint/cmd/golangci-lint
28-
PKG_gotestsum=gotest.tools/gotestsum
32+
# Docker image build configuration
33+
DOCKER_CMD := docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm64/v8 --builder container --build-arg VERSION=$(VERSION) --push --no-cache
2934

30-
COLOR_GREEN=\033[0;32m
31-
COLOR_RESET=\033[0m
35+
# Arguments for the tests
36+
GOTESTSUM_ARGS=--format=standard-quiet
37+
GO_TEST_FLAGS=-v --race
38+
39+
# Frontend directories
3240

3341
FE_DIR=./internal/frontend
3442
FE_GEN_DIR=${FE_DIR}/gen
3543
FE_ASSETS_DIR=${FE_DIR}/assets
44+
FE_BUILD_DIR=./ui/dist
45+
FE_BUNDLE_JS=${FE_ASSETS_DIR}/bundle.js
3646

37-
CERT_DIR=${LOCAL_DIR}/cert
47+
# Colors for the output
3848

39-
CA_CERT_FILE=${CERT_DIR}/ca-cert.pem
40-
CA_KEY_FILE=${CERT_DIR}/ca-key.pem
41-
SERVER_CERT_REQ=${CERT_DIR}/server-req.pem
42-
SERVER_CERT_FILE=${CERT_DIR}/server-cert.pem
43-
SERVER_KEY_FILE=${CERT_DIR}/server-key.pem
44-
CLIENT_CERT_REQ=${CERT_DIR}/client-req.pem
45-
CLIENT_CERT_FILE=${CERT_DIR}/client-cert.pem
46-
CLIENT_KEY_FILE=${CERT_DIR}/client-key.pem
47-
OPENSSL_CONF=${CERT_DIR}/openssl.conf
49+
COLOR_GREEN=\033[0;32m
50+
COLOR_RESET=\033[0m
51+
COLOR_RED=\033[0;31m
4852

49-
FE_BUILD_DIR=./ui/dist
50-
FE_BUNDLE_JS=${FE_ASSETS_DIR}/bundle.js
53+
# Go packages for the tools
5154

52-
APP_NAME=dagu
53-
BIN_DIR=${SCRIPT_DIR}/bin
55+
PKG_swagger=github.com/go-swagger/go-swagger/cmd/swagger
56+
PKG_golangci_lint=github.com/golangci/golangci-lint/cmd/golangci-lint
57+
PKG_gotestsum=gotest.tools/gotestsum
58+
PKG_gomerger=github.com/yohamta/gomerger
5459

55-
# gotestsum args
56-
GOTESTSUM_ARGS=--format=standard-quiet
57-
GO_TEST_FLAGS=-v --race
60+
# Certificates for the development environment
61+
62+
CERTS_DIR=${LOCAL_DIR}/certs
63+
64+
DEV_CERT_SUBJ_CA="/C=TR/ST=ASIA/L=TOKYO/O=DEV/OU=DAGU/CN=*.dagu.dev/emailAddress[email protected]"
65+
DEV_CERT_SUBJ_SERVER="/C=TR/ST=ASIA/L=TOKYO/O=DEV/OU=SERVER/CN=*.server.dev/emailAddress[email protected]"
66+
DEV_CERT_SUBJ_CLIENT="/C=TR/ST=ASIA/L=TOKYO/O=DEV/OU=CLIENT/CN=*.client.dev/emailAddress[email protected]"
67+
DEV_CERT_SUBJ_ALT="subjectAltName=DNS:localhost"
68+
69+
CA_CERT_FILE=${CERTS_DIR}/ca-cert.pem
70+
CA_KEY_FILE=${CERTS_DIR}/ca-key.pem
71+
SERVER_CERT_REQ=${CERTS_DIR}/server-req.pem
72+
SERVER_CERT_FILE=${CERTS_DIR}/server-cert.pem
73+
SERVER_KEY_FILE=${CERTS_DIR}/server-key.pem
74+
CLIENT_CERT_REQ=${CERTS_DIR}/client-req.pem
75+
CLIENT_CERT_FILE=${CERTS_DIR}/client-cert.pem
76+
CLIENT_KEY_FILE=${CERTS_DIR}/client-key.pem
77+
OPENSSL_CONF=${CONFIG_DIR}/openssl.local.conf
5878

59-
########## Main Targets ##########
79+
##############################################################################
80+
# Targets
81+
##############################################################################
6082

6183
# run starts the frontend server and the scheduler.
6284
run: ${FE_BUNDLE_JS}
63-
go run . start-all
85+
@echo "${COLOR_GREEN}Starting the frontend server and the scheduler...${COLOR_RESET}"
86+
@go run . start-all
87+
88+
# server build the binary and start the server.
89+
run-server: golangci-lint build-bin
90+
@echo "${COLOR_GREEN}Starting the server...${COLOR_RESET}"
91+
${LOCAL_BIN_DIR}/${APP_NAME} server
92+
93+
# scheduler build the binary and start the scheduler.
94+
run-scheduler: golangci-lint build-bin
95+
@echo "${COLOR_GREEN}Starting the scheduler...${COLOR_RESET}"
96+
${LOCAL_BIN_DIR}/${APP_NAME} scheduler
6497

6598
# check if the frontend assets are built.
6699
${FE_BUNDLE_JS}:
67-
echo "Please run 'make build-ui' to build the frontend assets."
100+
@echo "${COLOR_RED}Error: frontend assets are not built.${COLOR_RESET}"
101+
@echo "${COLOR_RED}Please run 'make build-ui' before starting the server.${COLOR_RESET}"
68102

69103
# https starts the server with the HTTPS protocol.
70-
https: ${SERVER_CERT_FILE} ${SERVER_KEY_FILE}
104+
run-server-https: ${SERVER_CERT_FILE} ${SERVER_KEY_FILE}
105+
@echo "${COLOR_GREEN}Starting the server with HTTPS...${COLOR_RESET}"
71106
@DAGU_CERT_FILE=${SERVER_CERT_FILE} \
72107
DAGU_KEY_FILE=${SERVER_KEY_FILE} \
73108
go run . start-all
74109

75-
# watch starts development UI server.
76-
# The backend server should be running.
77-
watch:
78-
@echo "${COLOR_GREEN}Installing nodemon...${COLOR_RESET}"
79-
@npm install -g nodemon
80-
@nodemon --watch . --ext go,gohtml --verbose --signal SIGINT --exec 'make server'
81-
82110
# test runs all tests.
83111
test:
84-
@go install ${PKG_gotestsum}
85-
@gotestsum ${GOTESTSUM_ARGS} -- ${GO_TEST_FLAGS} ./...
112+
@echo "${COLOR_GREEN}Running tests...${COLOR_RESET}"
113+
@GOBIN=${LOCAL_BIN_DIR} go install ${PKG_gotestsum}
114+
@${LOCAL_BIN_DIR}/gotestsum ${GOTESTSUM_ARGS} -- ${GO_TEST_FLAGS} ./...
86115

87116
# test-coverage runs all tests with coverage.
88117
test-coverage:
89-
@go install ${PKG_gotestsum}
90-
@gotestsum ${GOTESTSUM_ARGS} -- ${GO_TEST_FLAGS} -coverprofile="coverage.txt" -covermode=atomic ./...
118+
@echo "${COLOR_GREEN}Running tests with coverage...${COLOR_RESET}"
119+
@GOBIN=${LOCAL_BIN_DIR} go install ${PKG_gotestsum}
120+
@${LOCAL_BIN_DIR}/gotestsum ${GOTESTSUM_ARGS} -- ${GO_TEST_FLAGS} -coverprofile="coverage.txt" -covermode=atomic ./...
91121

92122
# test-clean cleans the test cache and run all tests.
93123
test-clean: build-bin
94-
@go install ${PKG_gotestsum}
124+
@echo "${COLOR_GREEN}Running tests...${COLOR_RESET}"
125+
@GOBIN=${LOCAL_BIN_DIR} go install ${PKG_gotestsum}
95126
@go clean -testcache
96-
@gotestsum ${GOTESTSUM_ARGS} -- ${GO_TEST_FLAGS} ./...
127+
@${LOCAL_BIN_DIR}/gotestsum ${GOTESTSUM_ARGS} -- ${GO_TEST_FLAGS} ./...
97128

98129
# lint runs the linter.
99130
lint: golangci-lint
@@ -102,7 +133,7 @@ lint: golangci-lint
102133
swagger: clean-swagger gen-swagger
103134

104135
# certs generates the certificates to use in the development environment.
105-
certs: ${SERVER_CERT_FILE} ${CLIENT_CERT_FILE} gencert-check
136+
certs: ${CERTS_DIR} ${SERVER_CERT_FILE} ${CLIENT_CERT_FILE} certs-check
106137

107138
# build build the binary.
108139
build: build-ui build-bin
@@ -112,30 +143,38 @@ build: build-ui build-bin
112143
# ```sh
113144
# make build-image VERSION={version}
114145
# ```
115-
# {version} should be the version number such as v1.13.0.
146+
# {version} should be the version number such as "1.13.0".
147+
116148
build-image: build-image-version build-image-latest
117149
build-image-version:
118150
ifeq ($(VERSION),)
119-
$(error "VERSION is null")
151+
$(error "VERSION is not set")
120152
endif
153+
echo "${COLOR_GREEN}Building the docker image with the version $(VERSION)...${COLOR_RESET}"
121154
$(DOCKER_CMD) -t ghcr.io/dagu-dev/${APP_NAME}:$(VERSION) .
122155

123156
# build-image-latest build the docker image with the latest tag and push to
124157
# the registry.
125158
build-image-latest:
159+
@echo "${COLOR_GREEN}Building the docker image...${COLOR_RESET}"
126160
$(DOCKER_CMD) -t ghcr.io/dagu-dev/${APP_NAME}:latest .
127161

128-
# server build the binary and start the server.
129-
server: golangci-lint build-bin
130-
${BIN_DIR}/${APP_NAME} server
162+
gomerger: ${LOCAL_DIR}/merged
163+
@echo "${COLOR_GREEN}Merging Go files...${COLOR_RESET}"
164+
@rm -f ${LOCAL_DIR}/merged/merged_project.go
165+
@GOBIN=${LOCAL_BIN_DIR} go install ${PKG_gomerger}
166+
@${LOCAL_BIN_DIR}/gomerger .
167+
@mv merged_project.go ${LOCAL_DIR}/merged/
131168

132-
# scheduler build the binary and start the scheduler.
133-
scheduler: golangci-lint build-bin
134-
${BIN_DIR}/${APP_NAME} scheduler
169+
${LOCAL_DIR}/merged:
170+
@mkdir -p ${LOCAL_DIR}/merged
135171

136-
########## Tools ##########
172+
##############################################################################
173+
# Internal targets
174+
##############################################################################
137175

138176
build-bin:
177+
@echo "${COLOR_GREEN}Building the binary...${COLOR_RESET}"
139178
@mkdir -p ${BIN_DIR}
140179
@go build -ldflags="$(LDFLAGS)" -o ${BIN_DIR}/${APP_NAME} .
141180

@@ -148,20 +187,25 @@ build-ui:
148187
@cp ${FE_BUILD_DIR}/* ${FE_ASSETS_DIR}
149188

150189
golangci-lint:
151-
@go install $(PKG_GOLANGCI_LINT)
152-
@golangci-lint run ./...
190+
@echo "${COLOR_GREEN}Running linter...${COLOR_RESET}"
191+
@GOBIN=${LOCAL_BIN_DIR} go install $(PKG_golangci_lint)
192+
@${LOCAL_BIN_DIR}/golangci-lint run ./...
153193

154194
clean-swagger:
195+
@echo "${COLOR_GREEN}Cleaning the swagger files...${COLOR_RESET}"
155196
@rm -rf ${FE_GEN_DIR}/restapi/models
156197
@rm -rf ${FE_GEN_DIR}/restapi/operations
157198

158199
gen-swagger:
159-
@go install $(PKG_SWAGGER)
160-
@swagger validate ./swagger.yaml
161-
@swagger generate server -t ${FE_GEN_DIR} --server-package=restapi --exclude-main -f ./swagger.yaml
200+
@echo "${COLOR_GREEN}Generating the swagger server code...${COLOR_RESET}"
201+
@GOBIN=${LOCAL_BIN_DIR} go install $(PKG_swagger)
202+
@${LOCAL_BIN_DIR}/swagger validate ./swagger.yaml
203+
@${LOCAL_BIN_DIR}/swagger generate server -t ${FE_GEN_DIR} --server-package=restapi --exclude-main -f ./swagger.yaml
162204
@go mod tidy
163205

164-
########## Certificates ##########
206+
##############################################################################
207+
# Certificates
208+
##############################################################################
165209

166210
${CA_CERT_FILE}:
167211
@echo "${COLOR_GREEN}Generating CA certificates...${COLOR_RESET}"
@@ -194,7 +238,10 @@ ${CLIENT_CERT_FILE}: ${CA_CERT_FILE} ${CLIENT_KEY_FILE}
194238
-CAkey ${CA_KEY_FILE} -CAcreateserial -out ${CLIENT_CERT_FILE} \
195239
-extfile ${OPENSSL_CONF}
196240

197-
gencert-check:
241+
${CERTS_DIR}:
242+
@echo "${COLOR_GREEN}Creating the certificates directory...${COLOR_RESET}"
243+
@mkdir -p ${CERTS_DIR}
244+
245+
certs-check:
198246
@echo "${COLOR_GREEN}Checking CA certificate...${COLOR_RESET}"
199247
@openssl x509 -in ${SERVER_CERT_FILE} -noout -text
200-

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Dagu is a powerful Cron alternative that comes with a Web UI. It allows you to d
6767
- [**Documentation**](#documentation)
6868
- [**Running as a daemon**](#running-as-a-daemon)
6969
- [**Example DAG**](#example-dag)
70+
- [**Docker-compose setting**](#docker-compose-setting)
7071
- [**Motivation**](#motivation)
7172
- [**Why Not Use an Existing DAG Scheduler Like Airflow?**](#why-not-use-an-existing-dag-scheduler-like-airflow)
7273
- [**How It Works**](#how-it-works)
@@ -176,12 +177,13 @@ brew upgrade dagu-dev/brew/dagu
176177
docker run \
177178
--rm \
178179
-p 8080:8080 \
179-
-v $HOME/.dagu/dags:/home/dagu/.dagu/dags \
180-
-v $HOME/.dagu/data:/home/dagu/.dagu/data \
181-
-v $HOME/.dagu/logs:/home/dagu/.dagu/logs \
180+
-v $HOME/.config/dagu/dags:/home/dagu/.config/dagu/dags \
181+
-v $HOME/.local/share/dagu:/home/dagu/.local/share/dagu \
182182
ghcr.io/dagu-dev/dagu:latest dagu start-all
183183
```
184184

185+
See [Environment variables](https://dagu.readthedocs.io/en/latest/config.html#environment-variables) to configure those default directories.
186+
185187
## **Quick Start Guide**
186188

187189
### 1. Launch the Web UI
@@ -192,7 +194,7 @@ Start the server and scheduler with the command `dagu start-all` and browse to `
192194

193195
Navigate to the DAG List page by clicking the menu in the left panel of the Web UI. Then create a DAG by clicking the `NEW` button at the top of the page. Enter `example` in the dialog.
194196

195-
_Note: DAG (YAML) files will be placed in `~/.dagu/dags` by default. See [Configuration Options](https://dagu.readthedocs.io/en/latest/config.html) for more details._
197+
_Note: DAG (YAML) files will be placed in `~/.config/dagu/dags` by default. See [Configuration Options](https://dagu.readthedocs.io/en/latest/config.html) for more details._
196198

197199
### 3. Edit the DAG
198200

@@ -387,6 +389,10 @@ steps:
387389
- send_report
388390
```
389391
392+
## **Docker-compose setting**
393+
394+
To run Dagu using Docker-compose, please take a look at the example: [docker-compose file](examples/docker-compose.yaml)
395+
390396
## **Motivation**
391397
392398
Legacy systems often have complex and implicit dependencies between jobs. When there are hundreds of cron jobs on a server, it can be difficult to keep track of these dependencies and to determine which job to rerun if one fails. It can also be a hassle to SSH into a server to view logs and manually rerun shell scripts one by one. Dagu aims to solve these problems by allowing you to explicitly visualize and manage pipeline dependencies as a DAG, and by providing a web UI for checking dependencies, execution status, and logs and for rerunning or stopping jobs with a simple mouse click.

0 commit comments

Comments
 (0)