Skip to content

Commit 1aff594

Browse files
authored
Merge pull request #759 from aaannz/setup-merge
Merge the setup with the server container start
2 parents e82b89a + 8c3c64b commit 1aff594

36 files changed

Lines changed: 583 additions & 395 deletions

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ jobs:
3636
shell: sh -x {0}
3737
run: |
3838
git fetch origin ${{ github.base_ref }}
39-
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
39+
CHANGED_FILES=$(git diff --name-status origin/${{ github.base_ref }}...HEAD | grep -v "^D" | cut -f 2)
4040
./update-copyright-year.sh $CHANGED_FILES

mgradm/cmd/backup/restore/systemd_utils.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/backup/shared"
1616
"github.com/uyuni-project/uyuni-tools/mgradm/shared/pgsql"
1717
"github.com/uyuni-project/uyuni-tools/mgradm/shared/podman"
18+
adm_utils "github.com/uyuni-project/uyuni-tools/mgradm/shared/utils"
1819
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
1920
"github.com/uyuni-project/uyuni-tools/shared/utils"
2021
)
@@ -108,8 +109,12 @@ func generateDefaultSystemdServices(flags *shared.Flagpole) error {
108109
utils.PostgreSQLImage.Name,
109110
utils.PostgreSQLImage.Tag)
110111

112+
// Assumption is system is already configured when backup was taken.
113+
// No need for server environment file and everything should just work.
114+
111115
return utils.JoinErrors(
112-
podman.GenerateSystemdService(systemd, "", serverImage, false, "", []string{}),
116+
podman.GenerateUpgradeServerEnvironmentFile(false),
117+
podman.GenerateSystemdService(systemd, serverImage, adm_utils.InstallationFlags{}, []string{}, ""),
113118
pgsql.GeneratePgsqlSystemdService(systemd, dbImage),
114119
systemd.ReloadDaemon(false),
115120
)

mgradm/cmd/install/flags.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ func AddInstallFlags(cmd *cobra.Command) {
2020

2121
cmd_utils.AddServerFlags(cmd)
2222

23-
cmd.Flags().Bool("debug-java", false, L("Enable tomcat and taskomatic remote debugging"))
24-
2523
cmd_utils.AddCocoFlag(cmd)
2624

2725
cmd_utils.AddHubXmlrpcFlags(cmd)

mgradm/cmd/install/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ NOTE: installing on a remote podman is not supported yet!
5151

5252
adm_utils.AddMirrorFlag(cmd)
5353
AddInstallFlags(cmd)
54+
adm_utils.AddDebugFlags(cmd)
5455
podman.AddPodmanArgFlag(cmd)
55-
5656
return cmd
5757
}
5858

mgradm/cmd/install/utils.go

Lines changed: 28 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package install
66

