Fix Docker deployment inputs

Include all addon workspaces and vendored dependencies in image builds, and expose deploy time plus commit metadata on the home page.

Amp-Thread-ID: https://ampcode.com/threads/T-01a033d4-0e44-708e-af0e-6166283416ff
Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
Amp
2026-08-24 18:30:45 +00:00
co-authored by heaust
parent 6153223fd5
commit d71da85307
6 changed files with 61 additions and 5 deletions
+24
View File
@@ -13,6 +13,7 @@ import (
"path"
"strconv"
"strings"
"time"
)
//go:embed web
@@ -40,6 +41,13 @@ func newApplication(store *playgroundStore, packages map[string]memoryAsset, mon
if err != nil {
return nil, err
}
if name == "home.html" {
logMessage, err := json.Marshal(deploymentLogMessage())
if err != nil {
return nil, err
}
content = bytes.Replace(content, []byte("__YAWN_DEPLOYMENT_LOG__"), logMessage, 1)
}
pages[name] = content
}
return &application{
@@ -51,6 +59,22 @@ func newApplication(store *playgroundStore, packages map[string]memoryAsset, mon
}, nil
}
func deploymentLogMessage() string {
deployedAt := "unknown"
if value := os.Getenv("YAWN_DEPLOYED_AT"); value != "" {
deployedAt = value
if parsed, err := time.Parse(time.RFC3339, value); err == nil {
ist := time.FixedZone("IST", 5*60*60+30*60)
deployedAt = parsed.In(ist).Format("2 January 2006, 03:04:05 PM MST")
}
}
commitMessage := strings.TrimSpace(os.Getenv("YAWN_DEPLOY_COMMIT_MESSAGE"))
if commitMessage == "" {
commitMessage = "unknown"
}
return fmt.Sprintf("Yawn deployed at %s\nLatest commit: %s", deployedAt, commitMessage)
}
func (app *application) routes() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/healthz", app.health)
+19
View File
@@ -68,6 +68,25 @@ func TestHealth(t *testing.T) {
}
}
func TestHomeLogsDeploymentMetadata(t *testing.T) {
t.Setenv("YAWN_DEPLOYED_AT", "2026-08-24T18:30:00Z")
t.Setenv("YAWN_DEPLOY_COMMIT_MESSAGE", "Fix Docker deployment")
request := httptest.NewRequest(http.MethodGet, "/", nil)
response := httptest.NewRecorder()
testApplication(t).routes().ServeHTTP(response, request)
if response.Code != http.StatusOK {
t.Fatalf("status = %d", response.Code)
}
for _, expected := range []string{
`console.log("Yawn deployed at 25 August 2026, 12:00:00 AM IST\nLatest commit: Fix Docker deployment")`,
"<title>Yawn",
} {
if !bytes.Contains(response.Body.Bytes(), []byte(expected)) {
t.Fatalf("home page does not contain %q", expected)
}
}
}
func TestPlaygroundStoreMigratesLoadouts(t *testing.T) {
path := filepath.Join(t.TempDir(), "legacy.db")
database, err := sql.Open("sqlite3", path)
+7 -1
View File
@@ -50,8 +50,14 @@ if [[ "$(git rev-parse HEAD)" != "$fetched" ]]; then
exit 1
fi
deployed_at="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
commit_message="$(git log -1 --format=%s)"
printf 'Building the production image...\n'
"${compose[@]}" build --pull yawn
"${compose[@]}" build --pull \
--build-arg "YAWN_DEPLOYED_AT=$deployed_at" \
--build-arg "YAWN_DEPLOY_COMMIT_MESSAGE=$commit_message" \
yawn
"${compose[@]}" up -d --remove-orphans yawn
container="$("${compose[@]}" ps -q yawn)"
+3
View File
@@ -13,6 +13,9 @@
<link rel="stylesheet" href="/assets/site.css" />
<link rel="stylesheet" href="/assets/theme.css" />
<script type="module" src="/assets/site.js"></script>
<script>
console.log(__YAWN_DEPLOYMENT_LOG__);
</script>
</head>
<body>
<header class="site-header">