Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-11261 Update PMM via watchtower #2844

Merged
merged 20 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions api/serverpb/json/client/server/start_update_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions api/serverpb/json/client/server/start_update_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion api/serverpb/json/serverpb.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
601 changes: 306 additions & 295 deletions api/serverpb/server.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/serverpb/server.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion api/serverpb/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ message CheckUpdatesResponse {
google.protobuf.Timestamp last_check = 5;
}

message StartUpdateRequest {}
message StartUpdateRequest {
string new_image = 1;
}

message StartUpdateResponse {
// Authentication token for getting update statuses.
Expand Down
8 changes: 7 additions & 1 deletion api/swagger/swagger-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -3649,7 +3649,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
8 changes: 7 additions & 1 deletion api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@
"in": "body",
"required": true,
"schema": {
"type": "object"
"type": "object",
"properties": {
"new_image": {
"type": "string",
"x-order": 0
}
}
}
}
],
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ services:
- ENABLE_RBAC=${ENABLE_RBAC:-0}
- LESS_LOG_NOISE=1
- PERCONA_TEST_VERSION_SERVICE_URL=${PERCONA_TEST_VERSION_SERVICE_URL}
- PMM_WATCHTOWER_HOST=${PMM_WATCHTOWER_HOST:-http://watchtower:8080}
- PMM_WATCHTOWER_TOKEN=${PMM_WATCHTOWER_TOKEN:-123}
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
# - PERCONA_TEST_PLATFORM_ADDRESS=https://check.localhost
# - PERCONA_TEST_PLATFORM_INSECURE=1
# - PERCONA_TEST_PLATFORM_PUBLIC_KEY=<public key>
Expand Down Expand Up @@ -94,6 +96,22 @@ services:
# /opt/entrypoint.sh
# "

# docker run -v /var/run/docker.sock:/var/run/docker.sock -e WATCHTOWER_HTTP_API_UPDATE=1 -e WATCHTOWER_HTTP_API_TOKEN=123 --hostname=watchtower --network=pmm_default docker.io/bupychuk/watchtower
watchtower:
profiles:
- pmm
image: ${WATCHTOWER_IMAGE:-bupychuk/watchtower}
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
container_name: watchtower
environment:
- WATCHTOWER_HTTP_LISTEN_PORT=8080
- WATCHTOWER_HTTP_API_UPDATE=1
- WATCHTOWER_HTTP_API_TOKEN=${PMM_WATCHTOWER_TOKEN:-123}
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
hostname: watchtower
networks:
- ${NETWORK:-default}
volumes:
- /var/run/docker.sock:${DOCKER_PATH:-/var/run/docker.sock}

# PMM with external DBs
ch:
profiles:
Expand Down
15 changes: 15 additions & 0 deletions managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,20 @@ func main() { //nolint:cyclop,maintidx

dumpService := dump.New(db)

// Get the hostname from the environment variable
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
watchtowerHost := os.Getenv("PMM_WATCHTOWER_HOST")
if watchtowerHost == "" {
watchtowerHost = "http://watchtower:8080"
}

// Create a URL with the images and new image name as query parameters
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
u, err := url.Parse(watchtowerHost)
if err != nil {
l.Fatalf("Failed to parse watchtower hostname: %s", err)
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved
}

updater := server.NewUpdater(supervisord, u)

serverParams := &server.Params{
DB: db,
VMDB: vmdb,
Expand All @@ -981,6 +995,7 @@ func main() { //nolint:cyclop,maintidx
AwsInstanceChecker: awsInstanceChecker,
GrafanaClient: grafanaClient,
VMAlertExternalRules: externalRules,
Updater: updater,
}

server, err := server.NewServer(serverParams)
Expand Down
20 changes: 10 additions & 10 deletions managed/services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
awsInstanceChecker *AWSInstanceChecker
grafanaClient grafanaClient
haService haService
updater *Updater

l *logrus.Entry

Expand Down Expand Up @@ -91,6 +92,7 @@
TelemetryService telemetryService
AwsInstanceChecker *AWSInstanceChecker
GrafanaClient grafanaClient
Updater *Updater
}

// NewServer returns new server for Server service.
Expand All @@ -113,6 +115,7 @@
telemetryService: params.TelemetryService,
awsInstanceChecker: params.AwsInstanceChecker,
grafanaClient: params.GrafanaClient,
updater: params.Updater,
l: logrus.WithField("component", "server"),
pmmUpdateAuthFile: path,
envSettings: &models.ChangeSettingsParams{},
Expand Down Expand Up @@ -258,16 +261,16 @@
s.envRW.RUnlock()

if req.OnlyInstalledVersion {
return s.onlyInstalledVersionResponse(ctx), nil
return s.updater.onlyInstalledVersionResponse(), nil
}

if req.Force {
if err := s.supervisord.ForceCheckUpdates(ctx); err != nil {
if err := s.updater.ForceCheckUpdates(ctx); err != nil {
return nil, err
}
}

v, lastCheck := s.supervisord.LastCheckUpdatesResult(ctx)
v, lastCheck := s.updater.LastCheckUpdatesResult(ctx)
if v == nil {
return nil, status.Error(codes.Unavailable, "failed to check for updates")
}
Expand All @@ -281,7 +284,7 @@
Version: v.Latest.Version,
FullVersion: v.Latest.FullVersion,
},
UpdateAvailable: v.UpdateAvailable,
UpdateAvailable: true,
LatestNewsUrl: v.LatestNewsURL,
}

Expand Down Expand Up @@ -314,19 +317,16 @@
return nil, status.Error(codes.FailedPrecondition, "Updates are disabled via DISABLE_UPDATES environment variable.")
}

offset, err := s.supervisord.StartUpdate()
if err != nil {
return nil, err
}
s.updater.StartUpdate(ctx, req.NewImage)

Check failure on line 320 in managed/services/server/server.go

View workflow job for this annotation

GitHub Actions / Checks

Error return value of `s.updater.StartUpdate` is not checked (errcheck)
BupycHuk marked this conversation as resolved.
Show resolved Hide resolved

authToken := uuid.New().String()
if err = s.writeUpdateAuthToken(authToken); err != nil {
if err := s.writeUpdateAuthToken(authToken); err != nil {
return nil, err
}

return &serverpb.StartUpdateResponse{
AuthToken: authToken,
LogOffset: offset,
LogOffset: 0,
}, nil
}

Expand Down
Loading
Loading