diff --git a/README.md b/README.md index cdab019..96ce479 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,40 @@ level of precision is better left to other tools. days: [Monday, Wednesday] ``` -These can be combined to emit a new version on an interval during a particular -time period. + These can be combined to emit a new version on an interval during a particular + time period. + +* `initial_version`: *Optional.* When using `start` and `stop` as a trigger for + a job, you will be unable to run the job manually until it goes into the + configured time range for the first time (manual runs will work once the `time` + resource has produced it's first version). + + To get around this issue, there are two approaches: + * Use `initial_version: true`, which will produce a new version that is + set to the current time, if `check` runs and there isn't already a version + specified. **NOTE: This has a downside that if used with `trigger: true`, it will + kick off the correlating job when the pipeline is first created, even + outside of the specified window**. + * Alternatively, once you push a pipeline that utilizes `start` and `stop`, run the + following fly command to run the resource check from a previous point + in time (see [this issue](https://github.com/concourse/time-resource/issues/24#issuecomment-689422764) + for 6.x.x+ or [this issue](https://github.com/concourse/time-resource/issues/11#issuecomment-562385742) + for older Concourse versions). + + ``` + fly -t \ + check-resource + --from "time:2000-01-01T00:00:00Z" # the important part + ``` + + This has the benefit that it shouldn't trigger that initial job run, but + will still allow you to manually run the job if needed. + + e.g. + + ``` + initial_version: true + ``` ## Behavior diff --git a/check_command.go b/check_command.go index afdee69..0e0d34f 100644 --- a/check_command.go +++ b/check_command.go @@ -37,6 +37,9 @@ func (*CheckCommand) Run(request models.CheckRequest) ([]models.Version, error) if !previousTime.IsZero() { versions = append(versions, models.Version{Time: previousTime}) + } else if request.Source.InitialVersion { + versions = append(versions, models.Version{Time: currentTime}) + return versions, nil } if tl.Check(currentTime) { diff --git a/dockerfiles/ubuntu/Dockerfile b/dockerfiles/ubuntu/Dockerfile index 427e281..1592083 100644 --- a/dockerfiles/ubuntu/Dockerfile +++ b/dockerfiles/ubuntu/Dockerfile @@ -1,4 +1,4 @@ -ARG base_image +ARG base_image=ubuntu:latest ARG builder_image=concourse/golang-builder FROM ${builder_image} AS builder @@ -12,19 +12,19 @@ RUN go build -o /assets/out github.com/concourse/time-resource/out RUN go build -o /assets/in github.com/concourse/time-resource/in RUN go build -o /assets/check github.com/concourse/time-resource/check RUN set -e; for pkg in $(go list ./...); do \ - go test -o "/tests/$(basename $pkg).test" -c $pkg; \ + go test -o "/tests/$(basename $pkg).test" -c $pkg; \ done FROM ${base_image} AS resource RUN apt update && apt upgrade -y -o Dpkg::Options::="--force-confdef" RUN apt update && apt install -y --no-install-recommends tzdata \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* COPY --from=builder /assets /opt/resource FROM resource AS tests COPY --from=builder /tests /tests RUN set -e; for test in /tests/*.test; do \ - $test; \ + $test; \ done FROM resource diff --git a/models/models.go b/models/models.go index 6a97694..ab85658 100644 --- a/models/models.go +++ b/models/models.go @@ -39,11 +39,12 @@ type CheckRequest struct { type CheckResponse []Version type Source struct { - Interval *Interval `json:"interval"` - Start *TimeOfDay `json:"start"` - Stop *TimeOfDay `json:"stop"` - Days []Weekday `json:"days"` - Location *Location `json:"location"` + InitialVersion bool `json:"initial_version"` + Interval *Interval `json:"interval"` + Start *TimeOfDay `json:"start"` + Stop *TimeOfDay `json:"stop"` + Days []Weekday `json:"days"` + Location *Location `json:"location"` } func (source Source) Validate() error {