Skip to content

Commit 38d6093

Browse files
committed
Generate update manifest during build
1 parent 8753a77 commit 38d6093

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

components/local-app/BUILD.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ packages:
33
- name: docker
44
type: docker
55
deps:
6-
- :app
6+
- :app-with-manifest
77
argdeps:
88
- imageRepoBase
99
config:
@@ -13,7 +13,32 @@ packages:
1313
image:
1414
- ${imageRepoBase}/local-app:${version}
1515
- ${imageRepoBase}/local-app:commit-${__git_commit}
16-
16+
- name: update-manifest
17+
type: go
18+
srcs:
19+
- go.mod
20+
- go.sum
21+
- "**/*.go"
22+
- version.txt
23+
deps:
24+
- components/supervisor-api/go:lib
25+
- components/gitpod-protocol/go:lib
26+
- components/local-app-api/go:lib
27+
- components/public-api/go:lib
28+
config:
29+
packaging: app
30+
dontTest: true
31+
buildCommand: ["go", "build", "-o", "update-manifest", "./main/update-manifest/main.go"]
32+
- name: app-with-manifest
33+
type: generic
34+
deps:
35+
- :app
36+
- :update-manifest
37+
config:
38+
commands:
39+
- ["sh", "-c", "mkdir -p bin && mv components-local-app--app/bin/* bin/"]
40+
- ["sh", "-c", "components-local-app--update-manifest/update-manifest --cwd bin | tee bin/manifest.json"]
41+
- ["rm", "-rf", "components-local-app--update-manifest", "components-local-app--app"]
1742
scripts:
1843
- name: install-cli
1944
description: "Install gitpod-cli as `gitpod` command and add auto-completion. Usage: '. $(leeway run components/local-app:install-cli)'"

components/local-app/leeway.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
FROM cgr.dev/chainguard/wolfi-base:latest@sha256:a8c9c2888304e62c133af76f520c9c9e6b3ce6f1a45e3eaa57f6639eb8053c90
66

77
WORKDIR /app
8-
COPY components-local-app--app/bin/* ./
8+
COPY components-local-app--app-with-manifest/bin/* ./
99

1010
ARG __GIT_COMMIT
1111
ARG VERSION
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package main
6+
7+
import (
8+
"encoding/json"
9+
"fmt"
10+
"os"
11+
12+
"github.com/Masterminds/semver/v3"
13+
"github.com/gitpod-io/local-app/pkg/constants"
14+
"github.com/gitpod-io/local-app/pkg/selfupdate"
15+
"github.com/sagikazarmark/slog-shim"
16+
"github.com/spf13/pflag"
17+
)
18+
19+
var (
20+
version = pflag.String("version", constants.Version.String(), "version to use")
21+
cwd = pflag.String("cwd", ".", "working directory")
22+
)
23+
24+
func main() {
25+
pflag.Parse()
26+
27+
ver := semver.MustParse(*version)
28+
mf, err := selfupdate.GenerateManifest(ver, *cwd, selfupdate.DefaultFilenameParser)
29+
if err != nil {
30+
slog.Error("cannot generate manifest", "err", err)
31+
os.Exit(1)
32+
}
33+
fc, err := json.MarshalIndent(mf, "", " ")
34+
if err != nil {
35+
slog.Error("cannot marshal manifest", "err", err)
36+
os.Exit(1)
37+
}
38+
fmt.Println(string(fc))
39+
}

components/local-app/pkg/config/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type Config struct {
2222

2323
ActiveContext string `yaml:"activeContext,omitempty"`
2424
Contexts map[string]*ConnectionContext
25-
Telemetry *Telemetry `yaml:"telemetry"`
26-
Autoupdate bool `yaml:"autoupdate"`
25+
Telemetry Telemetry `yaml:"telemetry"`
26+
Autoupdate bool `yaml:"autoupdate"`
2727
}
2828

2929
type Telemetry struct {
@@ -83,7 +83,7 @@ func LoadConfig(fn string) (res *Config, err error) {
8383
cfg := &Config{
8484
Filename: fn,
8585
Contexts: make(map[string]*ConnectionContext),
86-
Telemetry: &Telemetry{
86+
Telemetry: Telemetry{
8787
Enabled: !telemetry.DoNotTrack(),
8888
Identity: telemetry.GenerateIdentity(),
8989
},

components/local-app/pkg/selfupdate/selfupdate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Binary struct {
4646

4747
type FilenameParserFunc func(filename string) (os, arch string, ok bool)
4848

49-
var regexDefaultFilenamePattern = regexp.MustCompile(`^.*-(linux|darwin|windows)-(amd64|arm64)(\.exe)?$`)
49+
var regexDefaultFilenamePattern = regexp.MustCompile(`.*-(linux|darwin|windows)-(amd64|arm64)(\.exe)?`)
5050

5151
func DefaultFilenameParser(filename string) (os, arch string, ok bool) {
5252
matches := regexDefaultFilenamePattern.FindStringSubmatch(filename)

0 commit comments

Comments
 (0)