mirror of
https://github.com/DerDavidBohl/dirigent-spring.git
synced 2026-01-04 09:29:44 -06:00
Merge pull request #11 from DerDavidBohl/9-scheduled-reloaddeploy
Added Scheduled All Deployments Start
This commit is contained in:
40
README.md
40
README.md
@@ -15,6 +15,8 @@ services:
|
||||
- DIRIGENT_DEPLOYMENTS_GIT_URL=<Your Deployments Repo>
|
||||
- DIRIGENT_GIT_AUTHTOKEN=<Your Auth token with Access to your repos - only if needed> # optional
|
||||
- DIRIGENT_START_ALL_ON_STARTUP=<Start All Deployments On Startup> # optional Default true
|
||||
- DIRIGENT_DEPLOYMENTS_SCHEDULE_ENABLED=<true/false enable scheduled start of all deployments> # optional Default true
|
||||
- DIRIGENT_DEPLOYMENTS_SCHEDULE_CRON=<cron expression for scheduled start of all deployments> # optional Default * */5 * * * * (Every 5th minute)
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
@@ -30,6 +32,8 @@ docker run -d \
|
||||
-e DIRIGENT_DEPLOYMENTS_GIT_URL=<Your Deployments Repo> \
|
||||
-e DIRIGENT_GIT_AUTHTOKEN=<Your Auth token with Access to your repos - only if needed> \
|
||||
-e DIRIGENT_STARTALL_ON_STARTUP=<Start All Deployments On Startup - only if needed> \
|
||||
-e DIRIGENT_DEPLOYMENTS_SCHEDULE_ENABLED=<true/false enable scheduled start of all deployments - only if needed> \
|
||||
-e DIRIGENT_DEPLOYMENTS_SCHEDULE_CRON=<cron expression for scheduled start of all deployments - only if needed>
|
||||
-v /path/to/config:/app/config \
|
||||
-v /path/to/deployments:/app/deployments \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
@@ -38,11 +42,25 @@ docker run -d \
|
||||
|
||||
### Environment Variables
|
||||
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| DIRIGENT_DEPLOYMENTS_GIT_URL | URL to your deployments git repository | |
|
||||
| DIRIGENT_GIT_AUTHTOKEN | Auth token with access to your repos | |
|
||||
| DIRIGENT_START_ALL_ON_STARTUP | Start all deployments on startup | true |
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------------------------------------------------------------------------------------------------|---------|
|
||||
| DIRIGENT_DEPLOYMENTS_GIT_URL | URL to your deployments git repository | |
|
||||
| DIRIGENT_GIT_AUTHTOKEN | Auth token with access to your repos | |
|
||||
| DIRIGENT_START_ALL_ON_STARTUP | Start all deployments on startup | true |
|
||||
| DIRIGENT_DEPLOYMENTS_SCHEDULE_ENABLED | enable scheduled start of all deployments | true |
|
||||
| DIRIGENT_DEPLOYMENTS_SCHEDULE_CRON | cron expression for scheduled start of all deployments (second minute hour day(month) month day(week) | * */5 * * * * |
|
||||
|
||||
### deployments.yml
|
||||
Example of a `deployments.yml`
|
||||
```yaml
|
||||
deployments:
|
||||
- name: test1
|
||||
source: https://github.com/url/tomyrepo1.git
|
||||
order: 20
|
||||
- name: test2
|
||||
source: https://github.com//url/tomyrepo2.git
|
||||
order: 10
|
||||
```
|
||||
|
||||
### Volumes
|
||||
|
||||
@@ -52,14 +70,22 @@ docker run -d \
|
||||
| /app/deployments | Deployments directory for Dirigent |
|
||||
| /var/run/docker.sock | Docker socket for Dirigent |
|
||||
|
||||
## Webhooks
|
||||
## API
|
||||
|
||||
### Gitea
|
||||
### Gitea Webhook
|
||||
|
||||
1. Create a new webhook in your repository
|
||||
2. Set the URL to `http://<dirigent-host-and-port>/api/v1/gitea`
|
||||
3. Done ;)
|
||||
|
||||
### Deployments
|
||||
|
||||
#### Start All Deployments:
|
||||
`POST` to `/api/v1/deployments/all/start`
|
||||
|
||||
#### Start Deployment by name:
|
||||
`POST` to `/api/v1/deployments/{name}/start`
|
||||
|
||||
## Develop
|
||||
|
||||
### Setup for local Tests
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.davidbohl.dirigent.deployments.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class DeploymentScheduler {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(DeploymentScheduler.class);
|
||||
|
||||
@Value("${dirigent.delpoyments.schedule.enabled}")
|
||||
boolean enabled;
|
||||
|
||||
private final DeploymentsService deploymentsService;
|
||||
|
||||
public DeploymentScheduler(@Autowired DeploymentsService deploymentsService) {
|
||||
this.deploymentsService = deploymentsService;
|
||||
}
|
||||
|
||||
@Scheduled(cron = "${dirigent.delpoyments.schedule.cron}")
|
||||
void runScheduledDeployments() {
|
||||
if(enabled) {
|
||||
logger.info("Starting all deployments scheduled");
|
||||
deploymentsService.startAllDeployments();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,4 +3,6 @@ dirigent.compose.command=docker compose
|
||||
dirigent.deployments.cache.evict.interval=60000
|
||||
dirigent.start.all.on.startup=true
|
||||
spring.profiles.active=local
|
||||
dirigent.git.authToken=
|
||||
dirigent.git.authToken=
|
||||
dirigent.delpoyments.schedule.enabled=true
|
||||
dirigent.delpoyments.schedule.cron=* */5 * * * *
|
||||
Reference in New Issue
Block a user