77
import (
88
"errors"
9-
"fmt"
109
"os/exec"
1110

1211
"github.com/rs/zerolog"
@@ -19,11 +18,9 @@ import (
1918
"github.com/uyuni-project/uyuni-tools/mgradm/shared/podman"
2019
"github.com/uyuni-project/uyuni-tools/mgradm/shared/saline"
2120
"github.com/uyuni-project/uyuni-tools/mgradm/shared/tftp"
22-
adm_utils "github.com/uyuni-project/uyuni-tools/mgradm/shared/utils"
2321
"github.com/uyuni-project/uyuni-tools/shared"
2422
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
2523
shared_podman "github.com/uyuni-project/uyuni-tools/shared/podman"
26-
"github.com/uyuni-project/uyuni-tools/shared/ssl"
2724
"github.com/uyuni-project/uyuni-tools/shared/types"
2825
"github.com/uyuni-project/uyuni-tools/shared/utils"
2926
)
@@ -82,15 +79,19 @@ func installForPodman(
8279
return err
8380
}
8481

85-
log.Info().Msg(L("Run setup command"))
86-
87-
if err := runSetup(preparedImage, &flags.ServerFlags, fqdn); err != nil {
82+
// This creates installation values to be passed as envvars
83+
if err := podman.GenerateServerEnvironmentFile(flags.Installation, fqdn, flags.Mirror != ""); err != nil {
8884
return err
8985
}
9086

87+
if err := podman.GenerateSystemdService(
88+
systemd, preparedImage, flags.Installation, flags.Podman.Args, flags.Mirror,
89+
); err != nil {
90+
return utils.Error(err, L("failed to generate server service"))
91+
}
92+
9193
cnx := shared.NewConnection("podman", shared_podman.ServerContainerName, "")
92-
if err := podman.WaitForSystemStart(systemd, cnx, preparedImage, flags.Installation.TZ,
93-
flags.Installation.Debug.Java, flags.Mirror, flags.Podman.Args); err != nil {
94+
if err := podman.WaitForSystemStart(systemd, cnx); err != nil {
9495
return utils.Error(err, L("cannot wait for system start"))
9596
}
9697
if err := cnx.CopyCaCertificate(fqdn); err != nil {
@@ -114,7 +115,7 @@ func installForPodman(
114115
)
115116
}
116117

117-
func setupDatabase(dbFlags adm_utils.DBFlags, reportdbFlags adm_utils.DBFlags, preparedImage string) error {
118+
func setupDatabase(dbFlags types.DBFlags, reportdbFlags types.DBFlags, preparedImage string) error {
118119
if err := shared_podman.CreateCredentialsSecrets(
119120
shared_podman.DBUserSecret, dbFlags.User,
120121
shared_podman.DBPassSecret, dbFlags.Password,
@@ -129,81 +130,29 @@ func setupDatabase(dbFlags adm_utils.DBFlags, reportdbFlags adm_utils.DBFlags, p
129130
return err
130131
}
131132

132-
if dbFlags.IsLocal() {
133-
// The admin password is not needed for external databases
134-
if err := shared_podman.CreateCredentialsSecrets(
135-
shared_podman.DBAdminUserSecret, dbFlags.Admin.User,
136-
shared_podman.DBAdminPassSecret, dbFlags.Admin.Password,
137-
); err != nil {
138-
return err
139-
}
140-
if dbFlags.Walbackup {
141-
if err := pgsql.GenerateBackupVolumeConfig(systemd); err != nil {
142-
return err
143-
}
144-
}
145-
// Run the DB container setup if the user doesn't set a custom host name for it.
146-
if err := pgsql.SetupPgsql(systemd, preparedImage); err != nil {
147-
return err
148-
}
149-
if dbFlags.Walbackup {
150-
if err := db.Enable(true); err != nil {
151-
return err
152-
}
153-
}
154-
} else {
133+
if !dbFlags.IsLocal() {
155134
log.Info().Msgf(
156135
L("Skipped database container setup to use external database %s"),
157136
dbFlags.Host,
158137
)
138+
return nil
159139
}
160-
return nil
161-
}
162140

163-
// runSetup execute the setup.
164-
func runSetup(image string, flags *adm_utils.ServerFlags, fqdn string) error {
165-
env := adm_utils.GetSetupEnv(flags.Mirror, &flags.Installation, fqdn)
166-
envNames := []string{}
167-
envValues := []string{}
168-
for key, value := range env {
169-
envNames = append(envNames, "-e", key)
170-
envValues = append(envValues, fmt.Sprintf("%s=%s", key, value))
171-
}
172-
173-
command := []string{
174-
"run",
175-
"--rm",
176-
"--shm-size=0",
177-
"--shm-size-systemd=0",
178-
"--name", "uyuni-setup",
179-
"--network", shared_podman.UyuniNetwork,
180-
"-e", "TZ=" + flags.Installation.TZ,
181-
"--secret", shared_podman.DBUserSecret + ",type=env,target=MANAGER_USER",
182-
"--secret", shared_podman.DBPassSecret + ",type=env,target=MANAGER_PASS",
183-
"--secret", shared_podman.ReportDBUserSecret + ",type=env,target=REPORT_DB_USER",
184-
"--secret", shared_podman.ReportDBPassSecret + ",type=env,target=REPORT_DB_PASS",
185-
"-e REPORT_DB_CA_CERT=" + ssl.DBCAContainerPath,
186-
"--secret", shared_podman.DBCASecret + ",type=mount,target=" + ssl.DBCAContainerPath,
187-
"--secret", shared_podman.CASecret + ",type=mount,target=" + ssl.CAContainerPath,
188-
"--secret", shared_podman.CASecret + ",type=mount,target=/usr/share/susemanager/salt/certs/RHN-ORG-TRUSTED-SSL-CERT",
189-
"--secret", shared_podman.CASecret + ",type=mount,target=/srv/www/htdocs/pub/RHN-ORG-TRUSTED-SSL-CERT",
190-
"--secret", shared_podman.SSLCertSecret + ",type=mount,target=" + ssl.ServerCertPath,
191-
"--secret", shared_podman.SSLKeySecret + ",type=mount,target=" + ssl.ServerCertKeyPath,
192-
}
193-
for _, volume := range utils.ServerVolumeMounts {
194-
command = append(command, "-v", fmt.Sprintf("%s:%s", volume.Name, volume.MountPath))
195-
}
196-
command = append(command, envNames...)
197-
command = append(command, image)
198-
199-
command = append(command, "/usr/bin/bash", "-e", "-c", "/docker-entrypoint-init.d/00-mgrSetup.sh")
200-
201-
if _, err := newRunner("podman", command...).Env(envValues).StdMapping().Exec(); err != nil {
202-
return utils.Error(err, L("server setup failed"))
203-
}
204-
205-
log.Info().Msgf(L("Server set up, login on https://%[1]s with %[2]s user"), fqdn, flags.Installation.Admin.Login)
141+
// The admin password is not needed for external databases
142+
if err := shared_podman.CreateCredentialsSecrets(
143+
shared_podman.DBAdminUserSecret, dbFlags.Admin.User,
144+
shared_podman.DBAdminPassSecret, dbFlags.Admin.Password,
145+
); err != nil {
146+
return err
147+
}
148+
// Run the DB container setup if the user doesn't set a custom host name for it.
149+
if err := pgsql.SetupPgsql(systemd, preparedImage); err != nil {
150+
return err
151+
}
152+
if dbFlags.Walbackup {
153+
if err := db.Enable(true); err != nil {
154+
return err
155+
}
156+
}
206157
return nil
207158
}
208-
209-
var newRunner = utils.NewRunner

mgradm/cmd/support/ptf/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func ptfForPodman(
4141
//we don't want to perform a postgres version upgrade when installing a PTF.
4242
//in that case, we can use the upgrade command.
4343
dummyImage := types.ImageFlags{}
44-
dummyDB := adm_utils.DBFlags{}
45-
dummyReportDB := adm_utils.DBFlags{}
44+
dummyDB := types.DBFlags{}
45+
dummyReportDB := types.DBFlags{}
4646
dummySSL := adm_utils.InstallSSLFlags{}
4747

4848
if err := flags.checkParameters(authFile); err != nil {
@@ -61,6 +61,7 @@ func ptfForPodman(
6161
flags.Pgsql,
6262
flags.TFTPD,
6363
flags.Installation.TZ,
64+
flags.Installation.Debug.Java,
6465
)
6566
}
6667

mgradm/cmd/upgrade/upgrade.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func newCmd(globalFlags *types.GlobalFlags, run utils.CommandFunc[podmanUpgradeF
4242
},
4343
}
4444
AddUpgradeFlags(cmd)
45+
cmd_utils.AddDebugFlags(cmd)
4546
podman.AddPodmanArgFlag(cmd)
4647
return cmd
4748
}

mgradm/cmd/upgrade/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ func upgradePodman(_ *types.GlobalFlags, flags *podmanUpgradeFlags, cmd *cobra.C
4747
flags.Pgsql,
4848
flags.TFTPD,
4949
flags.Installation.TZ,
50+
flags.Installation.Debug.Java,
5051
)
5152
}

mgradm/shared/coco/coco.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func Upgrade(
2222
authFile string,
2323
cocoFlags adm_utils.CocoFlags,
2424
baseImage types.ImageFlags,
25-
db adm_utils.DBFlags,
25+
db types.DBFlags,
2626
) error {
2727
if cocoFlags.Image.Name == "" {
2828
log.Info().Msg(L("Not altering the confidential computing service"))
@@ -54,7 +54,7 @@ func writeCocoServiceFiles(
5454
authFile string,
5555
cocoFlags adm_utils.CocoFlags,
5656
baseImage types.ImageFlags,
57-
db adm_utils.DBFlags,
57+
db types.DBFlags,
5858
) error {
5959
image := cocoFlags.Image
6060
currentReplicas := systemd.CurrentReplicaCount(podman.ServerAttestationService)
@@ -104,7 +104,7 @@ Environment=database_connection=jdbc:postgresql://%s:%d/%s
104104
`, preparedImage, db.Host, db.Port, db.Name)
105105

106106
if err := podman.GenerateSystemdConfFile(
107-
podman.ServerAttestationService+"@", "generated.conf", environment, true,
107+
podman.ServerAttestationService+"@", podman.GeneratedConf, environment, true,
108108
); err != nil {
109109
return utils.Errorf(err, L("cannot generate systemd conf file"))
110110
}
@@ -121,7 +121,7 @@ func SetupCocoContainer(
121121
authFile string,
122122
coco adm_utils.CocoFlags,
123123
baseImage types.ImageFlags,
124-
db adm_utils.DBFlags,
124+
db types.DBFlags,
125125
) error {
126126
if err := writeCocoServiceFiles(
127127
systemd, authFile, coco, baseImage, db,

mgradm/shared/hub/xmlrpcapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func generateHubXmlrpcSystemdService(systemd podman.Systemd, image string, serve
117117

118118
environment := fmt.Sprintf("Environment=UYUNI_HUB_XMLRPC_IMAGE=%s", image)
119119
if err := podman.GenerateSystemdConfFile(
120-
podman.HubXmlrpcService+"@", "generated.conf", environment, true,
120+
podman.HubXmlrpcService+"@", podman.GeneratedConf, environment, true,
121121
); err != nil {
122122
return utils.Errorf(err, L("cannot generate systemd conf file"))
123123
}

0 commit comments

Comments
 (0)