Skip to main content

Image tag template

Template syntax for tagging built images.

Overview

When building service images as part of uc build or uc deploy commands, Uncloud automatically generates image tags based on the current Git repository state. You can customise the image name and tag format for the built images using the Go template syntax environment variables.

Default template

If you don't specify an image attribute for a service with a build section, Uncloud uses the following Go template for tagging the built image:

{{.Project}}/{{.Service}}:{{if.Git.IsRepo}}{{gitdate "2006-01-02-150405"}}.{{gitsha 7}}{{if.Git.IsDirty}}.dirty{{end}}{{else}}{{date "2006-01-02-150405"}}{{end}}
compose.yaml
services:
web:
build: .

This generates image tags as follows:

  • Git repository (clean): myapp/web:2025-10-30-223604.84d33bb
  • Git repository (with uncommitted changes): myapp/web:2025-10-30-223604.84d33bb.dirty
  • Non-Git directory: myapp/web:2025-10-31-120651

If you specify only an image name without a tag in the image attribute, Uncloud appends the tag portion of the default template to your image name.

compose.yaml
services:
web:
build: .
image: webapp # → webapp:2025-10-30-223604.84d33bb

If you specify a full image name with tag in the image attribute, Uncloud uses it as-is without modification.

compose.yaml
services:
web:
build: .
image: webapp:1.2.3 # → webapp:1.2.3

Template functions

gitsha [length]

Returns the Git commit SHA, optionally truncated to the specified length.

image: myapp:{{gitsha 7}}   # → myapp:84d33bb
image: myapp:{{gitsha}} # → myapp:84d33bbf0dbb37f96e7df6a5010aed7bab00b089

Returns empty string if the working directory is not a Git repository.

gitdate "format" ["timezone"]

Returns the current Git commit date/time formatted using Go time layout format. The timezone parameter is optional and defaults to UTC. Use IANA timezone names like America/New_York or Europe/London.

image: myapp:{{gitdate "2006-01-02"}}                               # → myapp:2025-10-30
image: myapp:{{gitdate "20060102-150405"}} # → myapp:20251030-223604
image: myapp:{{gitdate "2006-01-02-150405" "Australia/Brisbane"}} # → myapp:2025-10-31-083604

Returns empty string if the working directory is not a Git repository.

date "format" ["timezone"]

Returns the current local date/time formatted using Go time layout format. The timezone parameter is optional and defaults to UTC. Use IANA timezone names like America/New_York or Europe/London.

image: myapp:{{date "2006-01-02"}}                # → myapp:2025-10-31
image: myapp:{{date "20060102-150405"}} # → myapp:20251031-120651
image: myapp:{{date "20060102-150405" "Local"}} # → myapp:20251031-220651

Date format reference

Go uses a reference time (Mon Jan 2 15:04:05 MST 2006) for formatting. Replace reference components with desired format:

ComponentReferenceExample
Year20062025
Month0110
Day0230
Hour1522 (24hr)
Minute0436
Second0504

Common patterns:

FormatPatternExample
ISO 8601 date2006-01-022025-10-30
Compact date2006010220251030
Date with compact time2006-01-02-1504052025-10-30-223604

See Go time.Format documentation for all formatting options.

Template fields

Access metadata about your project, service, and Git state:

FieldTypeDescriptionExample
.ProjectstringProject name from name in Compose file or working directory namemyapp
.ServicestringService nameweb
.TagstringPre-rendered default tag (without image name)2025-10-30-223604.84d33bb
.Git.IsRepoboolWhether working directory is a Git repositorytrue or false
.Git.IsDirtyboolWhether there are uncommitted changestrue or false
.Git.SHAstringFull SHA (40 characters) of the latest Git commit84d33bb1234567...
.Git.Datetime.TimeGit commit date/time (use gitdate function to format)-

Environment variable interpolation

Combine templates with environment variable interpolation using Bash-like syntax. The environment variables are expanded before rendering the template.

# CI build number from environment
image: myapp:{{gitdate "20060102"}}.{{gitsha 7}}.${GITHUB_RUN_ID} # → myapp:20251030.84d33bb.1234

# With default value
image: myapp:{{gitsha 7}}.${GITHUB_RUN_ID:-local} # GITHUB_RUN_ID not set → myapp:84d33bb.local

See also