-
Notifications
You must be signed in to change notification settings - Fork 124
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-12573 Update podman via UI. #3128
base: v3
Are you sure you want to change the base?
Changes from 2 commits
41c0323
c47aa2c
b198056
e095a8c
36dfcc9
7cf938f
95e9f3b
ecfeadc
5b2c6bf
47c925c
4c3e6f8
17312aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
PMM_WATCHTOWER_HOST=http://watchtower:8080 | ||
PMM_WATCHTOWER_TOKEN=123 | ||
PMM_SERVER_UPDATE_VERSION=docker.io/perconalab/pmm-server:3-dev-container | ||
PMM_DEV_UPDATE_DOCKER_IMAGE=docker.io/perconalab/pmm-server:3-dev-container | ||
PMM_IMAGE={{ pmm_server_image_name }} | ||
PMM_DISTRIBUTION_METHOD={{ pmm_distribution_method }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just small thing there is missing empty line at end of file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ import ( | |
"google.golang.org/grpc/codes" | ||
grpcstatus "google.golang.org/grpc/status" | ||
|
||
serverv1 "github.com/percona/pmm/api/server/v1" | ||
"github.com/percona/pmm/managed/utils/distribution" | ||
"github.com/percona/pmm/version" | ||
) | ||
|
||
|
@@ -44,6 +46,7 @@ const ( | |
updateCheckInterval = 24 * time.Hour | ||
updateCheckResultFresh = updateCheckInterval + 10*time.Minute | ||
updateDefaultTimeout = 30 * time.Second | ||
envfilePath = "/home/pmm/.config/systemd/user/pmm-server.env" | ||
) | ||
|
||
var fileName = "/etc/pmm-server-update-version.json" | ||
|
@@ -52,6 +55,7 @@ var fileName = "/etc/pmm-server-update-version.json" | |
type Updater struct { | ||
l *logrus.Entry | ||
watchtowerHost *url.URL | ||
dus *distribution.Service | ||
gRPCMessageMaxSize uint32 | ||
|
||
performM sync.Mutex | ||
|
@@ -63,10 +67,11 @@ type Updater struct { | |
} | ||
|
||
// NewUpdater creates a new Updater service. | ||
func NewUpdater(watchtowerHost *url.URL, gRPCMessageMaxSize uint32) *Updater { | ||
func NewUpdater(watchtowerHost *url.URL, dus *distribution.Service, gRPCMessageMaxSize uint32) *Updater { | ||
u := &Updater{ | ||
l: logrus.WithField("service", "updater"), | ||
watchtowerHost: watchtowerHost, | ||
dus: dus, | ||
gRPCMessageMaxSize: gRPCMessageMaxSize, | ||
} | ||
return u | ||
|
@@ -157,6 +162,15 @@ func (up *Updater) StartUpdate(ctx context.Context, newImageName string) error { | |
return grpcstatus.Errorf(codes.FailedPrecondition, "failed to check watchtower host") | ||
} | ||
|
||
dm, _, _ := up.dus.GetDistributionMethodAndOS() | ||
if dm != serverv1.DistributionMethod_DISTRIBUTION_METHOD_DOCKER { | ||
err := up.updateEnvironmentVariables(envfilePath, newImageName) | ||
if err != nil { | ||
up.l.WithError(err).Error("Failed to update environment variables file") | ||
return errors.Wrap(err, "failed to update environment variables file") | ||
} | ||
} | ||
|
||
if err := up.sendRequestToWatchtower(ctx, newImageName); err != nil { | ||
up.l.WithError(err).Error("Failed to trigger update") | ||
return errors.Wrap(err, "failed to trigger update") | ||
|
@@ -409,6 +423,27 @@ func (up *Updater) checkWatchtowerHost() error { | |
return nil | ||
} | ||
|
||
func (up *Updater) updateEnvironmentVariables(filename string, name string) error { | ||
if len(strings.Split(name, "/")) < 3 { | ||
name = "docker.io/" + name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. podman requires full name to update. |
||
} | ||
file, err := os.ReadFile(filename) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to read file") | ||
} | ||
lines := strings.Split(string(file), "\n") | ||
for i, line := range lines { | ||
if strings.Contains(line, "PMM_IMAGE") { | ||
lines[i] = fmt.Sprintf("PMM_IMAGE=%s", name) | ||
} | ||
} | ||
err = os.WriteFile(filename, []byte(strings.Join(lines, "\n")), 0o644) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to write file") | ||
} | ||
return nil | ||
} | ||
|
||
func isHostAvailable(host string, port string, timeout time.Duration) bool { | ||
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), timeout) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
PMM_WATCHTOWER_HOST=http://watchtower:8080 | ||
PMM_WATCHTOWER_TOKEN=123 | ||
PMM_IMAGE=docker.io/perconalab/pmm-server:3-dev-latest | ||
PMM_DISTRIBUTION_METHOD=ami | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just small thing there is missing empty line at end of file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be dropped before GA