Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
166 lines (155 loc) · 7.06 KB
/
Copy pathTaskfile.yml
File metadata and controls
166 lines (155 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Taskfile for sprisa/opencode Docker image.
# Install go-task: https://taskfile.dev/installation/ (brew install go-task)
# Run `task` (or `task --list`) to see available commands.
version: "3"
vars:
REGISTRY: docker.io
OWNER: sprisa
IMAGE: opencode
RELEASE_REPO: "{{.OWNER}}/opencode-server"
RELEASE_COMMIT:
sh: git rev-parse HEAD
OCI: "{{.REGISTRY}}/{{.OWNER}}/{{.IMAGE}}"
VERSION:
sh: cat version.txt | tr -d '[:space:]'
VERSION_V1:
sh: cat version-v1.txt | tr -d '[:space:]'
# Monthly apt refresh: see APT_REFRESH in the Dockerfile.
APT_REFRESH:
sh: date -u +%Y-%m
# Build cache on ghcr.io, one tag per line, kept off Docker Hub so users only
# see release tags. Pushes read both (v1 and v2 share every layer below the
# opencode binary) and write their own, so unchanged layers keep their
# digests across releases and nodes only download what changed. Without a
# ghcr.io login, the import only warns and the export is skipped.
CACHE_REPO: ghcr.io/{{.OWNER}}/opencode-buildcache
CACHE_FROM: >-
--cache-from type=registry,ref={{.CACHE_REPO}}:v2
--cache-from type=registry,ref={{.CACHE_REPO}}:v1
tasks:
default:
desc: List available tasks
cmds:
- task --list
silent: true
update:
desc: Fetch latest opencode releases from GitHub and update version.txt (v2) and version-v1.txt (v1)
preconditions:
- sh: command -v gh >/dev/null
msg: "GitHub CLI not found. Install it: brew install gh"
- sh: command -v jq >/dev/null
msg: "jq not found. Install it: brew install jq"
cmds:
- |
RELEASES=$(bash ./scripts/latest-releases.sh)
update_track() {
local file="$1" track="$2"
local latest cur
latest="$(printf '%s' "$RELEASES" | jq -er --arg track "$track" '.[$track]')"
cur="$(cat "$file" 2>/dev/null | tr -d '[:space:]' || true)"
if [ -z "$cur" ] || jq -en --arg latest "$latest" --arg current "$cur" \
'($latest | split(".") | map(tonumber)) > ($current | split(".") | map(tonumber))' >/dev/null; then
echo "$latest" > "$file"
echo "$file updated: ${cur:-none} -> $latest"
else
echo "$file is up to date: $cur (upstream: $latest)"
fi
}
update_track version.txt v2
update_track version-v1.txt v1
docker:build:
desc: "Build the image locally (tag: sprisa/opencode:<version>)"
cmds:
- docker build --build-arg OPENCODE_VERSION={{.VERSION}} --build-arg APT_REFRESH={{.APT_REFRESH}} --build-arg IMAGE_CREATED="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" -t {{.OCI}}:{{.VERSION}} .
docker:push:
desc: "Build and push multi-arch v2 image to Docker Hub with <version>, :latest, and :v2 tags"
cmds:
- |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg OPENCODE_VERSION={{.VERSION}} \
--build-arg APT_REFRESH={{.APT_REFRESH}} \
--build-arg IMAGE_CREATED="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
{{.CACHE_FROM}} \
--cache-to type=registry,ref={{.CACHE_REPO}}:v2,mode=max,ignore-error=true \
--push \
-t {{.OCI}}:{{.VERSION}} \
-t {{.OCI}}:latest \
-t {{.OCI}}:v2 \
.
- "echo Pushed {{.OCI}}:{{.VERSION}}, {{.OCI}}:latest and {{.OCI}}:v2"
docker:login:
desc: "Log in to Docker Hub (needs $DOCKER_USER and $DOCKER_PASS)"
preconditions:
- sh: '[ -n "$DOCKER_USER" ]'
msg: "Set DOCKER_USER"
- sh: '[ -n "$DOCKER_PASS" ]'
msg: "Set DOCKER_PASS (use a Docker Hub access token)"
cmds:
- "echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin"
publish:
desc: "Push pinned tracks (v2 + v1) not yet on Docker Hub and create missing GitHub Releases (FORCE=true republishes)"
preconditions:
- sh: command -v gh >/dev/null
msg: "GitHub CLI not found. Install it: brew install gh"
- sh: gh auth status >/dev/null 2>&1
msg: "Not logged in to GitHub CLI. Run: gh auth login"
cmds:
- task: publish:v2
- task: publish:v1
# A version tag that already exists on Docker Hub is skipped, so publishing
# one track doesn't rebuild the other or move its :v1/:v2/:latest tags.
# FORCE=true republishes anyway, e.g. to ship image changes without a new
# opencode version.
publish:v2:
desc: "Push the v2 image (:latest + :v2 + <version>) unless <version> is on Docker Hub, and create the v2 GitHub Release if missing"
cmds:
- |
if [ "{{.FORCE}}" != "true" ] && docker buildx imagetools inspect {{.OCI}}:{{.VERSION}} >/dev/null 2>&1; then
echo "{{.OCI}}:{{.VERSION}} is already on Docker Hub, skipping push (FORCE=true republishes)"
else
task docker:push
fi
- |
if gh release view v{{.VERSION}} --repo {{.RELEASE_REPO}} >/dev/null 2>&1; then
echo "GitHub Release v{{.VERSION}} already exists, skipping"
else
./scripts/release-notes.sh v{{.VERSION}} {{.RELEASE_REPO}} > ./RELEASE_NOTES.md
gh release create v{{.VERSION}} --repo {{.RELEASE_REPO}} --target {{.RELEASE_COMMIT}} --latest --title "v{{.VERSION}}" --notes-file ./RELEASE_NOTES.md
fi
publish:v1:
desc: "Push the v1 image (:latest stays on v2) with <version> and :v1 tags unless <version> is on Docker Hub, and create the v1 GitHub Release if missing"
cmds:
- |
if [ "{{.FORCE}}" != "true" ] && docker buildx imagetools inspect {{.OCI}}:{{.VERSION_V1}} >/dev/null 2>&1; then
echo "{{.OCI}}:{{.VERSION_V1}} is already on Docker Hub, skipping push (FORCE=true republishes)"
else
task docker:push:v1
fi
- |
if gh release view v{{.VERSION_V1}} --repo {{.RELEASE_REPO}} >/dev/null 2>&1; then
echo "GitHub Release v{{.VERSION_V1}} already exists, skipping"
else
./scripts/release-notes.sh v{{.VERSION_V1}} {{.RELEASE_REPO}} > ./RELEASE_NOTES.md
gh release create v{{.VERSION_V1}} --repo {{.RELEASE_REPO}} --target {{.RELEASE_COMMIT}} --latest=false --title "v{{.VERSION_V1}}" --notes-file ./RELEASE_NOTES.md
fi
docker:build:v1:
desc: "Build the v1 image locally (tag: sprisa/opencode:<v1-version>)"
cmds:
- docker build --build-arg OPENCODE_VERSION={{.VERSION_V1}} --build-arg APT_REFRESH={{.APT_REFRESH}} --build-arg IMAGE_CREATED="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" -t {{.OCI}}:{{.VERSION_V1}} .
docker:push:v1:
desc: "Build and push multi-arch v1 image to Docker Hub with <version> and :v1 tags (:latest stays on v2)"
cmds:
- |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg OPENCODE_VERSION={{.VERSION_V1}} \
--build-arg APT_REFRESH={{.APT_REFRESH}} \
--build-arg IMAGE_CREATED="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
{{.CACHE_FROM}} \
--cache-to type=registry,ref={{.CACHE_REPO}}:v1,mode=max,ignore-error=true \
--push \
-t {{.OCI}}:{{.VERSION_V1}} \
-t {{.OCI}}:v1 \
.
- "echo Pushed {{.OCI}}:{{.VERSION_V1}} and {{.OCI}}:v1"