Merge pull request #11 from DerDavidBohl/9-scheduled-reloaddeploy

Added Scheduled All Deployments Start
This commit is contained in:
David Bohl
2025-01-17 08:07:56 +01:00
committed by GitHub
3 changed files with 70 additions and 8 deletions

View File

@@ -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

View File

@@ -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();
}
}
}

View File

@@ -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 * * * *