-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathjustfile
More file actions
162 lines (142 loc) · 5.89 KB
/
justfile
File metadata and controls
162 lines (142 loc) · 5.89 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
# Load versions from the single source of truth
set dotenv-filename := "versions.env"
KITSU_VERSION := env_var('KITSU_VERSION')
ZOU_VERSION := env_var('ZOU_VERSION')
INDEX_VERSION := env_var('INDEX_VERSION')
image := "cgwire/cgwire"
tag := KITSU_VERSION + "-" + ZOU_VERSION + "-" + INDEX_VERSION
# List available commands
default:
@just --list
# Show current versions
versions:
@echo "KITSU_VERSION={{ KITSU_VERSION }}"
@echo "ZOU_VERSION={{ ZOU_VERSION }}"
@echo "INDEX_VERSION={{ INDEX_VERSION }}"
@echo "Tag: {{ tag }}"
# Fetch latest versions from GitHub and update versions.env
update-versions:
#!/usr/bin/env bash
set -euo pipefail
KITSU_VERSION=$(curl -s https://api.github.com/repos/cgwire/kitsu/releases/latest | jq -r '.tag_name' | sed 's/^v//')
ZOU_VERSION=$(curl -s https://api.github.com/repos/cgwire/zou/tags | jq -r '.[0].name' | sed 's/^v//')
echo "Latest Kitsu: ${KITSU_VERSION}"
echo "Latest Zou: ${ZOU_VERSION}"
sed -i'' -e "s/^KITSU_VERSION=.*/KITSU_VERSION=${KITSU_VERSION}/" versions.env
sed -i'' -e "s/^ZOU_VERSION=.*/ZOU_VERSION=${ZOU_VERSION}/" versions.env
echo "Updated versions.env:"
cat versions.env
GIT_PAGER="" git diff versions.env
# Build the Docker image locally (single platform)
build:
docker build \
--build-arg KITSU_VERSION={{ KITSU_VERSION }} \
--build-arg ZOU_VERSION={{ ZOU_VERSION }} \
-t {{ image }}:{{ tag }} \
.
# Build and push multi-platform image to Docker Hub
build-push:
docker buildx build \
--push --no-cache \
--platform=linux/amd64,linux/arm64 \
--build-arg KITSU_VERSION={{ KITSU_VERSION }} \
--build-arg ZOU_VERSION={{ ZOU_VERSION }} \
-t {{ image }}:{{ tag }} \
.
# Start a container for a given platform (arm64 or amd64)
start platform="arm64":
#!/usr/bin/env bash
set -euo pipefail
CONTAINER_NAME=cgwire-{{ platform }}
LOCAL_PORT={{ if platform == "arm64" { "8590" } else { "8591" } }}
echo "Starting ${CONTAINER_NAME} on port ${LOCAL_PORT}..."
echo "docker container run --platform=linux/{{ platform }} -d --init -p 127.0.0.1:${LOCAL_PORT}:80 --rm --name \"${CONTAINER_NAME}\" {{ image }}:{{ tag }}"
docker container run --platform=linux/{{ platform }} -d --init -p ${LOCAL_PORT}:80 --rm --name "${CONTAINER_NAME}" {{ image }}:{{ tag }}
echo "${CONTAINER_NAME} started on http://127.0.0.1:${LOCAL_PORT}"
# Start both platforms
start-all: (start "arm64") (start "amd64")
# Stop and remove a container for a given platform (arm64 or amd64)
stop platform="arm64":
-docker kill cgwire-{{ platform }}
# Stop both platforms
stop-all: (stop "arm64") (stop "amd64")
# Run tests against a running container (arm64 or amd64)
test platform="arm64":
#!/usr/bin/env bash
set -euo pipefail
LOCAL_PORT={{ if platform == "arm64" { "8590" } else { "8591" } }}
echo "====== Test Kitsu: {{ KITSU_VERSION }}, Zou: {{ ZOU_VERSION }}, index: {{ INDEX_VERSION }} on {{ platform }}"
KITSU_URL="http://127.0.0.1:${LOCAL_PORT}" \
KITSU_VERSION="{{ KITSU_VERSION }}" \
ZOU_VERSION="{{ ZOU_VERSION }}" \
TIMEOUT=30 \
WAIT=1 \
uvx --from 'cgwire-checks @ git+https://github.com/cgwire/kitsu-checker.git' cgwire_checks
echo "====== Tests passed for {{ platform }}"
# Test both platforms
test-all: (test "arm64") (test "amd64")
# Start, test, and stop a container for a given platform (arm64 or amd64)
check platform="arm64": (start platform)
#!/usr/bin/env bash
set -euo pipefail
trap 'just stop {{ platform }}' EXIT
just test {{ platform }}
# Start, test, and stop both platforms
check-all: start-all
#!/usr/bin/env bash
set -euo pipefail
trap 'just stop-all' EXIT
just test-all
# Add alias tags (latest + kitsu version) to the pushed image
push-tags:
docker buildx imagetools create \
{{ image }}:{{ tag }} \
--tag {{ image }}:{{ KITSU_VERSION }} \
--tag {{ image }}:latest
# Commit versions.env, tag, and push to trigger CI
release:
#!/usr/bin/env bash
set -euo pipefail
echo "Releasing {{ tag }}"
git add versions.env
git commit -m "Bump Kitsu and Zou versions ({{ KITSU_VERSION }} and {{ ZOU_VERSION }})"
git tag {{ tag }}
git push origin master --tags
# Open Docker Hub tags page
hub:
open https://hub.docker.com/r/cgwire/cgwire/tags
# Update GitHub Actions pinned SHAs to their latest release
update-actions:
#!/usr/bin/env bash
set -euo pipefail
WORKFLOW=".github/workflows/docker.yml"
# Extract unique action references (owner/repo@sha)
actions=$(sed -n 's/.*uses: \([^@]*\)@.*/\1/p' "$WORKFLOW" | sort -u)
for action in $actions; do
echo "--- ${action}"
# Get latest release tag
tag=$(curl -s "https://api.github.com/repos/${action}/releases/latest" | jq -r '.tag_name')
if [ "$tag" = "null" ]; then
tag=$(curl -s "https://api.github.com/repos/${action}/tags" | jq -r '.[0].name')
fi
# Resolve tag to commit SHA (handle annotated tags)
ref=$(curl -s "https://api.github.com/repos/${action}/git/ref/tags/${tag}")
sha=$(echo "$ref" | jq -r '.object.sha')
obj_type=$(echo "$ref" | jq -r '.object.type')
if [ "$obj_type" = "tag" ]; then
sha=$(curl -s "https://api.github.com/repos/${action}/git/tags/${sha}" | jq -r '.object.sha')
fi
echo " ${tag} -> ${sha}"
# Get current SHA from workflow
old_sha=$(grep -m1 "uses: ${action}@" "$WORKFLOW" | sed 's/.*@\([a-f0-9]*\).*/\1/')
if [ "$old_sha" = "$sha" ]; then
echo " (already up to date)"
else
sed -i'' -e "s|${action}@${old_sha}.*|${action}@${sha} # ${tag}|" "$WORKFLOW"
echo " updated from ${old_sha}"
fi
done
echo ""
GIT_PAGER="" git diff "$WORKFLOW"
# Full local workflow: update versions, build, check, release
all: update-versions build check-all release