Skip to content

Commit

Permalink
Applied changes from mcuadros#137
Browse files Browse the repository at this point in the history
  • Loading branch information
rdelcorro authored and TheDevMinerTV committed May 31, 2022
1 parent 94edcdf commit 5b0a009
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 234 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:1.17.1-alpine AS builder
FROM golang:1.18.1-alpine3.15 AS builder

RUN apk --no-cache add gcc musl-dev
RUN apk --no-cache add gcc musl-dev git

WORKDIR ${GOPATH}/src/github.com/mcuadros/ofelia
COPY . ${GOPATH}/src/github.com/mcuadros/ofelia

RUN go build -o /go/bin/ofelia .

FROM alpine:3.14.2
FROM alpine:3.16.0

# this label is required to identify container with ofelia running
LABEL ofelia.service=true
Expand Down
48 changes: 39 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ In order to use this type of configurations, ofelia need access to docker socket
```sh
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
--label ofelia.job-local.my-test-job.schedule="@every 5s" \
--label ofelia.job-local.my-test-job.command="date" \
mcuadros/ofelia:latest daemon --docker
mcuadros/ofelia:latest daemon
```

Labels format: `ofelia.<JOB_TYPE>.<JOB_NAME>.<JOB_PARAMETER>=<PARAMETER_VALUE>.
Expand All @@ -86,9 +84,8 @@ docker run -it --rm \
nginx
```

Now if we start `ofelia` container with the command provided above, it will pickup 2 jobs:
Now if we start `ofelia` container with the command provided above, it will execute the task:

- Local - `date`
- Exec - `uname -a`

Or with docker-compose:
Expand All @@ -100,12 +97,9 @@ services:
image: mcuadros/ofelia:latest
depends_on:
- nginx
command: daemon --docker
command: daemon
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
labels:
ofelia.job-local.my-test-job.schedule: "@every 5s"
ofelia.job-local.my-test-job.command: "date"

nginx:
image: nginx
Expand All @@ -115,6 +109,42 @@ services:
ofelia.job-exec.datecron.command: "uname -a"
```
#### Dynamic docker configuration
You can start ofelia in its own container or on the host itself, and it will magically pick up any container that starts, stops or is modified on the fly.
In order to achieve this, you simply have to use docker containers with the labels described above and let ofelia take care of the rest.
#### Hybrid configuration (INI files + Docker)
You can specify part of the configuration on the INI files, such as globals for the middlewares or even declare tasks in there but also merge them with docker.
The docker labels will be parsed, added and removed on the fly but also, the file config can be used.
**Use the INI file to:**
- Configure the slack or other middleware integration
- Configure any global setting
- Create a job-run so it executes on a new container each time
```ini
[global]
slack-webhook = https://myhook.com/auth

[job-run "job-executed-on-new-container"]
schedule = @hourly
image = ubuntu:latest
command = touch /tmp/example
```

**Use docker to:**

```sh
docker run -it --rm \
--label ofelia.enabled=true \
--label ofelia.job-exec.test-exec-job.schedule="@every 5s" \
--label ofelia.job-exec.test-exec-job.command="uname -a" \
nginx
```

### Logging
**Ofelia** comes with three different logging drivers that can be configured in the `[global]` section:
- `mail` to send mails
Expand Down
Loading

0 comments on commit 5b0a009

Please sign in to comment.